Skip to content

Commit

Permalink
feat: convert musl static .a to .so
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Feb 13, 2024
1 parent 8d19795 commit 747fa70
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions rust/pact_ffi/release-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,42 @@ rustup run nightly cbindgen \
cp include/*.h ../release_artifacts

echo -- Build the musl release artifacts --
sudo apt install musl-tools
rustup target add x86_64-unknown-linux-musl
cargo build --release --target=x86_64-unknown-linux-musl
cargo install cross@0.2.5
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

cargo install cross@0.2.5
mkdir tmp
cp ../target/x86_64-unknown-linux-musl/release/libpact_ffi.a tmp/
docker run --platform=linux/amd64 --rm -it -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-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


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

mkdir tmp
cp ../target/aarch64-unknown-linux-musl/release/libpact_ffi.a tmp/
docker run --platform=linux/arm64 --rm -it -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
Expand Down

0 comments on commit 747fa70

Please sign in to comment.