Skip to content

Commit 137ebea

Browse files
committed
ci: add musl build step
1 parent 3f6595d commit 137ebea

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

.github/workflows/build.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ jobs:
9191
rust: [stable, nightly]
9292
clang: ["15", "17"]
9393
phpts: [ts, nts]
94+
target: [gnu, musl]
9495
exclude:
9596
# ext-php-rs requires nightly Rust when on Windows.
9697
- os: windows-latest
@@ -101,11 +102,23 @@ jobs:
101102
clang: "15"
102103
- os: windows-latest
103104
clang: "15"
105+
# musl only supported on Linux with stable Rust
106+
- os: windows-latest
107+
target: musl
108+
- os: macos-latest
109+
target: musl
110+
- target: musl
111+
rust: nightly
104112
env:
105113
CARGO_TERM_COLOR: always
106114
steps:
107115
- name: Checkout code
108116
uses: actions/checkout@v5
117+
- name: Install musl toolchain
118+
if: matrix.target == 'musl'
119+
run: |
120+
sudo apt-get update
121+
sudo apt-get install -y musl-tools musl-dev
109122
- name: Setup PHP
110123
uses: shivammathur/setup-php@v2
111124
with:
@@ -118,6 +131,9 @@ jobs:
118131
with:
119132
toolchain: ${{ matrix.rust }}
120133
components: rustfmt, clippy
134+
- name: Add musl target
135+
if: matrix.target == 'musl'
136+
run: rustup target add x86_64-unknown-linux-musl
121137
- run: rustup show
122138
- name: Cache cargo dependencies
123139
uses: Swatinem/rust-cache@v2
@@ -162,13 +178,17 @@ jobs:
162178
- name: Build
163179
env:
164180
EXT_PHP_RS_TEST: ""
165-
run: cargo build --release --features closure,anyhow,runtime --workspace
181+
RUSTFLAGS: ${{ matrix.target == 'musl' && '-C target-feature=-crt-static' || '' }}
182+
CC: ${{ matrix.target == 'musl' && 'musl-gcc' || 'gcc' }}
183+
run: cargo build --release --features closure,anyhow,runtime --workspace ${{ matrix.target == 'musl' && '--target x86_64-unknown-linux-musl' || '' }}
166184
# Test
167185
- name: Test inline examples
168186
# Macos fails on unstable rust. We skip the inline examples test for now.
169187
if: "!(contains(matrix.os, 'macos') && matrix.rust == 'nightly')"
170-
run: cargo test --release --workspace --features closure,anyhow,runtime --no-fail-fast
171-
188+
env:
189+
RUSTFLAGS: ${{ matrix.target == 'musl' && '-C target-feature=-crt-static' || '' }}
190+
CC: ${{ matrix.target == 'musl' && 'musl-gcc' || 'gcc' }}
191+
run: cargo test --release --workspace --features closure,anyhow,runtime --no-fail-fast ${{ matrix.target == 'musl' && '--target x86_64-unknown-linux-musl' || '' }}
172192
test-embed:
173193
name: Test with embed
174194
runs-on: ubuntu-latest

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ best resource at the moment. This can be viewed at [docs.rs].
126126
1.57 at the time of writing.
127127
- Clang 5.0 or later.
128128

129+
### Alpine Linux (musl) Requirements
130+
131+
Building for Alpine Linux (musl libc) is supported on stable Rust with the following
132+
requirements:
133+
134+
- Install musl toolchain: `sudo apt-get install musl-tools musl-dev`
135+
- Add musl target: `rustup target add x86_64-unknown-linux-musl`
136+
- Build with dynamic linking flag:
137+
```bash
138+
RUSTFLAGS="-C target-feature=-crt-static" \
139+
cargo build --target x86_64-unknown-linux-musl
140+
```
141+
142+
**Note**: Building for musl requires dynamic CRT linking (`-crt-static` flag) to produce
143+
the `cdylib` output required for PHP extensions.
144+
129145
### Windows Requirements
130146

131147
- Extensions can only be compiled for PHP installations sourced from

0 commit comments

Comments
 (0)