Skip to content

Commit

Permalink
WIP: Add infra to publish as platform-dependent npm packages
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Sep 24, 2023
1 parent 0f8bb91 commit 09d5170
Show file tree
Hide file tree
Showing 34 changed files with 780 additions and 725 deletions.
24 changes: 24 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ jobs:
sudo docker exec sharp sh -c "apt-get update && apt-get install -y nodejs"
- run: sudo docker exec sharp sh -c "npm install --build-from-source"
- run: sudo docker exec sharp sh -c "npm test"
- run: |
sudo docker exec sharp sh -c "npm run package-from-local-build"
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@sharpen/sharp-linux-arm64=file:./npm/linux-arm64\""
sudo docker exec sharp sh -c "npm run clean"
sudo docker exec sharp sh -c "npm install --ignore-scripts"
sudo docker exec sharp sh -c "npm test"
- run: "[[ -n $CIRCLE_TAG ]] && sudo docker exec --env prebuild_upload sharp sh -c \"npx prebuild --upload=$prebuild_upload\" || true"
linux-arm64-glibc-node-20:
resource_class: arm.medium
Expand All @@ -54,6 +60,12 @@ jobs:
sudo docker cp . sharp:/mnt/sharp/.
- run: sudo docker exec sharp sh -c "npm install --build-from-source"
- run: sudo docker exec sharp sh -c "npm test"
- run: |
sudo docker exec sharp sh -c "npm run package-from-local-build"
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@sharpen/sharp-linux-arm64=file:./npm/linux-arm64\""
sudo docker exec sharp sh -c "npm run clean"
sudo docker exec sharp sh -c "npm install --ignore-scripts"
sudo docker exec sharp sh -c "npm test"
linux-arm64-musl-node-18:
resource_class: arm.medium
machine:
Expand All @@ -65,6 +77,12 @@ jobs:
sudo docker exec sharp sh -c "apk add build-base git python3 font-noto --update-cache"
- run: sudo docker exec sharp sh -c "npm install --build-from-source"
- run: sudo docker exec sharp sh -c "npm test"
- run: |
sudo docker exec sharp sh -c "npm run package-from-local-build"
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@sharpen/sharp-linuxmusl-arm64=file:./npm/linuxmusl-arm64\""
sudo docker exec sharp sh -c "npm run clean"
sudo docker exec sharp sh -c "npm install --ignore-scripts"
sudo docker exec sharp sh -c "npm test"
- run: "[[ -n $CIRCLE_TAG ]] && sudo docker exec --env prebuild_upload sharp sh -c \"npx prebuild --upload=$prebuild_upload\" || true"
linux-arm64-musl-node-20:
resource_class: arm.medium
Expand All @@ -79,3 +97,9 @@ jobs:
sudo docker cp . sharp:/mnt/sharp/.
- run: sudo docker exec sharp sh -c "npm install --build-from-source"
- run: sudo docker exec sharp sh -c "npm test"
- run: |
sudo docker exec sharp sh -c "npm run package-from-local-build"
sudo docker exec sharp sh -c "npm pkg set \"optionalDependencies.@sharpen/sharp-linuxmusl-arm64=file:./npm/linuxmusl-arm64\""
sudo docker exec sharp sh -c "npm run clean"
sudo docker exec sharp sh -c "npm install --ignore-scripts"
sudo docker exec sharp sh -c "npm test"
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
- os: macos-11
nodejs_arch: x64
nodejs_version: "^18.17.0"
nodejs_version_major: 18
platform: darwin-x64
prebuild: true
- os: macos-11
Expand Down Expand Up @@ -105,6 +106,13 @@ jobs:
run: npm install --build-from-source
- name: Test
run: npm test
- name: Test packaging
run: |
npm run package-from-local-build
npm pkg set "optionalDependencies.@sharpen/sharp-${{ matrix.platform }}=file:./npm/${{ matrix.platform }}"
npm run clean
npm install --ignore-scripts
npm test
- name: Prebuild
if: matrix.prebuild && startsWith(github.ref, 'refs/tags/')
env:
Expand Down Expand Up @@ -133,6 +141,11 @@ jobs:
chown root.root .
npm install --build-from-source
npx mocha --no-config --spec=test/unit/io.js
npm run package-from-local-build
npm pkg set "optionalDependencies.@sharpen/sharp-linux-arm=file:./npm/linux-arm"
npm run clean
npm install --ignore-scripts
npx mocha --no-config --spec=test/unit/io.js
[[ -n $prebuild_upload ]] && npx prebuild || true
macstadium-runner:
permissions:
Expand Down Expand Up @@ -167,6 +180,13 @@ jobs:
run: npm install --build-from-source
- name: Test
run: npm test
- name: Test packaging
run: |
npm run package-from-local-build
npm pkg set "optionalDependencies.@sharpen/sharp-${{ matrix.platform }}=file:./npm/${{ matrix.platform }}"
npm run clean
npm install --ignore-scripts
npm test
- name: Prebuild
if: matrix.prebuild && startsWith(github.ref, 'refs/tags/')
env:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
build
node_modules
/coverage
npm/*/*
!npm/*/package.json
test/bench/node_modules
test/fixtures/output*
test/fixtures/vips-properties.xml
Expand All @@ -9,7 +11,6 @@ test/saliency/report.json
test/saliency/Image*
test/saliency/[Uu]serData*
!test/saliency/userData.js
vendor
.gitattributes
.DS_Store
.nyc_output
Expand Down
2 changes: 1 addition & 1 deletion .prebuildrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"runtime": "napi",
"include-regex": "(sharp-.+\\.node|libvips-cpp\\.dll)",
"include-regex": "(sharp-.+\\.node|libvips-.+\\.dll|libglib-.+\\.dll|libgobject-.+\\.dll)",
"prerelease": true,
"strip": true
}
82 changes: 55 additions & 27 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Copyright 2013 Lovell Fuller and others.
# SPDX-License-Identifier: Apache-2.0

{
'variables': {
'vips_version': '<!(node -p "require(\'./lib/libvips\').minimumLibvipsVersion")',
'platform_and_arch': '<!(node -p "require(\'./lib/platform\')()")',
'sharp_vendor_dir': './vendor/<(vips_version)/<(platform_and_arch)'
'platform_and_arch': '<!(node -p "require(\'./lib/libvips\').buildPlatformArch()")',
'sharp_libvips_include_dir': '<!(node -p "require(\'./lib/libvips\').buildSharpLibvipsIncludeDir()")',
'sharp_libvips_cplusplus_dir': '<!(node -p "require(\'./lib/libvips\').buildSharpLibvipsCPlusPlusDir()")',
'sharp_libvips_lib_dir': '<!(node -p "require(\'./lib/libvips\').buildSharpLibvipsLibDir()")'
},
'targets': [{
'target_name': 'libvips-cpp',
'target_name': 'win-libvips-cpp',
'conditions': [
['OS == "win"', {
# Build libvips C++ binding for Windows due to MSVC std library ABI changes
Expand All @@ -15,19 +20,19 @@
'_ALLOW_KEYWORD_MACROS'
],
'sources': [
'src/libvips/cplusplus/VConnection.cpp',
'src/libvips/cplusplus/VError.cpp',
'src/libvips/cplusplus/VImage.cpp',
'src/libvips/cplusplus/VInterpolate.cpp',
'src/libvips/cplusplus/VRegion.cpp'
'<(sharp_libvips_cplusplus_dir)/VConnection.cpp',
'<(sharp_libvips_cplusplus_dir)/VError.cpp',
'<(sharp_libvips_cplusplus_dir)/VImage.cpp',
'<(sharp_libvips_cplusplus_dir)/VInterpolate.cpp',
'<(sharp_libvips_cplusplus_dir)/VRegion.cpp'
],
'include_dirs': [
'<(sharp_vendor_dir)/include',
'<(sharp_vendor_dir)/include/glib-2.0',
'<(sharp_vendor_dir)/lib/glib-2.0/include'
'<(sharp_libvips_include_dir)',
'<(sharp_libvips_include_dir)/glib-2.0',
'<(sharp_libvips_lib_dir)/glib-2.0/include'
],
'link_settings': {
'library_dirs': ['<(sharp_vendor_dir)/lib'],
'library_dirs': ['<(sharp_libvips_lib_dir)'],
'libraries': [
'libvips.lib',
'libglib-2.0.lib',
Expand Down Expand Up @@ -76,10 +81,9 @@
],
'dependencies': [
'<!(node -p "require(\'node-addon-api\').gyp")',
'libvips-cpp'
'win-libvips-cpp'
],
'variables': {
'runtime_link%': 'shared',
'conditions': [
['OS != "win"', {
'pkg_config_path': '<!(node -p "require(\'./lib/libvips\').pkgConfigPath()")',
Expand All @@ -106,12 +110,8 @@
['use_global_libvips == "true"', {
# Use pkg-config for include and lib
'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s\/-I//g)'],
'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs vips-cpp)'],
'conditions': [
['runtime_link == "static"', {
'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs --static vips-cpp)']
}, {
'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs vips-cpp)']
}],
['OS == "linux"', {
'defines': [
# Inspect libvips-cpp.so to determine which C++11 ABI version was used and set _GLIBCXX_USE_CXX11_ABI accordingly. This is quite horrible.
Expand All @@ -122,9 +122,9 @@
}, {
# Use pre-built libvips stored locally within node_modules
'include_dirs': [
'<(sharp_vendor_dir)/include',
'<(sharp_vendor_dir)/include/glib-2.0',
'<(sharp_vendor_dir)/lib/glib-2.0/include'
'<(sharp_libvips_include_dir)',
'<(sharp_libvips_include_dir)/glib-2.0',
'<(sharp_libvips_lib_dir)/glib-2.0/include'
],
'conditions': [
['OS == "win"', {
Expand All @@ -133,7 +133,7 @@
'_FILE_OFFSET_BITS=64'
],
'link_settings': {
'library_dirs': ['<(sharp_vendor_dir)/lib'],
'library_dirs': ['<(sharp_libvips_lib_dir)'],
'libraries': [
'libvips.lib',
'libglib-2.0.lib',
Expand All @@ -143,15 +143,19 @@
}],
['OS == "mac"', {
'link_settings': {
'library_dirs': ['../<(sharp_vendor_dir)/lib'],
'library_dirs': [
'<(sharp_libvips_lib_dir)'
],
'libraries': [
'libvips-cpp.42.dylib'
]
},
'xcode_settings': {
'OTHER_LDFLAGS': [
# Ensure runtime linking is relative to sharp.node
'-Wl,-rpath,\'@loader_path/../../<(sharp_vendor_dir)/lib\''
'-Wl,-rpath,\'@loader_path/../../sharp-libvips-<(platform_and_arch)/lib\'',
'-Wl,-rpath,\'@loader_path/../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\'',
'-Wl,-rpath,\'@loader_path/../../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\''
]
}
}],
Expand All @@ -160,13 +164,19 @@
'_GLIBCXX_USE_CXX11_ABI=1'
],
'link_settings': {
'library_dirs': ['../<(sharp_vendor_dir)/lib'],
'library_dirs': [
'<(sharp_libvips_lib_dir)'
],
'libraries': [
'-l:libvips-cpp.so.42'
],
'ldflags': [
# Ensure runtime linking is relative to sharp.node
'-Wl,-s -Wl,--disable-new-dtags -Wl,-rpath=\'$$ORIGIN/../../<(sharp_vendor_dir)/lib\''
'-Wl,-s',
'-Wl,--disable-new-dtags',
'-Wl,-rpath=\'$$ORIGIN/../../sharp-libvips-<(platform_and_arch)/lib\'',
'-Wl,-rpath=\'$$ORIGIN/../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\'',
'-Wl,-rpath=\'$$ORIGIN/../../../node_modules/@sharpen/sharp-libvips-<(platform_and_arch)/lib\''
]
}
}]
Expand Down Expand Up @@ -232,5 +242,23 @@
]
}
},
}, {
'target_name': 'win-copy-dlls',
'type': 'none',
'dependencies': [
'sharp-<(platform_and_arch)'
],
'conditions': [
['OS == "win"', {
'copies': [{
'destination': 'build/Release',
'files': [
'<(sharp_libvips_lib_dir)/libvips-42.dll',
'<(sharp_libvips_lib_dir)/libglib-2.0-0.dll',
'<(sharp_libvips_lib_dir)/libgobject-2.0-0.dll'
]
}]
}]
]
}]
}
14 changes: 0 additions & 14 deletions install/can-compile.js

This file was deleted.

18 changes: 18 additions & 0 deletions install/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2013 Lovell Fuller and others.
// SPDX-License-Identifier: Apache-2.0

'use strict';

const { useGlobalLibvips, globalLibvipsVersion, log } = require('../lib/libvips');

const buildFromSource = (msg) => {
log(msg);
log('Building from source via node-gyp');
process.exitCode = 1;
};

if (process.env.npm_config_build_from_source) {
buildFromSource('Detected --build-from-source flag');
} else if (useGlobalLibvips()) {
buildFromSource(`Detected globally-installed libvips v${globalLibvipsVersion()}`);
}
40 changes: 0 additions & 40 deletions install/dll-copy.js

This file was deleted.

Loading

0 comments on commit 09d5170

Please sign in to comment.