Skip to content

Commit

Permalink
Add support for statically-linked dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Jun 27, 2020
1 parent 85459e0 commit fbdac80
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 75 deletions.
115 changes: 51 additions & 64 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
'variables': {
'vips_version': '8.9.2',
'sharp_vendor_dir': '<(module_root_dir)/vendor/<(vips_version)'
},
'targets': [{
'target_name': 'libvips-cpp',
'conditions': [
Expand All @@ -16,15 +20,18 @@
'src/libvips/cplusplus/VImage.cpp'
],
'include_dirs': [
'vendor/include',
'vendor/include/glib-2.0',
'vendor/lib/glib-2.0/include'
],
'libraries': [
'../vendor/lib/libvips.lib',
'../vendor/lib/libglib-2.0.lib',
'../vendor/lib/libgobject-2.0.lib'
'<(sharp_vendor_dir)/include',
'<(sharp_vendor_dir)/include/glib-2.0',
'<(sharp_vendor_dir)/lib/glib-2.0/include'
],
'link_settings': {
'library_dirs': ['<(sharp_vendor_dir)/lib'],
'libraries': [
'libvips.lib',
'libglib-2.0.lib',
'libgobject-2.0.lib'
],
},
'configurations': {
'Release': {
'msvs_settings': {
Expand Down Expand Up @@ -110,74 +117,55 @@
}, {
# Use pre-built libvips stored locally within node_modules
'include_dirs': [
'vendor/include',
'vendor/include/glib-2.0',
'vendor/lib/glib-2.0/include'
'<(sharp_vendor_dir)/include',
'<(sharp_vendor_dir)/include/glib-2.0',
'<(sharp_vendor_dir)/lib/glib-2.0/include'
],
'conditions': [
['OS == "win"', {
'defines': [
'_ALLOW_KEYWORD_MACROS',
'_FILE_OFFSET_BITS=64'
],
'libraries': [
'../vendor/lib/libvips.lib',
'../vendor/lib/libglib-2.0.lib',
'../vendor/lib/libgobject-2.0.lib'
]
'link_settings': {
'library_dirs': ['<(sharp_vendor_dir)/lib'],
'libraries': [
'libvips.lib',
'libglib-2.0.lib',
'libgobject-2.0.lib'
]
}
}],
['OS == "mac"', {
'libraries': [
'../vendor/lib/libvips-cpp.42.dylib',
'../vendor/lib/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\''
]
'link_settings': {
'library_dirs': ['<(sharp_vendor_dir)/lib'],
'libraries': [
'libvips-cpp.42.dylib',
'libvips.42.dylib'
]
},
'xcode_settings': {
'OTHER_LDFLAGS': [
# Ensure runtime linking is relative to sharp.node
'-Wl,-rpath,\'@loader_path/../../vendor/<(vips_version)/lib\''
]
}
}],
['OS == "linux"', {
'defines': [
'_GLIBCXX_USE_CXX11_ABI=0'
],
'libraries': [
'../vendor/lib/libvips-cpp.so',
'../vendor/lib/libvips.so',
'../vendor/lib/libglib-2.0.so',
'../vendor/lib/libgobject-2.0.so',
# 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
'-Wl,-s -Wl,--disable-new-dtags -Wl,-rpath=\'$${ORIGIN}/../../vendor/lib\''
]
'link_settings': {
'library_dirs': ['<(sharp_vendor_dir)/lib'],
'libraries': [
'-l:libvips-cpp.so.42',
'-l:libvips.so.42'
],
'ldflags': [
# Ensure runtime linking is relative to sharp.node
'-Wl,-s -Wl,--disable-new-dtags -Wl,-rpath=\'$$ORIGIN/../../vendor/<(vips_version)/lib\''
]
}
}]
]
}]
Expand All @@ -190,8 +178,7 @@
],
'xcode_settings': {
'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '10.7',
'MACOSX_DEPLOYMENT_TARGET': '10.9',
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'GCC_ENABLE_CPP_RTTI': 'YES',
'OTHER_CPLUSPLUSFLAGS': [
Expand Down
4 changes: 3 additions & 1 deletion install/dll-copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const path = require('path');
const libvips = require('../lib/libvips');
const npmLog = require('npmlog');

const minimumLibvipsVersion = libvips.minimumLibvipsVersion;

const platform = process.env.npm_config_platform || process.platform;
if (platform === 'win32') {
const buildDir = path.join(__dirname, '..', 'build');
Expand All @@ -15,7 +17,7 @@ if (platform === 'win32') {
libvips.mkdirSync(buildDir);
libvips.mkdirSync(buildReleaseDir);
} 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}`);
try {
fs
Expand Down
4 changes: 3 additions & 1 deletion install/libvips.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ const fail = function (err) {
const extractTarball = function (tarPath) {
const vendorPath = path.join(__dirname, '..', 'vendor');
libvips.mkdirSync(vendorPath);
const versionedVendorPath = path.join(vendorPath, minimumLibvipsVersion);
libvips.mkdirSync(versionedVendorPath);
tar
.extract({
file: tarPath,
cwd: vendorPath,
cwd: versionedVendorPath,
strict: true
})
.catch(function (err) {
Expand Down
8 changes: 1 addition & 7 deletions lib/libvips.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,11 @@ const globalLibvipsVersion = function () {

const hasVendoredLibvips = function () {
const currentPlatformId = platform();
const vendorPath = path.join(__dirname, '..', 'vendor');
let vendorVersionId;
const vendorPath = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion);
let vendorPlatformId;
try {
vendorVersionId = require(path.join(vendorPath, 'versions.json')).vips;
vendorPlatformId = require(path.join(vendorPath, 'platform.json'));
} 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 */
if (vendorPlatformId) {
/* istanbul ignore else */
Expand Down
2 changes: 1 addition & 1 deletion lib/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let versions = {
vips: sharp.libvipsVersion()
};
try {
versions = require('../vendor/versions.json');
versions = require(`../vendor/${versions.vips}/versions.json`);
} catch (err) {}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
},
"license": "Apache-2.0",
"config": {
"libvips": "8.9.1"
"libvips": "8.9.2-alpha2"
},
"engines": {
"node": ">=10"
Expand Down

0 comments on commit fbdac80

Please sign in to comment.