|
| 1 | +name: Test Static Builds |
| 2 | + |
| 3 | +# Test workflow for static musl builds |
| 4 | +# Run manually to test different approaches before updating release.yml |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + arch: |
| 10 | + description: 'Architecture to test' |
| 11 | + required: true |
| 12 | + type: choice |
| 13 | + options: |
| 14 | + - x86_64 |
| 15 | + - aarch64 |
| 16 | + - both |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + |
| 21 | +env: |
| 22 | + RUST_BACKTRACE: 1 |
| 23 | + |
| 24 | +jobs: |
| 25 | + # x86_64 static build - uses Alpine container (this works) |
| 26 | + build-static-x86_64: |
| 27 | + name: build-static-x86_64 |
| 28 | + if: ${{ github.event.inputs.arch == 'x86_64' || github.event.inputs.arch == 'both' }} |
| 29 | + runs-on: ubuntu-latest |
| 30 | + container: |
| 31 | + image: rust:alpine |
| 32 | + steps: |
| 33 | + - name: Checkout repository |
| 34 | + uses: actions/checkout@v6 |
| 35 | + |
| 36 | + - name: Install dependencies |
| 37 | + run: | |
| 38 | + apk add --no-cache \ |
| 39 | + musl-dev libpcap-dev pkgconfig build-base perl \ |
| 40 | + elfutils-dev zlib-dev zlib-static zstd-dev zstd-static \ |
| 41 | + clang llvm linux-headers git |
| 42 | + rustup component add rustfmt |
| 43 | +
|
| 44 | + - name: Build static binary |
| 45 | + env: |
| 46 | + RUSTFLAGS: "-C strip=symbols -C link-arg=-l:libzstd.a" |
| 47 | + run: cargo build --release |
| 48 | + |
| 49 | + - name: Verify static linking |
| 50 | + run: | |
| 51 | + file target/release/rustnet |
| 52 | + file target/release/rustnet | grep -q "static.* linked" || \ |
| 53 | + (echo "ERROR: Binary is not statically linked" && exit 1) |
| 54 | +
|
| 55 | + - name: Create release archive |
| 56 | + run: | |
| 57 | + staging="rustnet-test-x86_64-unknown-linux-musl" |
| 58 | + mkdir -p "$staging/assets" |
| 59 | + cp target/release/rustnet "$staging/" |
| 60 | + cp assets/services "$staging/assets/" 2>/dev/null || true |
| 61 | + cp README.md "$staging/" |
| 62 | + cp LICENSE "$staging/" 2>/dev/null || true |
| 63 | + tar czf "$staging.tar.gz" "$staging" |
| 64 | +
|
| 65 | + - name: Upload artifact |
| 66 | + uses: actions/upload-artifact@v6 |
| 67 | + with: |
| 68 | + name: static-x86_64-unknown-linux-musl |
| 69 | + path: rustnet-test-x86_64-unknown-linux-musl.tar.gz |
| 70 | + if-no-files-found: error |
| 71 | + |
| 72 | + # aarch64 static build - test with manual git clone and artifact upload |
| 73 | + build-static-aarch64: |
| 74 | + name: build-static-aarch64 |
| 75 | + if: ${{ github.event.inputs.arch == 'aarch64' || github.event.inputs.arch == 'both' }} |
| 76 | + runs-on: ubuntu-24.04-arm |
| 77 | + container: |
| 78 | + image: rust:alpine |
| 79 | + steps: |
| 80 | + # JS actions don't work in Alpine containers on ARM - use manual git clone |
| 81 | + - name: Checkout repository |
| 82 | + run: | |
| 83 | + apk add --no-cache git |
| 84 | + git clone --depth 1 https://github.com/${{ github.repository }}.git . |
| 85 | +
|
| 86 | + - name: Install dependencies |
| 87 | + run: | |
| 88 | + apk add --no-cache \ |
| 89 | + musl-dev libpcap-dev pkgconfig build-base perl \ |
| 90 | + elfutils-dev zlib-dev zlib-static zstd-dev zstd-static \ |
| 91 | + clang llvm linux-headers |
| 92 | + rustup component add rustfmt |
| 93 | +
|
| 94 | + - name: Build static binary |
| 95 | + env: |
| 96 | + RUSTFLAGS: "-C strip=symbols -C link-arg=-l:libzstd.a" |
| 97 | + run: cargo build --release |
| 98 | + |
| 99 | + - name: Verify static linking |
| 100 | + run: | |
| 101 | + file target/release/rustnet |
| 102 | + file target/release/rustnet | grep -q "static.* linked" || \ |
| 103 | + (echo "ERROR: Binary may not be fully statically linked") |
| 104 | +
|
| 105 | + - name: Show binary info |
| 106 | + run: | |
| 107 | + ls -la target/release/rustnet |
| 108 | + file target/release/rustnet |
| 109 | +
|
| 110 | + - name: Create release archive |
| 111 | + run: | |
| 112 | + staging="rustnet-test-aarch64-unknown-linux-musl" |
| 113 | + mkdir -p "$staging/assets" |
| 114 | + cp target/release/rustnet "$staging/" |
| 115 | + cp assets/services "$staging/assets/" 2>/dev/null || true |
| 116 | + cp README.md "$staging/" |
| 117 | + cp LICENSE "$staging/" 2>/dev/null || true |
| 118 | + tar czf "$staging.tar.gz" "$staging" |
| 119 | + ls -la "$staging.tar.gz" |
| 120 | +
|
| 121 | + # Try uploading artifact - this may fail on ARM Alpine |
| 122 | + # If it fails, the archive is still created and we know the build works |
| 123 | + - name: Upload artifact (may fail on ARM) |
| 124 | + continue-on-error: true |
| 125 | + uses: actions/upload-artifact@v6 |
| 126 | + with: |
| 127 | + name: static-aarch64-unknown-linux-musl |
| 128 | + path: rustnet-test-aarch64-unknown-linux-musl.tar.gz |
| 129 | + if-no-files-found: error |
0 commit comments