-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: linux musl static bins / windows aarch64
- create linux executables linked statically to musl - drop gnu (glibc) target, executable will work on alpine & glibc based distros (debian etc) - create windows aarch64 target - refactor release script & workflow to match pact-reference - builds on pull request to master/main branch, in debug mode Related epics - musl all the things - pact-foundation/roadmap#30
- Loading branch information
Showing
6 changed files
with
300 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ build | |
target | ||
pacts | ||
*.out | ||
# Generated Release Artifacts | ||
release_artifacts | ||
|
||
# Misc | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,123 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
set -x | ||
|
||
RUST_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")/.." && pwd )" | ||
|
||
source "$RUST_DIR/scripts/gzip-and-sum.sh" | ||
ARTIFACTS_DIR=${ARTIFACTS_DIR:-"$RUST_DIR/release_artifacts"} | ||
mkdir -p "$ARTIFACTS_DIR" | ||
export CARGO_TARGET_DIR=${CARO_TARGET_DIR:-"$RUST_DIR/target"} | ||
|
||
if [ $# -lt 1 ] | ||
then | ||
echo "Usage : $0 <Linux|Windows|macOS>" | ||
exit | ||
fi | ||
|
||
echo Building Release for "$1" | ||
APP=pact-plugin-cli | ||
OS=$1 | ||
shift; | ||
# All flags passed to this script are passed to cargo. | ||
cargo_flags=( "$@" ) | ||
install_cross() { | ||
cargo install [email protected] | ||
} | ||
|
||
build_linux_x86_64() { | ||
install_cross | ||
cargo clean | ||
cross build --target=x86_64-unknown-linux-musl "${cargo_flags[@]}" | ||
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/x86_64-unknown-linux-musl/release/${APP}" \ | ||
"$ARTIFACTS_DIR/${APP}-linux-x86_64.gz" | ||
|
||
fi | ||
} | ||
|
||
build_linux_aarch64() { | ||
install_cross | ||
cargo clean | ||
cross build --target=aarch64-unknown-linux-musl "${cargo_flags[@]}" | ||
|
||
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/aarch64-unknown-linux-musl/release/${APP}" \ | ||
"$ARTIFACTS_DIR/${APP}-linux-aarch64.gz" | ||
fi | ||
} | ||
# Build the x86_64 darwin release | ||
build_macos_x86_64() { | ||
#cargo clean | ||
cargo build --target x86_64-apple-darwin "${cargo_flags[@]}" | ||
|
||
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/x86_64-apple-darwin/release/${APP}" \ | ||
"$ARTIFACTS_DIR/${APP}-osx-x86_64.gz" | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/x86_64-apple-darwin/release/${APP}" \ | ||
"$ARTIFACTS_DIR/${APP}-macos-x86_64.gz" | ||
fi | ||
} | ||
|
||
# Build the aarch64 darwin release | ||
build_macos_aarch64() { | ||
#cargo clean | ||
cargo build --target aarch64-apple-darwin "${cargo_flags[@]}" | ||
|
||
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/aarch64-apple-darwin/release/${APP}" \ | ||
"$ARTIFACTS_DIR/${APP}-osx-aarch64.gz" | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/aarch64-apple-darwin/release/${APP}" \ | ||
"$ARTIFACTS_DIR/${APP}-macos-aarch64.gz" | ||
fi | ||
} | ||
|
||
# Build the x86_64 windows release | ||
build_windows_x86_64() { | ||
#cargo clean | ||
cargo build --target x86_64-pc-windows-msvc "${cargo_flags[@]}" | ||
|
||
# If --release in cargo flags, then gzip and sum the release artifacts | ||
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/x86_64-pc-windows-msvc/release/${APP}.exe" \ | ||
"$ARTIFACTS_DIR/${APP}-windows-x86_64.exe.gz" | ||
fi | ||
} | ||
|
||
# Build the aarch64 windows release | ||
build_windows_aarch64() { | ||
#cargo clean | ||
cargo build --target aarch64-pc-windows-msvc "${cargo_flags[@]}" | ||
|
||
cargo clean | ||
mkdir -p target/artifacts/ | ||
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/aarch64-pc-windows-msvc/release/${APP}.exe" \ | ||
"$ARTIFACTS_DIR/${APP}-windows-aarch64.exe.gz" | ||
fi | ||
} | ||
|
||
case "$1" in | ||
case "$OS" in | ||
Linux) echo "Building for Linux" | ||
docker run --rm --user "$(id -u)":"$(id -g)" -v "$(pwd):/workspace" -w /workspace -t pactfoundation/rust-musl-build -c 'cargo build --release' | ||
gzip -c target/release/pact-plugin-cli > target/artifacts/pact-plugin-cli-linux-x86_64.gz | ||
openssl dgst -sha256 -r target/artifacts/pact-plugin-cli-linux-x86_64.gz > target/artifacts/pact-plugin-cli-linux-x86_64.gz.sha256 | ||
|
||
# Build aarch64 | ||
cargo install cross | ||
cross build --target aarch64-unknown-linux-gnu --release | ||
gzip -c target/aarch64-unknown-linux-gnu/release/pact-plugin-cli > target/artifacts/pact-plugin-cli-linux-aarch64.gz | ||
openssl dgst -sha256 -r target/artifacts/pact-plugin-cli-linux-aarch64.gz > target/artifacts/pact-plugin-cli-linux-aarch64.gz.sha256 | ||
build_linux_x86_64 | ||
build_linux_aarch64 | ||
;; | ||
Windows) echo "Building for Windows" | ||
cargo build --release | ||
gzip -c target/release/pact-plugin-cli.exe > target/artifacts/pact-plugin-cli-windows-x86_64.exe.gz | ||
openssl dgst -sha256 -r target/artifacts/pact-plugin-cli-windows-x86_64.exe.gz > target/artifacts/pact-plugin-cli-windows-x86_64.exe.gz.sha256 | ||
Windows) echo "Building for windows" | ||
build_windows_x86_64 | ||
build_windows_aarch64 | ||
;; | ||
macOS) echo "Building for OSX" | ||
cargo build --release | ||
gzip -c target/release/pact-plugin-cli > target/artifacts/pact-plugin-cli-osx-x86_64.gz | ||
openssl dgst -sha256 -r target/artifacts/pact-plugin-cli-osx-x86_64.gz > target/artifacts/pact-plugin-cli-osx-x86_64.gz.sha256 | ||
|
||
# M1 | ||
export SDKROOT=$(xcrun -sdk macosx11.1 --show-sdk-path) | ||
export MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.1 --show-sdk-platform-version) | ||
cargo build --target aarch64-apple-darwin --release | ||
|
||
gzip -c target/aarch64-apple-darwin/release/pact-plugin-cli > target/artifacts/pact-plugin-cli-osx-aarch64.gz | ||
openssl dgst -sha256 -r target/artifacts/pact-plugin-cli-osx-aarch64.gz > target/artifacts/pact-plugin-cli-osx-aarch64.gz.sha256 | ||
macOS) echo "Building for macos" | ||
build_macos_x86_64 | ||
build_macos_aarch64 | ||
;; | ||
*) echo "$1 is not a recognised OS" | ||
*) echo "$OS is not a recognised OS" | ||
exit 1 | ||
;; | ||
esac | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.