Skip to content

Fix build with musl 1.2.4#3755

Merged
lovell merged 1 commit intolovell:mainfrom
kleisauke:fix-musl-1.2.4-build
Aug 7, 2023
Merged

Fix build with musl 1.2.4#3755
lovell merged 1 commit intolovell:mainfrom
kleisauke:fix-musl-1.2.4-build

Conversation

@kleisauke
Copy link
Contributor

@kleisauke kleisauke commented Aug 7, 2023

musl 1.2.4 has removed the legacy LFS64 glibc-ABI-compat symbols, which would cause an error during npm install sharp when compiled from source (either with the --build-from-source flag or when a globally installed libvips is detected).

On the API level, the legacy "LFS64" ("large file support") interfaces, which were provided by macros remapping them to their standard names (#define stat64 stat and similar) have been deprecated and are no longer provided under the _GNU_SOURCE feature profile, only under explicit _LARGEFILE64_SOURCE. The latter will also be removed in a future version. Builds broken by this change can be fixed short-term by adding -D_LARGEFILE64_SOURCE to CFLAGS, but should be fixed to use the standard interfaces.
https://musl.libc.org/releases.html

The fix is to replace the OS-specific #ifdef's with a single one that checks whether _LARGEFILE64_SOURCE is defined. Other libc implementations that provide nondegenerate LFS64 interfaces are expected to define this macro as well.

Reproducer
$ mkdir sharp-musl && cd sharp-musl
$ docker run -v $(pwd):/app -w /app -it alpine:edge sh -c "\
    apk add build-base git npm python3 vips-cpp vips-dev && \
    npm install --build-from-source sharp"
...
npm ERR! ../src/pipeline.cc: In member function 'virtual void PipelineWorker::OnOK()':
npm ERR! ../src/pipeline.cc:1267:30: error: aggregate 'PipelineWorker::OnOK()::stat64 st' has incomplete type and cannot be defined
npm ERR!  1267 |         struct STAT64_STRUCT st;
npm ERR!       |                              ^~
npm ERR! ../src/pipeline.cc:1268:55: error: invalid use of incomplete type 'struct PipelineWorker::OnOK()::stat64'
npm ERR!  1268 |         if (STAT64_FUNCTION(baton->fileOut.data(), &st) == 0) {
npm ERR!       |                                                       ^
npm ERR! ../src/pipeline.cc:33:23: note: forward declaration of 'struct PipelineWorker::OnOK()::stat64'
npm ERR!    33 | #define STAT64_STRUCT stat64
npm ERR!       |                       ^~~~~~
npm ERR! ../src/pipeline.cc:1267:16: note: in expansion of macro 'STAT64_STRUCT'
npm ERR!  1267 |         struct STAT64_STRUCT st;
npm ERR!       |                ^~~~~~~~~~~~~
npm ERR! make: *** [sharp-linuxmusl-x64.target.mk:169: Release/obj.target/sharp-linuxmusl-x64/src/pipeline.o] Error 1
...

@lovell lovell merged commit 2829e17 into lovell:main Aug 7, 2023
@lovell
Copy link
Owner

lovell commented Aug 7, 2023

Dankjewel Kleis!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants