Skip to content

Commit

Permalink
feat: enable platform/arch specific packages
Browse files Browse the repository at this point in the history
publish packages

  "@pact-foundation/pact-core-darwin-arm64": "16.0.0",
    "@pact-foundation/pact-core-darwin-x64": "16.0.0",
    "@pact-foundation/pact-core-linux-arm64-glibc": "16.0.0",
    "@pact-foundation/pact-core-linux-arm64-musl": "16.0.0",
    "@pact-foundation/pact-core-linux-x64-glibc": "16.0.0",
    "@pact-foundation/pact-core-linux-x64-musl": "16.0.0",
    "@pact-foundation/pact-core-windows-x64": "16.0.0"
  • Loading branch information
YOU54F committed Jan 22, 2025
1 parent 23db9d0 commit 0fd192f
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ reports
tmp
.tmp
test/__testoutput__

# platform-arch specific packages
@pact-foundation/*
9 changes: 8 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,11 @@ DEVELOPER.md
RELEASING.md
test.js
tsconfig.build.json
tsconfig.json
tsconfig.json

# Standalone Binaries - Published as seperate packages
@pact-foundation/

# Cross packaging files
Makefile
package.json.tmpl
101 changes: 70 additions & 31 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ Pact-Js-Core uses FFI bindings from the pact-reference project, which are prebui

Do this and you should be 👌👌👌:

```
```sh
bash script/ci/prebuild.sh
npm ci --ignore-scripts
make supported_platforms=darwin-arm64 build_opt_deps
make supported_platforms=darwin-arm64 link
npm run build
npm test
npm run test
```

set supported platform to one of these values

- `linux-x64`
- `linux-arm64`
- `darwin-x64`
- `darwin-arm64`
- `windows-x64`

_notes_ -

As a developer, you need to run `bash script/ci/prebuild.sh` to
Expand All @@ -32,61 +41,91 @@ Alternatively you can run the following, which will not create a prebuild, but i
bash script/download-libs.sh
npm ci
npm run build
npm test
npm run test
```

### Linux x86_64 Task
## Creating Platform specific packages

#### Pre Reqs
We create cross-platform and architecture binaries which are published individually to NPM, and consumed in this project.

1. x86_64 Machine
1. ARM64 Mac - If you have Rosetta (MacOS)
### Download prebuilt binaries for all platforms

### CI Locally
```sh
make libs
```

1. Docker/Podman
2. Act
This will run the following script, which will grab the latest prebuilt binaries from GitHub.

```sh
act --container-architecture linux/amd64 -W .github/workflows/build-and-test.yml --artifact-server-path tmp
FETCH_ASSETS=true ./script/ci/check-release-libs.sh --fetch-assets -t v15.2.1
```

### MacOS ARM64 Task
### Building all platform specific npm packages

#### Pre Reqs
```sh
make build_opt_deps
```

1. Arm64 Mac
2. Cirrus-Cli
3. Tart.run
### Building individual platform specific npm package

Supported platforms are

```sh
cirrus run --output github-actions macos_arm --artifacts-dir tmp
supported_platforms?="linux-x64" "linux-arm64" "darwin-x64" "darwin-arm64" "windows-x64"
```

### Linux ARM64 Task
You can build with one

#### Pre Reqs
```sh
make supported_platforms=darwin-arm64 build_opt_deps
```

1. Arm64 Machine
or multiple

### CI Locally
```sh
make supported_platforms="darwin-arm64 darwin-amd64" build_opt_deps
```

1. Arm64 Machine
2. Docker / Podman
3. Cirrus-Cli
### Linking arch specific package, for your local build

Make link will try to link all available packages, for all available platforms, and will link any that apply

```sh
cirrus run --output github-actions linux_arm --artifacts-dir tmp
make link
```

#### Publishing Assets
You can scope it with `supported_platforms`

MacOS ARM64
```sh
make supported_platforms=darwin-arm64 link
```

### Publishing packages

Dry run publishing optional packages, (default)

```sh
make publish_opt_deps
```

`cirrus run --output github-actions macos_arm --artifacts-dir tmp --environment GITHUB_TOKEN=$GITHUB_TOKEN --environment CIRRUS_RELEASE=test --environment CIRRUS_REPO_FULL_NAME=pact-foundation/pact-js-core;`
Publishing packages with `--dry-run` option removed.

Linux ARM64
```sh
make DRY_RUN= publish_opt_deps
```

### Linux x86_64 Task

#### Pre Reqs

`cirrus run --output github-actions linux_arm --artifacts-dir tmp --environment GITHUB_TOKEN=$GITHUB_TOKEN --environment CIRRUS_RELEASE=test --environment CIRRUS_REPO_FULL_NAME=pact-foundation/pact-js-core;`
1. x86_64 Machine
1. ARM64 Mac - If you have Rosetta (MacOS)

### CI Locally

1. Docker/Podman
2. Act

```sh
act --container-architecture linux/amd64 -W .github/workflows/build-and-test.yml --artifact-server-path tmp
```
116 changes: 116 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
SHELL:=/bin/bash
export bin=@pact-foundation/pact-core
export pkg_version?=$(shell cat package.json | jq -r .version)
supported_platforms?="linux-x64-glibc" "linux-arm64-glibc" "linux-x64-musl" "linux-arm64-musl" "darwin-x64" "darwin-arm64" "windows-x64"

# https://github.com/npm/npm/issues/17722
# https://github.com/npm/cli/issues/4828
# https://github.com/orhun/packaging-rust-for-npm
# https://blog.orhun.dev/packaging-rust-for-npm/

clean:
rm -rf @pact-foundation
npm run clean-libs
libs:
FETCH_ASSETS=true ./script/ci/check-release-libs.sh --fetch-assets -t v$(pkg_version)

DRY_RUN?=--dry-run
build_opt_deps:
for supported_platform in $(supported_platforms); do \
IFS='-' read -r node_os node_arch node_libc <<< "$$supported_platform"; \
export node_os=$$node_os; \
export node_arch=$$node_arch; \
export node_libc=$$node_libc; \
if [ "$$node_os" = "windows" ]; then \
export node_os="win32"; \
fi; \
if [ "$$node_libc" = "glibc" ]; then \
export libc='"libc": ["glibc"],'; \
fi; \
if [ "$$node_libc" = "musl" ]; then \
export libc='"libc": ["musl"],'; \
fi; \
if [ "$$node_libc" = "musl" ]||[ "$$node_libc" = "glibc" ]; then \
export standalone_package=prebuilds/$$node_os-$$node_arch; \
export node_pkg=$(bin)-$$node_os-$$node_arch-$$node_libc; \
else \
export standalone_package=prebuilds/$$node_os-$$node_arch; \
export node_pkg=$(bin)-$$node_os-$$node_arch; \
fi; \
echo "Building for $$node_os-$$node_arch"; \
echo "Building $$node_pkg"; \
mkdir -p "$$node_pkg/prebuilds"; \
cp -R "$$standalone_package" "$$node_pkg/prebuilds"; \
if [ "$$node_libc" = "glibc" ]; then \
find "$$node_pkg/prebuilds" -type f -name '*musl*' -exec rm -f {} +; \
fi; \
if [ "$$node_libc" = "musl" ]; then \
find "$$node_pkg/prebuilds" -type f ! -name '*musl*' -exec rm -f {} +; \
fi; \
envsubst < package.json.tmpl > "$$node_pkg/package.json"; \
(cd $$node_pkg && npm publish --access public $(DRY_RUN);)\
done

update_opt_deps:
@for supported_platform in $(supported_platforms); do \
IFS='-' read -r node_os node_arch node_libc <<< "$$supported_platform"; \
if [ "$$node_libc" = "musl" ]||[ "$$node_libc" = "glibc" ]; then \
export node_pkg=$(bin)-$$node_os-$$node_arch-$$node_libc; \
else \
export node_pkg=$(bin)-$$node_os-$$node_arch; \
fi; \
jq '.optionalDependencies."'$$node_pkg'" = "$(pkg_version)"' package.json > package-new.json; \
mv package-new.json package.json; \
done

publish_opt_package:
set -eu; for supported_platform in $(supported_platforms); do \
IFS='-' read -r node_os node_arch node_libc <<< "$$supported_platform"; \
export node_os=$$node_os; \
export node_arch=$$node_arch; \
export node_libc=$$node_libc; \
if [ "$$node_os" = "windows" ]; then \
export node_os="win32"; \
fi; \
if [ "$$node_libc" = "glibc" ]; then \
export libc='"libc": ["glibc"],'; \
fi; \
if [ "$$node_libc" = "musl" ]; then \
export libc='"libc": ["musl"],'; \
fi; \
if [ "$$node_libc" = "musl" ]||[ "$$node_libc" = "glibc" ]; then \
export standalone_package=prebuilds/$$node_os-$$node_arch-$$node_libc; \
export node_pkg=$(bin)-$$node_os-$$node_arch-$$node_libc; \
else \
export standalone_package=prebuilds/$$node_os-$$node_arch; \
export node_pkg=$(bin)-$$node_os-$$node_arch; \
fi; \
echo "Building for $$node_os-$$node_arch"; \
echo "Building $$node_pkg for $$node_os-$$node_arch"; \
(cd $$node_pkg && npm publish --access public $(DRY_RUN);)\
done
link:
set -eu; for supported_platform in $(supported_platforms); do \
IFS='-' read -r node_os node_arch node_libc <<< "$$supported_platform"; \
export node_os=$$node_os; \
export node_arch=$$node_arch; \
export node_libc=$$node_libc; \
if [ "$$node_os" = "windows" ]; then \
export node_os="win32"; \
fi; \
if [ "$$node_libc" = "glibc" ]; then \
export libc='"libc": ["glibc"],'; \
fi; \
if [ "$$node_libc" = "musl" ]; then \
export libc='"libc": ["musl"],'; \
fi; \
if [ "$$node_libc" = "musl" ]||[ "$$node_libc" = "glibc" ]; then \
export standalone_package=prebuilds/$$node_os-$$node_arch-$$node_libc; \
export node_pkg=$(bin)-$$node_os-$$node_arch-$$node_libc; \
else \
export standalone_package=prebuilds/$$node_os-$$node_arch; \
export node_pkg=$(bin)-$$node_os-$$node_arch; \
fi; \
(cd $$node_pkg && npm link || echo "cannot link for platform";);\
npm link $$node_pkg || echo "cannot link for platform";\
done
41 changes: 39 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0fd192f

Please sign in to comment.