Skip to content

Commit d3b41be

Browse files
authored
Merge branch 'master' into add-sapi-zts-test
2 parents 9cbfed4 + b9384df commit d3b41be

File tree

20 files changed

+260
-63
lines changed

20 files changed

+260
-63
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ linker = "rust-lld"
66

77
[target.i686-pc-windows-msvc]
88
linker = "rust-lld"
9+
10+
[target.'cfg(target_env = "musl")']
11+
rustflags = ["-C", "target-feature=-crt-static"]

.github/action/musl/Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
ARG PHP_VERSION=8.4
2+
ARG TS=-zts
3+
4+
FROM php:${PHP_VERSION}${TS}-alpine
5+
6+
RUN apk add --no-cache \
7+
llvm17 \
8+
llvm17-dev \
9+
llvm17-libs \
10+
llvm17-static \
11+
clang17 \
12+
clang17-dev \
13+
clang17-static \
14+
curl
15+
16+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
17+
ENV PATH="/root/.cargo/bin:${PATH}"
18+
19+
RUN rustup target add x86_64-unknown-linux-musl
20+
RUN cargo install cargo-expand --locked
21+
22+
ENV PHP=/usr/local/bin/php
23+
ENV PHP_CONFIG=/usr/local/bin/php-config
24+
25+
ENV LLVM_CONFIG_PATH=/usr/lib/llvm17/bin/llvm-config
26+
ENV LIBCLANG_PATH=/usr/lib/llvm17/lib
27+
ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/lib
28+
ENV RUSTFLAGS="-C target-feature=-crt-static -C link-arg=-Wl,-rpath,/usr/local/lib -L /usr/local/lib"
29+
30+
WORKDIR /workspace
31+
32+
COPY . .
33+
34+
ENTRYPOINT ["cargo"]
35+
CMD ["build", "--release", "--no-default-features", "--features", "closure,anyhow,runtime,enum", "--workspace", "--target", "x86_64-unknown-linux-musl"]

.github/workflows/build.yml

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
name: Build and Lint
22
on:
3-
schedule:
4-
# runs every monday at midnight
5-
- cron: "0 0 * * 1"
6-
push:
7-
branches:
8-
- master
9-
pull_request:
3+
workflow_call:
4+
inputs:
5+
rust_cache_prefix:
6+
description: "Cache busting prefix for Rust dependencies"
7+
default: "v0-rust"
8+
type: string
9+
workflow_dispatch:
1010
env:
1111
# increment this manually to force cache eviction
12-
RUST_CACHE_PREFIX: "v0-rust"
12+
RUST_CACHE_PREFIX: ${{ inputs.rust_cache_prefix }}
1313

1414
concurrency:
1515
group: ${{ github.workflow }}-${{ github.ref }}
@@ -168,7 +168,6 @@ jobs:
168168
# Macos fails on unstable rust. We skip the inline examples test for now.
169169
if: "!(contains(matrix.os, 'macos') && matrix.rust == 'nightly')"
170170
run: cargo test --release --workspace --features closure,anyhow,runtime --no-fail-fast
171-
172171
test-embed:
173172
name: Test with embed (${{ matrix.phpts }})
174173
runs-on: ubuntu-latest
@@ -231,3 +230,45 @@ jobs:
231230
ulimit -c unlimited
232231
cargo test --workspace --release --features closure,embed,anyhow --no-fail-fast || \
233232
(for core in core.*; do [ -f "$core" ] && gdb -batch -ex "thread apply all bt" target/release/deps/sapi_tests-* "$core"; done; exit 1)
233+
234+
build-musl:
235+
name: musl / ${{ matrix.php }} / ${{ matrix.phpts[1] }}
236+
runs-on: ubuntu-latest
237+
strategy:
238+
matrix:
239+
php: ["8.1", "8.2", "8.3", "8.4"]
240+
phpts: [["-zts", "TS"], ["", "NTS"]]
241+
env:
242+
CARGO_TERM_COLOR: always
243+
steps:
244+
- name: Checkout code
245+
uses: actions/checkout@v5
246+
- name: Setup DockerX
247+
uses: docker/setup-buildx-action@v3
248+
- name: Build
249+
uses: docker/build-push-action@v6
250+
with:
251+
context: .github/action/musl
252+
file: .github/action/musl/Dockerfile
253+
tags: |
254+
extphprs/ext-php-rs:musl-${{ matrix.php }}-${{ matrix.phpts[1] }}
255+
push: false
256+
load: true
257+
platforms: linux/amd64
258+
build-args: |
259+
PHP_VERSION=${{ matrix.php }}
260+
TS=${{ matrix.phpts[0] }}
261+
- name: Build
262+
run: |
263+
docker run \
264+
-v $(pwd):/workspace \
265+
-w /workspace \
266+
extphprs/ext-php-rs:musl-${{ matrix.php }}-${{ matrix.phpts[1] }} \
267+
build --release --features closure,anyhow,runtime --workspace
268+
- name: Run tests
269+
run: |
270+
docker run \
271+
-v $(pwd):/workspace \
272+
-w /workspace \
273+
extphprs/ext-php-rs:musl-${{ matrix.php }}-${{ matrix.phpts[1] }} \
274+
test --workspace --release --features closure,anyhow,runtime --no-fail-fast

.github/workflows/coverage.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ on:
33
push:
44
branches-ignore:
55
- "release-plz-*"
6-
pull_request:
7-
branches-ignore:
8-
- "release-plz-*"
6+
workflow_call:
7+
workflow_dispatch:
98
env:
109
# increment this manually to force cache eviction
1110
RUST_CACHE_PREFIX: "v0-rust"

.github/workflows/docs.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
name: Deploy documentation
22
on:
3+
workflow_call:
34
workflow_dispatch:
4-
# runs every monday at midnight
5-
schedule:
6-
- cron: "0 0 * * 1"
7-
push:
8-
branches:
9-
- master
105

116
jobs:
127
docs:

.github/workflows/master.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Master Branch Workflow
2+
on:
3+
push:
4+
branches:
5+
- master
6+
workflow_dispatch:
7+
8+
jobs:
9+
build_and_lint:
10+
name: Build and Lint
11+
uses: ./.github/workflows/build.yml
12+
release:
13+
name: Create Release (MR)
14+
needs: [build_and_lint]
15+
permissions:
16+
id-token: write
17+
contents: write
18+
pull-requests: write
19+
uses: ./.github/workflows/release-plz.yml
20+
secrets:
21+
RELEASE_PLZ_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }}
22+
docs:
23+
name: Build and Deploy Documentation
24+
needs: [release]
25+
if: needs.release.outputs.release_created == 'true'
26+
permissions:
27+
contents: write
28+
uses: ./.github/workflows/docs.yml
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Merge Request Workflow
2+
on:
3+
pull_request:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build_and_lint:
8+
name: Build and Lint
9+
uses: ./.github/workflows/build.yml
10+
coverage:
11+
name: Code Coverage
12+
if: ${{ ! startsWith(github.head_ref, 'release-plz-') }}
13+
uses: ./.github/workflows/coverage.yml

.github/workflows/release-plz.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@ permissions:
55
contents: write
66

77
on:
8-
workflow_run:
9-
workflows: ["Build and Lint"]
10-
branches: ["master"]
11-
types:
12-
- completed
8+
workflow_call:
9+
secrets:
10+
RELEASE_PLZ_TOKEN:
11+
required: true
12+
outputs:
13+
release_created:
14+
description: "Indicates if a release was created"
15+
value: ${{ jobs.release-plz-release.outputs.release_created }}
16+
workflow_dispatch:
1317

1418
jobs:
1519
release-plz-release:
1620
name: Release-plz release
1721
runs-on: ubuntu-latest
22+
if: github.ref == 'refs/heads/master'
1823
permissions:
1924
id-token: write
20-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
25+
outputs:
26+
release_created: ${{ steps.release-plz.outputs.release_created }}
2127
env:
22-
clang: '17'
23-
php_version: '8.2'
28+
clang: "17"
29+
php_version: "8.4"
2430
steps:
2531
- name: Checkout repository
2632
uses: actions/checkout@v5
@@ -56,19 +62,19 @@ jobs:
5662
uses: rust-lang/crates-io-auth-action@v1
5763
id: auth
5864
- name: Run release-plz
65+
id: release-plz
5966
uses: release-plz/[email protected]
6067
with:
6168
command: release
6269
env:
6370
GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }}
64-
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
6571

6672
release-plz-pr:
6773
name: Release-plz PR
6874
runs-on: ubuntu-latest
75+
if: github.ref == 'refs/heads/master'
6976
permissions:
7077
id-token: write
71-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
7278
concurrency:
7379
group: release-plz-${{ github.ref }}
7480
cancel-in-progress: false
@@ -88,4 +94,3 @@ jobs:
8894
command: release-pr
8995
env:
9096
GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }}
91-
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

Dockerfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@ apt update -y
88
apt install -y \
99
libclang-dev \
1010
bison \
11-
re2c
11+
re2c \
12+
curl \
13+
jq
14+
15+
# Download and extract PHP
16+
FULL_VERSION=$(curl -fsSL "https://www.php.net/releases/index.php?json&version=${PHP_VERSION}" | jq -r '.version')
17+
echo "Downloading PHP ${FULL_VERSION}..."
18+
curl -fsSL "https://www.php.net/distributions/php-${FULL_VERSION}.tar.gz" -o php.tar.gz
19+
tar -xzf php.tar.gz
20+
rm php.tar.gz
21+
mv "php-${FULL_VERSION}" php-src
1222

1323
# Build PHP
14-
git clone --depth 1 -b PHP-${PHP_VERSION} https://github.com/php/php-src.git
1524
cd php-src
16-
# by default you will be on the master branch, which is the current
17-
# development version. You can check out a stable branch instead:
18-
./buildconf
1925
./configure \
2026
--enable-debug \
2127
--disable-all --disable-cgi

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ 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)
130+
131+
Building for Alpine Linux (musl libc) is supported on stable Rust with dynamic linking
132+
thanks to `runtime` feature flag from `bindgen`.
133+
134+
**Note**: Building for musl requires dynamic CRT linking (`-crt-static` flag) to produce
135+
the `cdylib` output required for PHP extensions.
136+
If you want to build statically, you'll need full LLVM + Clang toolchain.
137+
Please read: <https://github.com/KyleMayes/clang-sys#static>
138+
129139
### Windows Requirements
130140

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

0 commit comments

Comments
 (0)