|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Script to verify that the musl build produces a statically linked library |
| 4 | +# without libgcc_s.so.1 dependency - preventing regressions |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +# Build the musl target if not already built |
| 9 | +if [ ! -f "target/x86_64-unknown-linux-musl/release/libscal3.so" ]; then |
| 10 | + # Check if the musl target is added |
| 11 | + if ! rustup target list --installed | grep -q "x86_64-unknown-linux-musl"; then |
| 12 | + rustup target add x86_64-unknown-linux-musl |
| 13 | + fi |
| 14 | + cargo build --release --target x86_64-unknown-linux-musl |
| 15 | +fi |
| 16 | + |
| 17 | +# Path to the built library |
| 18 | +LIB_PATH="target/x86_64-unknown-linux-musl/release/libscal3.so" |
| 19 | + |
| 20 | +if [ ! -f "$LIB_PATH" ]; then |
| 21 | + echo "Library not found at $LIB_PATH" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +# Check if statically linked |
| 26 | +LDD_OUTPUT=$(ldd "$LIB_PATH" 2>&1 || true) |
| 27 | +if ! echo "$LDD_OUTPUT" | grep -q "statically linked"; then |
| 28 | + echo "Library is not statically linked" |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +# Check for libgcc dependency |
| 33 | +if echo "$LDD_OUTPUT" | grep -q "libgcc_s.so"; then |
| 34 | + echo "Found unwanted libgcc_s.so dependency" |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | + |
| 38 | +# Check undefined symbols - should only be malloc and free |
| 39 | +UNDEFINED_SYMBOLS=$(nm -D "$LIB_PATH" | grep "U " || true) |
| 40 | +UNWANTED_SYMBOLS=$(echo "$UNDEFINED_SYMBOLS" | grep -v -E "(malloc|free)" || true) |
| 41 | +if [ -n "$UNWANTED_SYMBOLS" ]; then |
| 42 | + echo "Found unexpected undefined symbols:" |
| 43 | + echo "$UNWANTED_SYMBOLS" |
| 44 | + exit 1 |
| 45 | +fi |
| 46 | + |
| 47 | +echo "✅ Static linking verification passed" |
0 commit comments