-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
Description
It seems that your loader procactively prohibits the use of Sharp on FreeBSD, which, quite frankly does not make any sense whatsoever.
Steps to reproduce:
pkg install vips
vips --version
vips-8.17.2
Next, in a dedicated folder and as non-privileged user:
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
export CXX=clang++
export CXXFLAGS="-std=c++17 -stdlib=libc++"
export CPPFLAGS="-I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include"
export LDFLAGS="-L/usr/local/lib -lvips -lvips-cpp"
export SHARP_BUILD_FROM_SOURCE=true
npm install node-addon-api node-gyp libvips tslib
npm install sharp@0.34.4
cd ./node_modules/sharp/src
npx node-gyp rebuild
cd /usr/home/sync-in/node_modules/sharp
mv src/build build
Note: Version-pinning of Sharp is needed to maintain compatibility with the latest avaiable vips port on FreeBSD.
Testing:
node -e "
const binary = require('./node_modules/sharp/build/Release/sharp-freebsd-x64.node');
console.log('Libvips version from binary:', binary.libvipsVersion());
console.log('Sharp should work - the loader is the problem!');
And:
# Check what sharp's loader is complaining about
node -e "
const help = [
'Could not load the \"sharp\" module using the freebsd-x64 runtime',
'Possible solutions:',
'- Manually install libvips >= 8.17.2',
'- Add experimental WebAssembly-based dependencies:',
' npm install --cpu=wasm32 sharp',
' npm install @img/sharp-wasm32',
'- Consult the installation documentation:',
' See https://sharp.pixelplumbing.com/install'
];
console.log('Loader error message is hardcoded!');
console.log('The loader is not even checking if the binary works!');
"
Well, the loader just peeps at the OS, and bails out, even without testing my shiny binary. This is not quite what the doctor ordered, is it?
Please allow those on FreeBSD to use your software! The fix should be easy; I have for now cut out the IMHO over-designed testing and issued:
cd
cp ~/node_modules/sharp/lib/sharp.js ~/node_modules/sharp/lib/sharp.js.orig
cat > ~/node_modules/sharp/lib/sharp.js << EOF
// Copyright 2013 Lovell Fuller and others.
// SPDX-License-Identifier: Apache-2.0
'use strict';
// FreeBSD patch: directly use our manually built binary
const { runtimePlatformArch } = require('./libvips');
const runtimePlatform = runtimePlatformArch();
module.exports = require(`../src/build/Release/sharp-${runtimePlatform}.node`);
EOF
node -e "require('sharp'); console.log('✅ Sharp loaded with nuclear patch!')"
Tadaaaa!
Thoughts regarding my urgent sugggestion to liberalise your user pool :-) ?