mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Add support for statically-linked dependencies (lovell/sharp-libvips#39) (#2223)
This commit is contained in:
parent
85459e0ec6
commit
7c1c48327e
101
binding.gyp
101
binding.gyp
@ -1,4 +1,8 @@
|
|||||||
{
|
{
|
||||||
|
'variables': {
|
||||||
|
'vips_version': '<!(node -p "require(\'./lib/libvips\').minimumLibvipsVersion")',
|
||||||
|
'sharp_vendor_dir': '<(module_root_dir)/vendor/<(vips_version)'
|
||||||
|
},
|
||||||
'targets': [{
|
'targets': [{
|
||||||
'target_name': 'libvips-cpp',
|
'target_name': 'libvips-cpp',
|
||||||
'conditions': [
|
'conditions': [
|
||||||
@ -16,15 +20,18 @@
|
|||||||
'src/libvips/cplusplus/VImage.cpp'
|
'src/libvips/cplusplus/VImage.cpp'
|
||||||
],
|
],
|
||||||
'include_dirs': [
|
'include_dirs': [
|
||||||
'vendor/include',
|
'<(sharp_vendor_dir)/include',
|
||||||
'vendor/include/glib-2.0',
|
'<(sharp_vendor_dir)/include/glib-2.0',
|
||||||
'vendor/lib/glib-2.0/include'
|
'<(sharp_vendor_dir)/lib/glib-2.0/include'
|
||||||
],
|
],
|
||||||
|
'link_settings': {
|
||||||
|
'library_dirs': ['<(sharp_vendor_dir)/lib'],
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'../vendor/lib/libvips.lib',
|
'libvips.lib',
|
||||||
'../vendor/lib/libglib-2.0.lib',
|
'libglib-2.0.lib',
|
||||||
'../vendor/lib/libgobject-2.0.lib'
|
'libgobject-2.0.lib'
|
||||||
],
|
],
|
||||||
|
},
|
||||||
'configurations': {
|
'configurations': {
|
||||||
'Release': {
|
'Release': {
|
||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
@ -70,8 +77,8 @@
|
|||||||
'runtime_link%': 'shared',
|
'runtime_link%': 'shared',
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['OS != "win"', {
|
['OS != "win"', {
|
||||||
'pkg_config_path': '<!(node -e "console.log(require(\'./lib/libvips\').pkgConfigPath())")',
|
'pkg_config_path': '<!(node -p "require(\'./lib/libvips\').pkgConfigPath()")',
|
||||||
'use_global_libvips': '<!(node -e "console.log(Boolean(require(\'./lib/libvips\').useGlobalLibvips()).toString())")'
|
'use_global_libvips': '<!(node -p "Boolean(require(\'./lib/libvips\').useGlobalLibvips()).toString()")'
|
||||||
}, {
|
}, {
|
||||||
'pkg_config_path': '',
|
'pkg_config_path': '',
|
||||||
'use_global_libvips': ''
|
'use_global_libvips': ''
|
||||||
@ -110,9 +117,9 @@
|
|||||||
}, {
|
}, {
|
||||||
# Use pre-built libvips stored locally within node_modules
|
# Use pre-built libvips stored locally within node_modules
|
||||||
'include_dirs': [
|
'include_dirs': [
|
||||||
'vendor/include',
|
'<(sharp_vendor_dir)/include',
|
||||||
'vendor/include/glib-2.0',
|
'<(sharp_vendor_dir)/include/glib-2.0',
|
||||||
'vendor/lib/glib-2.0/include'
|
'<(sharp_vendor_dir)/lib/glib-2.0/include'
|
||||||
],
|
],
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['OS == "win"', {
|
['OS == "win"', {
|
||||||
@ -120,64 +127,45 @@
|
|||||||
'_ALLOW_KEYWORD_MACROS',
|
'_ALLOW_KEYWORD_MACROS',
|
||||||
'_FILE_OFFSET_BITS=64'
|
'_FILE_OFFSET_BITS=64'
|
||||||
],
|
],
|
||||||
|
'link_settings': {
|
||||||
|
'library_dirs': ['<(sharp_vendor_dir)/lib'],
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'../vendor/lib/libvips.lib',
|
'libvips.lib',
|
||||||
'../vendor/lib/libglib-2.0.lib',
|
'libglib-2.0.lib',
|
||||||
'../vendor/lib/libgobject-2.0.lib'
|
'libgobject-2.0.lib'
|
||||||
]
|
]
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
['OS == "mac"', {
|
['OS == "mac"', {
|
||||||
|
'link_settings': {
|
||||||
|
'library_dirs': ['<(sharp_vendor_dir)/lib'],
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'../vendor/lib/libvips-cpp.42.dylib',
|
'libvips-cpp.42.dylib',
|
||||||
'../vendor/lib/libvips.42.dylib',
|
'libvips.42.dylib'
|
||||||
'../vendor/lib/libglib-2.0.0.dylib',
|
|
||||||
'../vendor/lib/libgobject-2.0.0.dylib',
|
|
||||||
# Ensure runtime linking is relative to sharp.node
|
|
||||||
'-rpath \'@loader_path/../../vendor/lib\''
|
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
'xcode_settings': {
|
||||||
|
'OTHER_LDFLAGS': [
|
||||||
|
# Ensure runtime linking is relative to sharp.node
|
||||||
|
'-Wl,-rpath,\'@loader_path/../../vendor/<(vips_version)/lib\''
|
||||||
|
]
|
||||||
|
}
|
||||||
}],
|
}],
|
||||||
['OS == "linux"', {
|
['OS == "linux"', {
|
||||||
'defines': [
|
'defines': [
|
||||||
'_GLIBCXX_USE_CXX11_ABI=0'
|
'_GLIBCXX_USE_CXX11_ABI=0'
|
||||||
],
|
],
|
||||||
|
'link_settings': {
|
||||||
|
'library_dirs': ['<(sharp_vendor_dir)/lib'],
|
||||||
'libraries': [
|
'libraries': [
|
||||||
'../vendor/lib/libvips-cpp.so',
|
'-l:libvips-cpp.so.42',
|
||||||
'../vendor/lib/libvips.so',
|
'-l:libvips.so.42'
|
||||||
'../vendor/lib/libglib-2.0.so',
|
],
|
||||||
'../vendor/lib/libgobject-2.0.so',
|
'ldflags': [
|
||||||
# Dependencies of dependencies, included for openSUSE support
|
|
||||||
'../vendor/lib/libcairo.so',
|
|
||||||
'../vendor/lib/libexif.so',
|
|
||||||
'../vendor/lib/libexpat.so',
|
|
||||||
'../vendor/lib/libffi.so',
|
|
||||||
'../vendor/lib/libfontconfig.so',
|
|
||||||
'../vendor/lib/libfreetype.so',
|
|
||||||
'../vendor/lib/libfribidi.so',
|
|
||||||
'../vendor/lib/libgdk_pixbuf-2.0.so',
|
|
||||||
'../vendor/lib/libgif.so',
|
|
||||||
'../vendor/lib/libgio-2.0.so',
|
|
||||||
'../vendor/lib/libgmodule-2.0.so',
|
|
||||||
'../vendor/lib/libgsf-1.so',
|
|
||||||
'../vendor/lib/libgthread-2.0.so',
|
|
||||||
'../vendor/lib/libharfbuzz.so',
|
|
||||||
'../vendor/lib/libjpeg.so',
|
|
||||||
'../vendor/lib/liblcms2.so',
|
|
||||||
'../vendor/lib/liborc-0.4.so',
|
|
||||||
'../vendor/lib/libpango-1.0.so',
|
|
||||||
'../vendor/lib/libpangocairo-1.0.so',
|
|
||||||
'../vendor/lib/libpangoft2-1.0.so',
|
|
||||||
'../vendor/lib/libpixman-1.so',
|
|
||||||
'../vendor/lib/libpng.so',
|
|
||||||
'../vendor/lib/librsvg-2.so',
|
|
||||||
'../vendor/lib/libtiff.so',
|
|
||||||
'../vendor/lib/libwebp.so',
|
|
||||||
'../vendor/lib/libwebpdemux.so',
|
|
||||||
'../vendor/lib/libwebpmux.so',
|
|
||||||
'../vendor/lib/libxml2.so',
|
|
||||||
'../vendor/lib/libz.so',
|
|
||||||
# Ensure runtime linking is relative to sharp.node
|
# Ensure runtime linking is relative to sharp.node
|
||||||
'-Wl,-s -Wl,--disable-new-dtags -Wl,-rpath=\'$${ORIGIN}/../../vendor/lib\''
|
'-Wl,-s -Wl,--disable-new-dtags -Wl,-rpath=\'$$ORIGIN/../../vendor/<(vips_version)/lib\''
|
||||||
]
|
]
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
]
|
]
|
||||||
}]
|
}]
|
||||||
@ -190,8 +178,7 @@
|
|||||||
],
|
],
|
||||||
'xcode_settings': {
|
'xcode_settings': {
|
||||||
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
|
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
|
||||||
'CLANG_CXX_LIBRARY': 'libc++',
|
'MACOSX_DEPLOYMENT_TARGET': '10.9',
|
||||||
'MACOSX_DEPLOYMENT_TARGET': '10.7',
|
|
||||||
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
||||||
'GCC_ENABLE_CPP_RTTI': 'YES',
|
'GCC_ENABLE_CPP_RTTI': 'YES',
|
||||||
'OTHER_CPLUSPLUSFLAGS': [
|
'OTHER_CPLUSPLUSFLAGS': [
|
||||||
|
@ -6,6 +6,8 @@ const path = require('path');
|
|||||||
const libvips = require('../lib/libvips');
|
const libvips = require('../lib/libvips');
|
||||||
const npmLog = require('npmlog');
|
const npmLog = require('npmlog');
|
||||||
|
|
||||||
|
const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
|
||||||
|
|
||||||
const platform = process.env.npm_config_platform || process.platform;
|
const platform = process.env.npm_config_platform || process.platform;
|
||||||
if (platform === 'win32') {
|
if (platform === 'win32') {
|
||||||
const buildDir = path.join(__dirname, '..', 'build');
|
const buildDir = path.join(__dirname, '..', 'build');
|
||||||
@ -15,7 +17,7 @@ if (platform === 'win32') {
|
|||||||
libvips.mkdirSync(buildDir);
|
libvips.mkdirSync(buildDir);
|
||||||
libvips.mkdirSync(buildReleaseDir);
|
libvips.mkdirSync(buildReleaseDir);
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
const vendorLibDir = path.join(__dirname, '..', 'vendor', 'lib');
|
const vendorLibDir = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, 'lib');
|
||||||
npmLog.info('sharp', `Copying DLLs from ${vendorLibDir} to ${buildReleaseDir}`);
|
npmLog.info('sharp', `Copying DLLs from ${vendorLibDir} to ${buildReleaseDir}`);
|
||||||
try {
|
try {
|
||||||
fs
|
fs
|
||||||
|
@ -37,10 +37,12 @@ const fail = function (err) {
|
|||||||
const extractTarball = function (tarPath) {
|
const extractTarball = function (tarPath) {
|
||||||
const vendorPath = path.join(__dirname, '..', 'vendor');
|
const vendorPath = path.join(__dirname, '..', 'vendor');
|
||||||
libvips.mkdirSync(vendorPath);
|
libvips.mkdirSync(vendorPath);
|
||||||
|
const versionedVendorPath = path.join(vendorPath, minimumLibvipsVersion);
|
||||||
|
libvips.mkdirSync(versionedVendorPath);
|
||||||
tar
|
tar
|
||||||
.extract({
|
.extract({
|
||||||
file: tarPath,
|
file: tarPath,
|
||||||
cwd: vendorPath,
|
cwd: versionedVendorPath,
|
||||||
strict: true
|
strict: true
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
|
@ -48,17 +48,11 @@ const globalLibvipsVersion = function () {
|
|||||||
|
|
||||||
const hasVendoredLibvips = function () {
|
const hasVendoredLibvips = function () {
|
||||||
const currentPlatformId = platform();
|
const currentPlatformId = platform();
|
||||||
const vendorPath = path.join(__dirname, '..', 'vendor');
|
const vendorPath = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion);
|
||||||
let vendorVersionId;
|
|
||||||
let vendorPlatformId;
|
let vendorPlatformId;
|
||||||
try {
|
try {
|
||||||
vendorVersionId = require(path.join(vendorPath, 'versions.json')).vips;
|
|
||||||
vendorPlatformId = require(path.join(vendorPath, 'platform.json'));
|
vendorPlatformId = require(path.join(vendorPath, 'platform.json'));
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
/* istanbul ignore if */
|
|
||||||
if (vendorVersionId && vendorVersionId !== minimumLibvipsVersion) {
|
|
||||||
throw new Error(`Found vendored libvips v${vendorVersionId} but require v${minimumLibvipsVersion}. Please remove the 'node_modules/sharp/vendor' directory and run 'npm install'.`);
|
|
||||||
}
|
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
if (vendorPlatformId) {
|
if (vendorPlatformId) {
|
||||||
/* istanbul ignore else */
|
/* istanbul ignore else */
|
||||||
|
@ -23,7 +23,7 @@ let versions = {
|
|||||||
vips: sharp.libvipsVersion()
|
vips: sharp.libvipsVersion()
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
versions = require('../vendor/versions.json');
|
versions = require(`../vendor/${versions.vips}/versions.json`);
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,7 +137,7 @@
|
|||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"config": {
|
"config": {
|
||||||
"libvips": "8.9.1"
|
"libvips": "8.9.2-alpha2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user