-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reapply "chore(ci): refactor release pipeline"
This reverts commit 7c09f17.
- Loading branch information
1 parent
2d87431
commit 823b009
Showing
10 changed files
with
416 additions
and
261 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 |
---|---|---|
@@ -1,75 +1,119 @@ | ||
#!/bin/bash -x | ||
#!/bin/bash | ||
|
||
set -e | ||
set -x | ||
|
||
echo -- Setup directories -- | ||
cargo clean | ||
mkdir -p ../release_artifacts | ||
RUST_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | ||
APP_NAME=libpact_ffi | ||
|
||
echo -- Build the Docker build image -- | ||
docker build -f Dockerfile.linux-build -t pact-ffi-build . | ||
source "$RUST_DIR/scripts/gzip-and-sum.sh" | ||
ARTIFACTS_DIR=${ARTIFACTS_DIR:-"$RUST_DIR/release_artifacts"} | ||
mkdir -p "$ARTIFACTS_DIR" | ||
install_cross() { | ||
cargo install [email protected] --force | ||
} | ||
install_cross_latest() { | ||
cargo install cross --git https://github.com/cross-rs/cross --force | ||
} | ||
clean_cargo_release_build() { | ||
rm -rf $CARGO_TARGET_DIR/release/build | ||
} | ||
|
||
echo -- Build the release artifacts -- | ||
docker run -t --rm --user "$(id -u)":"$(id -g)" -v $(pwd)/..:/workspace -w /workspace/pact_ffi pact-ffi-build -c 'cargo build --release' | ||
gzip -c ../target/release/libpact_ffi.so > ../release_artifacts/libpact_ffi-linux-x86_64.so.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-x86_64.so.gz > ../release_artifacts/libpact_ffi-linux-x86_64.so.gz.sha256 | ||
gzip -c ../target/release/libpact_ffi.a > ../release_artifacts/libpact_ffi-linux-x86_64.a.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-x86_64.a.gz > ../release_artifacts/libpact_ffi-linux-x86_64.a.gz.sha256 | ||
export CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-"$RUST_DIR/target"} | ||
|
||
echo -- Generate the header files -- | ||
rustup toolchain install nightly | ||
rustup component add rustfmt --toolchain nightly | ||
rustup run nightly cbindgen \ | ||
--config cbindgen.toml \ | ||
--crate pact_ffi \ | ||
--output include/pact.h | ||
rustup run nightly cbindgen \ | ||
--config cbindgen-c++.toml \ | ||
--crate pact_ffi \ | ||
--output include/pact-cpp.h | ||
cp include/*.h ../release_artifacts | ||
# All flags passed to this script are passed to cargo. | ||
case $1 in | ||
x86_64-unknown-linux-musl) | ||
TARGET=$1 | ||
shift | ||
;; | ||
aarch64-unknown-linux-musl) | ||
TARGET=$1 | ||
shift | ||
;; | ||
x86_64-unknown-linux-gnu) | ||
TARGET=$1 | ||
shift | ||
;; | ||
aarch64-unknown-linux-gnu) | ||
TARGET=$1 | ||
shift | ||
;; | ||
*) ;; | ||
esac | ||
cargo_flags=("$@") | ||
|
||
echo -- Build the musl release artifacts -- | ||
cargo install [email protected] | ||
cross build --release --target=x86_64-unknown-linux-musl | ||
gzip -c ../target/x86_64-unknown-linux-musl/release/libpact_ffi.a > ../release_artifacts/libpact_ffi-linux-x86_64-musl.a.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-x86_64-musl.a.gz > ../release_artifacts/libpact_ffi-linux-x86_64-musl.a.gz.sha256 | ||
build_target() { | ||
TARGET=$1 | ||
|
||
mkdir tmp | ||
cp ../target/x86_64-unknown-linux-musl/release/libpact_ffi.a tmp/ | ||
docker run --platform=linux/amd64 --rm -v $PWD/tmp:/scratch alpine /bin/sh -c 'apk add --no-cache musl-dev gcc && \ | ||
cd /scratch && \ | ||
ar -x libpact_ffi.a && \ | ||
gcc -shared *.o -o libpact_ffi.so && \ | ||
rm -f *.o' | ||
case $TARGET in | ||
x86_64-unknown-linux-musl) | ||
FILE_SUFFIX=linux-x86_64-musl | ||
RUSTFLAGS="-C target-feature=-crt-static" | ||
;; | ||
aarch64-unknown-linux-musl) | ||
FILE_SUFFIX=linux-aarch64-musl | ||
RUSTFLAGS="-C target-feature=-crt-static" | ||
;; | ||
x86_64-unknown-linux-gnu) | ||
FILE_SUFFIX=linux-x86_64 | ||
;; | ||
aarch64-unknown-linux-gnu) | ||
FILE_SUFFIX=linux-aarch64 | ||
;; | ||
*) | ||
echo unknown target $TARGET | ||
exit 1 | ||
;; | ||
esac | ||
RUSTFLAGS=${RUSTFLAGS:-""} cross build --target $TARGET "${cargo_flags[@]}" | ||
|
||
gzip -c tmp/libpact_ffi.so > ../release_artifacts/libpact_ffi-linux-x86_64-musl.so.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-x86_64-musl.so.gz > ../release_artifacts/libpact_ffi-linux-x86_64-musl.so.gz.sha256 | ||
rm -rf tmp | ||
if [[ "${cargo_flags[*]}" =~ "--release" ]]; then | ||
file "$CARGO_TARGET_DIR/$TARGET/release/$APP_NAME.a" | ||
file "$CARGO_TARGET_DIR/$TARGET/release/$APP_NAME.so" | ||
du -sh "$CARGO_TARGET_DIR/$TARGET/release/$APP_NAME.a" | ||
du -sh "$CARGO_TARGET_DIR/$TARGET/release/$APP_NAME.so" | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/$TARGET/release/$APP_NAME.a" \ | ||
"$ARTIFACTS_DIR/$APP_NAME-$FILE_SUFFIX.a.gz" | ||
gzip_and_sum \ | ||
"$CARGO_TARGET_DIR/$TARGET/release/$APP_NAME.so" \ | ||
"$ARTIFACTS_DIR/$APP_NAME-$FILE_SUFFIX.so.gz" | ||
fi | ||
} | ||
|
||
build_header() { | ||
rustup toolchain install nightly | ||
rustup run nightly cbindgen \ | ||
--config cbindgen.toml \ | ||
--crate pact_ffi \ | ||
--output "$ARTIFACTS_DIR/pact.h" | ||
rustup run nightly cbindgen \ | ||
--config cbindgen-c++.toml \ | ||
--crate pact_ffi \ | ||
--output "$ARTIFACTS_DIR/pact-cpp.h" | ||
} | ||
|
||
echo -- Build the musl aarch64 release artifacts -- | ||
cargo clean | ||
cross build --release --target=aarch64-unknown-linux-musl | ||
gzip -c ../target/aarch64-unknown-linux-musl/release/libpact_ffi.a > ../release_artifacts/libpact_ffi-linux-aarch64-musl.a.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-aarch64-musl.a.gz > ../release_artifacts/libpact_ffi-linux-aarch64-musl.a.gz.sha256 | ||
install_cross | ||
if [ ! -z "$TARGET" ]; then | ||
echo building for target $TARGET | ||
build_target $TARGET | ||
|
||
mkdir tmp | ||
cp ../target/aarch64-unknown-linux-musl/release/libpact_ffi.a tmp/ | ||
docker run --platform=linux/arm64 --rm -v $PWD/tmp:/scratch alpine /bin/sh -c 'apk add --no-cache musl-dev gcc && \ | ||
cd /scratch && \ | ||
ar -x libpact_ffi.a && \ | ||
gcc -shared *.o -o libpact_ffi.so && \ | ||
rm -f *.o' | ||
|
||
gzip -c tmp/libpact_ffi.so > ../release_artifacts/libpact_ffi-linux-aarch64-musl.so.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-aarch64-musl.so.gz > ../release_artifacts/libpact_ffi-linux-aarch64-musl.so.gz.sha256 | ||
rm -rf tmp | ||
|
||
echo -- Build the aarch64 release artifacts -- | ||
cargo clean | ||
cross build --target aarch64-unknown-linux-gnu --release | ||
gzip -c ../target/aarch64-unknown-linux-gnu/release/libpact_ffi.so > ../release_artifacts/libpact_ffi-linux-aarch64.so.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-aarch64.so.gz > ../release_artifacts/libpact_ffi-linux-aarch64.so.gz.sha256 | ||
gzip -c ../target/aarch64-unknown-linux-gnu/release/libpact_ffi.a > ../release_artifacts/libpact_ffi-linux-aarch64.a.gz | ||
openssl dgst -sha256 -r ../release_artifacts/libpact_ffi-linux-aarch64.a.gz > ../release_artifacts/libpact_ffi-linux-aarch64.a.gz.sha256 | ||
# If we are building indiv targets, ensure we build the headers | ||
# for at least 1 nominated target | ||
if [ "$TARGET" == "x86_64-unknown-linux-gnu" ]; then | ||
build_header | ||
fi | ||
else | ||
echo building for all targets | ||
# clean release build to avoid conflicting symbols when building all targets | ||
clean_cargo_release_build | ||
build_target x86_64-unknown-linux-gnu | ||
clean_cargo_release_build | ||
build_target aarch64-unknown-linux-gnu | ||
clean_cargo_release_build | ||
build_target x86_64-unknown-linux-musl | ||
clean_cargo_release_build | ||
build_target aarch64-unknown-linux-musl | ||
build_header | ||
fi |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.