<#446 Feat: Prebuildify pact.node for all FFI supp...
# pact-js-development
g
#446 Feat: Prebuildify pact.node for all FFI supported platform/architectures Pull request opened by YOU54F πŸ—£οΈ Context Would like Pact to run batteries included for all major platforms and architectures πŸ’¬ Narrative When run
npm install @pact-foundation/pact --ignore-scripts
on any major platform/architecture, and I am on a supported version of node, I should be able to install Pact πŸ—οΈ Design βœ… Acceptance Criteria GIVEN I have node version
16
,
18
or
20
installed AND I am on one of the following platforms WHEN I run
npm install @pact-foundation/pact --ignore-scripts
THEN I should be able to use
pact
βœ… = installs without build hooks, pre-built native library ❌ = not supported 🚫 Out of Scope β€’ Alpine Linux β€’ Requires
.so
file building - will come later β€’ Arm64 Windows β€’ Requires
.dll
file building - will come later πŸ“ Summary of Changes Changes proposed in this pull request: 1. use prebuilidfy
npx prebuildify --napi
to generate bindings for each targeted platform/arch combination
Copy code
❯tree prebuilds 
prebuilds
└── darwin-arm64
   β”œβ”€β”€ libpact_ffi.dylib
   └── node.napi.node
2. Use combination of cirrus-ci / github-actions to test generated
napi
build against supported LTS versions of node ⚠️ Items of Note Ruby arm64 runtimes β€’ Currently using #445 which relies on my pact-ruby-standalone fork release β€’ https://github.com/YOU54F/pact-ruby-standalone/releases/tag/v2.2.1 β€’ PR raised here - pact-foundation/pact-ruby-standalone#105 node-addon-api compatability ABI Matrix

Screenshot 2023-04-21 at 12 43 10β–Ύ

β€’ https://nodejs.org/api/n-api.html#node-api-version-matrix

Screenshot 2023-04-21 at 12 42 50β–Ύ

β€’ https://nodejs.org/en/download/releases We can see version in
NAPI_VERSION=3
here https://github.com/YOU54F/pact-js-core/blob/master/native/ffi.cc#L1 anything lower and it fails to build. Looking at the ABI compat matrix, version 8 supports v12 which is EOL, v14 which is going EOL end of the month, but raises minimum compat up to v15.12.0 (for v15 users) I'm not sure what the implications are of leaving it at the lowest version it will compile with (which is NAPI_VERSION=3). I also don't understand why that chart isn't updated, to include v17->v20, especially as that matrix for the node-api version matrix is on the node v20 ref docs This PR seeks to address those concerns, by allowing maintainers to easily add or remove different versions of node for testing, and ensuring the latest LTS versions are tested and covered. A combination of
nvm
and
nvs
is used to manage node versions in
.cirrus.yml
, as
nvs
offers a nicer interface for getting
x64
builds which you are on arm hardware (testing rosetta on MacOS) πŸ”¨ How To Test πŸ’» Local Machine 1. Checkout the branch
prebuildify
. 2. Run
bash script/download-libs.sh
β€’ This downloads the FFI libraries for building, end users wont do this 4. Run
npm ci --ignore-scripts
β€’ This installs our
node_modules
we only need
node-addon-api
for now 5. Run
npx prebuildify --napi
β€’ This run
node-gyp-build
and outputs a platform specific pact.node in the
prebuilds
directory β€’ This step used to be performed by end users, and required a full python build chain amongst other things with node-gyp 6. Run
rm -rf build ffi
β€’ This deletes folders we wont distribute in the end binary, and makes sure you are using the
prebuilds
β€’ It would read the prebuild anyway, but I just like to be sure 7. Run
npm run build
β€’ This transpiles the typescript into javascript 8. Run
npm run test
β€’ Hopefully all green! πŸ±β€πŸ’» Local Machine - GitHub Actions 1. Download Act 2. Download Docker (or Podman) Linux workflows
act --container-architecture linux/amd64 -W .github/workflows/build-and-test.yml --artifact-server-path pkgs
πŸ±β€πŸ’» Local Machine - Cirrus CLI 1. Download Cirrus CLI 2. Download Docker (or Podman) 3. If on an arm64 mac, download tart.run Linux workflows
cirrus run --output github-actions "linux_amd64" --artifacts-dir pkgs
MacOS workflows
cirrus run --output github-actions "macos_arm_prebuilder" --artifacts-dir pkgs
cirrus run --output github-actions "macos_x64_prebuilder" --artifacts-dir pkg
pact-foundation/pact-js-core GitHub Actions: release_dry_run βœ… 16 other checks have passed 16/17 successful checks