Skip to content

Commit

Permalink
wip: alpine static libs
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Feb 7, 2024
1 parent d349b99 commit 901386e
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 159 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,25 @@ jobs:
- if: runner.os == 'Windows'
run: echo "ONLY_DOWNLOAD_PACT_FOR_WINDOWS=true" >> $GITHUB_ENV

- run: ./script/ci/prebuild.sh

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: runner.os == 'Linux'
uses: docker/setup-buildx-action@v3

- if: runner.os == 'Linux'
name: prebuild arm64
name: prebuild linux arm64
run: docker run -v $PWD:/home --platform linux/arm64 --rm node:20 bin/bash -c 'cd /home && /home/script/ci/prebuild.sh'
- if: runner.os == 'Linux'
name: prebuild linux amd64 musl
run: docker run -v $PWD:/home --platform linux/amd64 --rm node:20-alpine bin/bash -c 'apk add bash curl python3 make g++ && cd /home && /home/script/ci/prebuild.sh && npm run build && npm test'
- if: runner.os == 'Linux'
name: prebuild linux arm64 musl
run: docker run -v $PWD:/home --platform linux/arm64 --rm node:20-alpine bin/bash -c 'apk add bash curl python3 make g++ && cd /home && /home/script/ci/prebuild.sh && npm run build && npm test'

- run: ./script/ci/prebuild.sh
- name: Upload prebuild for ${{ runner.os }}-${{ runner.arch }}
uses: actions/upload-artifact@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ standalone/*.gz
standalone/README.md
# FFI native bindings
*.so
*.a
*.dll*
*.dylib
pact.h
Expand Down
321 changes: 176 additions & 145 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,150 +1,181 @@
{
"targets": [
{
"target_name": "pact",
"sources": [
"native/addon.cc",
"native/ffi.cc",
"native/consumer.cc",
"native/provider.cc",
"native/plugin.cc"
],
"include_dirs": [
"<!(node -p \"require('node-addon-api').include_dir\")",
"<(module_root_dir)/native",
"<(module_root_dir)/ffi",
],
"conditions": [
[
"OS=='win'",
{
"libraries": [
"<(module_root_dir)/ffi/pact_ffi.dll.lib"
"variables": {
"is_alpine": "<!(grep -q Alpine /etc/os-release && echo true || echo false)"
},
"targets": [
{
"target_name": "pact",
"sources": [
"native/addon.cc",
"native/ffi.cc",
"native/consumer.cc",
"native/provider.cc",
"native/plugin.cc"
],
"defines": [
"_HAS_EXCEPTIONS=1"
"include_dirs": [
"<!(node -p \"require('node-addon-api').include_dir\")",
"<(module_root_dir)/native",
"<(module_root_dir)/ffi",
],
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": 1
}
},
"copies":[{
"files": [ "<(module_root_dir)/ffi/pact_ffi.dll"],
"destination": "<(PRODUCT_DIR)"
}],
}
],
[
"OS==\"mac\" and target_arch ==\"x64\"",
{
"xcode_settings": {
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES",
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
"GCC_TREAT_WARNINGS_AS_ERRORS": "YES",
"CLANG_CXX_LIBRARY": "libc++",
"MACOSX_DEPLOYMENT_TARGET": "10.7"
},
"link_settings": {
"libraries": [
"-lpact_ffi",
"-L<(module_root_dir)/ffi",
"-Wl,-rpath,@loader_path"
]
},
"copies":[{
"files": [ "<(module_root_dir)/ffi/libpact_ffi.dylib"],
"destination": "<(PRODUCT_DIR)"
}],
}
],
[
"OS==\"mac\" and target_arch ==\"arm64\"",
{
"xcode_settings": {
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES",
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
"GCC_TREAT_WARNINGS_AS_ERRORS": "YES",
"CLANG_CXX_LIBRARY": "libc++",
"MACOSX_DEPLOYMENT_TARGET": "10.7"
},
"link_settings": {
"libraries": [
"-lpact_ffi",
"-L<(module_root_dir)/ffi",
"-Wl,-rpath,@loader_path"
]
},
"copies":[{
"files": [ "<(module_root_dir)/ffi/osxaarch64/libpact_ffi.dylib"],
"destination": "<(PRODUCT_DIR)"
}],
}
],
[
"OS==\"linux\" and target_arch ==\"x64\"",
{
"link_settings": {
"libraries": [
"-lpact_ffi",
"-L<(module_root_dir)/ffi",
"-Wl,-rpath,'$$ORIGIN'"
]
},
"copies":[{
"files": [ "<(module_root_dir)/ffi/libpact_ffi.so"],
"destination": "<(PRODUCT_DIR)"
}],
}
],
[
"OS==\"linux\" and target_arch ==\"arm64\"",
{
"link_settings": {
"libraries": [
"-lpact_ffi",
"-L<(module_root_dir)/ffi/linuxaarch64",
"-Wl,-rpath,'$$ORIGIN'"
]
},
"copies":[{
"files": [ "<(module_root_dir)/ffi/linuxaarch64/libpact_ffi.so"],
"destination": "<(PRODUCT_DIR)"
}],
}
]
],
"library_dirs": [
"<(module_root_dir)/native"
],
"cflags_cc!": [
"-fno-exceptions",
],
"cflags_cc": [ "-Werror" ],
"defines": [
"NAPI_CPP_EXCEPTIONS"
]
},
# Need to set the library install name to enable the rpath settings to work on OSX
{
"target_name": "set_osx_install_name",
"dependencies": ["pact"],
"type": "none",
"target_conditions":[
[
"OS==\"mac\"",
{
"actions": [
{
"action_name": "modify install_name on osx",
"inputs": ["<(module_root_dir)/build/Release/pact.node"],
"outputs": ["<(module_root_dir)/build/Release/pact.node"],
'action': ['install_name_tool', '-change', 'libpact_ffi.dylib', '@rpath/libpact_ffi.dylib', '<(module_root_dir)/build/Release/pact.node'],
}
"conditions": [
[
"OS=='win'",
{
"libraries": [
"<(module_root_dir)/ffi/windows-x86_64/pact_ffi.dll.lib"
],
"defines": [
"_HAS_EXCEPTIONS=1"
],
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": 1
}
},
"copies": [{
"files": ["<(module_root_dir)/ffi/windows-x86_64/pact_ffi.dll"],
"destination": "<(PRODUCT_DIR)"
}],
}
],
[
"OS==\"mac\" and target_arch ==\"x64\"",
{
"xcode_settings": {
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES",
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
"GCC_TREAT_WARNINGS_AS_ERRORS": "YES",
"CLANG_CXX_LIBRARY": "libc++",
"MACOSX_DEPLOYMENT_TARGET": "10.7"
},
"link_settings": {
"libraries": [
"-lpact_ffi",
"-L<(module_root_dir)/ffi",
"-Wl,-rpath,@loader_path"
]
},
"copies": [{
"files": ["<(module_root_dir)/ffi/osx-x86_64/libpact_ffi.dylib"],
"destination": "<(PRODUCT_DIR)"
}],
}
],
[
"OS==\"mac\" and target_arch ==\"arm64\"",
{
"xcode_settings": {
"GCC_SYMBOLS_PRIVATE_EXTERN": "YES",
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
"GCC_TREAT_WARNINGS_AS_ERRORS": "YES",
"CLANG_CXX_LIBRARY": "libc++",
"MACOSX_DEPLOYMENT_TARGET": "10.7"
},
"link_settings": {
"libraries": [
"-lpact_ffi",
"-L<(module_root_dir)/ffi",
"-Wl,-rpath,@loader_path"
]
},
"copies": [{
"files": ["<(module_root_dir)/ffi/osx-aarch64/libpact_ffi.dylib"],
"destination": "<(PRODUCT_DIR)"
}],
}
],
[
"OS==\"linux\" and target_arch ==\"x64\" and is_alpine ==\"true\"",
{
"link_settings": {
"libraries": [
"<(module_root_dir)/ffi/linux-x86_64/libpact_ffi.a"
]
},
"copies": [{
"files": ["./ffi/linux-x86_64/libpact_ffi.a"],
"destination": "prebuilds/linux-x64"
}],
}
],
[
"OS==\"linux\" and target_arch ==\"arm64\" and is_alpine ==\"true\"",
{
"link_settings": {
"libraries": [
"<(module_root_dir)/ffi/linux-aarch64/libpact_ffi.a"
]
},
"copies": [{
"files": ["./ffi/linux-aarch64/libpact_ffi.a"],
"destination": "prebuilds/linux-arm64"
}],
}
],
[
"OS==\"linux\" and target_arch ==\"x64\" and is_alpine ==\"false\"",
{
"link_settings": {
"libraries": [
"-lpact_ffi",
"-L<(module_root_dir)/ffi/linux-x86_64/",
"-Wl,-rpath,'$$ORIGIN'"
]
},
"copies": [{
"files": ["<(module_root_dir)/ffi/linux-x86_64/libpact_ffi.so"],
"destination": "<(PRODUCT_DIR)"
}],
}
],
[
"OS==\"linux\" and target_arch ==\"arm64\" and is_alpine ==\"false\"",
{
"link_settings": {
"libraries": [
"-lpact_ffi",
"-L<(module_root_dir)/ffi/linux-aarch64",
"-Wl,-rpath,'$$ORIGIN'"
]
},
"copies": [{
"files": ["<(module_root_dir)/ffi/linux-aarch64/libpact_ffi.so"],
"destination": "<(PRODUCT_DIR)"
}],
}
],
],
"library_dirs": [
"<(module_root_dir)/native"
],
"cflags_cc!": [
"-fno-exceptions",
],
"cflags_cc": ["-Werror"],
"defines": [
"NAPI_CPP_EXCEPTIONS"
]
},
# Need to set the library install name to enable the rpath settings to work on OSX
{
"target_name": "set_osx_install_name",
"dependencies": ["pact"],
"type": "none",
"target_conditions": [
[
"OS==\"mac\"",
{
"actions": [
{
"action_name": "modify install_name on osx",
"inputs": ["<(module_root_dir)/build/Release/pact.node"],
"outputs": ["<(module_root_dir)/build/Release/pact.node"],
'action': ['install_name_tool', '-change', 'libpact_ffi.dylib', '@rpath/libpact_ffi.dylib', '<(module_root_dir)/build/Release/pact.node'],
}
]
}
]
]
}
]
]
}
]
}
]
}
6 changes: 6 additions & 0 deletions script/ci/prebuild-alpine-in-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh -eu

rm -rf node_modules
docker run -v $PWD:/home --platform=linux/amd64 --rm -it node:alpine bin/sh -c 'apk add bash curl python3 make g++ && cd /home && /home/script/ci/prebuild-alpine.sh && npm run build && npm test'
rm -rf node_modules
docker run -v $PWD:/home --platform=linux/arm64 --rm -it node:alpine bin/sh -c 'apk add bash curl python3 make g++ && cd /home && /home/script/ci/prebuild-alpine.sh && npm run build && npm test'
16 changes: 16 additions & 0 deletions script/ci/prebuild-alpine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash -eu
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" # Figure out where the script is running

node --version
npm --version
PREBUILDIFY_VERSION=5.0.1

cd /home

. "${SCRIPT_DIR}/../lib/export-binary-versions.sh"
"${SCRIPT_DIR}/../lib/download-ffi.sh"
apk add bash curl python3 make g++
npm ci --ignore-scripts
npx --yes prebuildify@${PREBUILDIFY_VERSION} --napi --libc musl --tag-libc
ls prebuilds/**/*
rm -rf ffi build
Loading

0 comments on commit 901386e

Please sign in to comment.