pact-foundation / pact-reference

Reference implementations for the pact specifications
https://pact.io
MIT License
91 stars 46 forks source link

docs: note musl based static builds, that work across linux distros + alpine ffi static & shared libs #416

Open YOU54F opened 1 month ago

YOU54F commented 1 month ago

it would be good to document this on the readme, so users are aware that

library alpine support version
pact_ffi - x86_64 .a from 0.2.4
- aarch64 .a from 0.4.15
- .so from 0.4.17
pact_mock_server_cli - 1.0.5
pact_verifier_cli - 1.1.1
pact-stub-server - 0.6.0
pact-plugin-cli - 0.1.2
pact-protobuf-plugin - 0.3.15
pact-csv-plugin - 0.0.6
mefellows commented 1 month ago

Nice! We should update here also: https://docs.pact.io/docker

YOU54F commented 1 month ago

So we have an issue with the pact_ffi shared library, for aarch64-musl .so in 0.4.20

Error

LoadError:
  Could not open library '/app/lib/pact/../../ffi/linux-arm64-musl/libpact_ffi.so': Error relocating /app/lib/pact/../../ffi/linux-arm64-musl/libpact_ffi.so: __builtin_copysignq: symbol not found.
  Searched in <system library path>, /usr/lib, /usr/local/lib, /opt/local/lib
# /usr/local/bundle/gems/ffi-1.16.3/lib/ffi/dynamic_library.rb:65:in `load_library'

Seems to be exclusive to aarch64, and the dynamic library only. amd64 tests are passing in pact-php as well using the shared library, and the static .a is being used and tested successfully in pact-js-core in this PR

First reported by @tienvx over in pact-php alpine PR - Thanks Tien!

YOU54F commented 1 month ago

So I've just built the aarch64 musl libs locally on my macbook,

https://github.com/pact-foundation/pact-reference/blob/e44458a8616856d3726470dd8f3884340999bf1e/rust/pact_ffi/release-linux.sh#L82-L111

Copied these over to pact-php

cp ../release_artifacts/libpact_ffi-linux-aarch64-musl.so ~/dev/pact-foundation/pact-php/bin/pact-ffi-lib/pact.so

Green php tests.

Screenshot 2024-05-15 at 18 44 43

note have tried regenerating the .so from the released 0.4.20 .a but get the same missing symbol issue, so not sure what has caused it

YOU54F commented 3 weeks ago

I think this was due to stripping of the symbols from the static archive, prior to generating the shared object file. It's possible to force the generation of the *.so at compile time with some rust flags, so that has been performed along with a smoke test to ensure its loading correctly in #432