Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build option to embed GDAL resources in GDAL library, using C23 #embed #10780

Open
rouault opened this issue Sep 12, 2024 · 1 comment
Open

Comments

@rouault
Copy link
Member

rouault commented Sep 12, 2024

Some parts of GDAL core, but mostly drivers, depends on a number of resource files for correct execution. Locating those resource files on the filesystem can be painful in some use cases of GDAL, that involve relocating the GDAL binary at installation time. Typically GDAL embedded in Rasterio of Fiona (CC @sgillies) where GDAL_DATA must be correctly set currently. Would presumably help WASM-like usages too.

We might be able to improve that in the future by leveraging the shiny #embed pre-processor directive that has landed in the C23 standard. Basically you do something like:

static const unsigned char my_resource[] = {
   #embed "path/to/my.bin"
};

et voila, the file is embeded at build time.

Cf the live example at Godbolt sample

Currently it is only implemented in CLang master branch (19.0dev). There's work in progress for GCC 15 I believe. MSVC will probably lag behind as often.
So we could potentially offer a EMBED_RESOURCE_FILES CMake option that would enable such feature. It would presumably no longer install the resource files, nor try to fetch them on disk.

(and we could also use that for PROJ's proj.db as well)

@sgillies
Copy link
Contributor

Intriguing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants