Skip to content

Commit 33f045e

Browse files
authored
feature: add workflow to precompile arrow extension binaries during release (#2278)
1 parent 77e46ce commit 33f045e

File tree

4 files changed

+211
-1
lines changed

4 files changed

+211
-1
lines changed

src/extension/arrow-ext/.cargo/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ rustflags = ["-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup"]
33

44
[target.x86_64-apple-darwin]
55
rustflags = ["-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup"]
6+
7+
[target.x86_64-unknown-linux-gnu]
8+
rustflags = ["-C", "link-arg=-Wl,--allow-shlib-undefined"]
9+
10+
[target.aarch64-unknown-linux-gnu]
11+
rustflags = ["-C", "link-arg=-Wl,--allow-shlib-undefined"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Readonly
2+
3+
on:
4+
pull_request_target:
5+
types: [opened]
6+
7+
jobs:
8+
run:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: superbrothers/close-pull-request@v3
12+
with:
13+
comment: |
14+
Hi, thank you for your contribution.
15+
Unfortunately, this repository is read-only. It's a split from our main monorepo repository.
16+
In order to proceed with this PR please open it against https://github.com/flow-php/flow repository.
17+
Thank you.
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
name: Release Precompiled Binaries
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
permissions:
9+
contents: write
10+
11+
env:
12+
EXTENSION_NAME: arrow
13+
RUST_BACKTRACE: 1
14+
15+
jobs:
16+
create-release:
17+
name: Create Release
18+
runs-on: ubuntu-latest
19+
outputs:
20+
tag: ${{ steps.tag.outputs.tag }}
21+
steps:
22+
- name: Get tag
23+
id: tag
24+
run: echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
25+
26+
- name: Create draft release
27+
env:
28+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
run: |
30+
gh release create "${{ steps.tag.outputs.tag }}" \
31+
--repo "${{ github.repository }}" \
32+
--draft \
33+
--title "${{ steps.tag.outputs.tag }}" \
34+
--generate-notes
35+
36+
build-linux:
37+
name: "Linux ${{ matrix.arch }} - PHP ${{ matrix.php }} - ${{ matrix.ts }}"
38+
needs: create-release
39+
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
php: ['8.3', '8.4', '8.5']
44+
arch: ['x86_64', 'arm64']
45+
ts: ['nts', 'zts']
46+
47+
steps:
48+
- uses: actions/checkout@v5
49+
50+
- name: Set build variables
51+
id: build-vars
52+
run: |
53+
if [ "${{ matrix.ts }}" = "zts" ]; then
54+
echo "php-image=${{ matrix.php }}-zts" >> "$GITHUB_OUTPUT"
55+
echo "ts-suffix=-zts" >> "$GITHUB_OUTPUT"
56+
else
57+
echo "php-image=${{ matrix.php }}-cli" >> "$GITHUB_OUTPUT"
58+
echo "ts-suffix=" >> "$GITHUB_OUTPUT"
59+
fi
60+
61+
- name: Build in Docker container
62+
run: |
63+
docker run --rm \
64+
-v "${{ github.workspace }}:/workspace" \
65+
-w /workspace \
66+
-e ARROW_VERSION="${{ needs.create-release.outputs.tag }}" \
67+
php:${{ steps.build-vars.outputs.php-image }} \
68+
bash -c '
69+
set -euo pipefail
70+
71+
echo "::group::Install system dependencies"
72+
apt-get update
73+
apt-get install -y build-essential clang libclang-dev curl pkg-config
74+
echo "::endgroup::"
75+
76+
echo "::group::Install Rust"
77+
curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
78+
source "$HOME/.cargo/env"
79+
echo "::endgroup::"
80+
81+
echo "::group::Build extension"
82+
cargo build --release
83+
echo "::endgroup::"
84+
85+
echo "::group::Verify extension loads"
86+
php -n -d extension=/workspace/target/release/libarrow.so -r "if (!extension_loaded(\"arrow\")) { echo \"ERROR: arrow extension failed to load\n\"; exit(1); } echo \"arrow extension loaded successfully\n\";"
87+
echo "::endgroup::"
88+
89+
echo "::group::Package artifact"
90+
mkdir -p /workspace/dist
91+
cp /workspace/target/release/libarrow.so /workspace/dist/arrow.so
92+
echo "::endgroup::"
93+
'
94+
95+
- name: Create ZIP archive
96+
run: |
97+
cd dist
98+
ARTIFACT_NAME="php_${{ env.EXTENSION_NAME }}-${{ needs.create-release.outputs.tag }}_php${{ matrix.php }}-${{ matrix.arch }}-linux-glibc${{ steps.build-vars.outputs.ts-suffix }}.zip"
99+
zip "$ARTIFACT_NAME" arrow.so
100+
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> "$GITHUB_ENV"
101+
echo "ARTIFACT_PATH=dist/$ARTIFACT_NAME" >> "$GITHUB_ENV"
102+
103+
- name: Upload to release
104+
env:
105+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106+
run: |
107+
gh release upload "${{ needs.create-release.outputs.tag }}" \
108+
"${{ env.ARTIFACT_PATH }}" \
109+
--repo "${{ github.repository }}"
110+
111+
build-macos:
112+
name: "macOS arm64 - PHP ${{ matrix.php }} - ${{ matrix.ts }}"
113+
needs: create-release
114+
runs-on: macos-latest
115+
strategy:
116+
fail-fast: false
117+
matrix:
118+
php: ['8.3', '8.4', '8.5']
119+
ts: ['nts', 'zts']
120+
121+
steps:
122+
- uses: actions/checkout@v5
123+
124+
- name: Setup PHP
125+
uses: shivammathur/setup-php@v2
126+
with:
127+
php-version: ${{ matrix.php }}
128+
env:
129+
phpts: ${{ matrix.ts }}
130+
131+
- name: Set build variables
132+
id: build-vars
133+
run: |
134+
if [ "${{ matrix.ts }}" = "zts" ]; then
135+
echo "ts-suffix=-zts" >> "$GITHUB_OUTPUT"
136+
else
137+
echo "ts-suffix=" >> "$GITHUB_OUTPUT"
138+
fi
139+
140+
- name: Install Rust toolchain
141+
uses: dtolnay/rust-toolchain@stable
142+
143+
- name: Install build dependencies
144+
run: |
145+
brew install llvm
146+
echo "LIBCLANG_PATH=$(brew --prefix llvm)/lib" >> "$GITHUB_ENV"
147+
148+
- name: Build extension
149+
env:
150+
ARROW_VERSION: ${{ needs.create-release.outputs.tag }}
151+
run: cargo build --release
152+
153+
- name: Verify extension loads
154+
run: php -n -d extension=./target/release/libarrow.dylib -r 'if (!extension_loaded("arrow")) { echo "ERROR: arrow extension failed to load\n"; exit(1); } echo "arrow extension loaded successfully\n";'
155+
156+
- name: Create ZIP archive
157+
run: |
158+
mkdir -p dist
159+
cp target/release/libarrow.dylib dist/arrow.so
160+
cd dist
161+
ARTIFACT_NAME="php_${{ env.EXTENSION_NAME }}-${{ needs.create-release.outputs.tag }}_php${{ matrix.php }}-arm64-darwin-bsdlibc${{ steps.build-vars.outputs.ts-suffix }}.zip"
162+
zip "$ARTIFACT_NAME" arrow.so
163+
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> "$GITHUB_ENV"
164+
echo "ARTIFACT_PATH=dist/$ARTIFACT_NAME" >> "$GITHUB_ENV"
165+
166+
- name: Upload to release
167+
env:
168+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
169+
run: |
170+
gh release upload "${{ needs.create-release.outputs.tag }}" \
171+
"${{ env.ARTIFACT_PATH }}" \
172+
--repo "${{ github.repository }}"
173+
174+
publish-release:
175+
name: Publish Release
176+
needs: [create-release, build-linux, build-macos]
177+
runs-on: ubuntu-latest
178+
steps:
179+
- name: Mark release as published
180+
env:
181+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
182+
run: |
183+
gh release edit "${{ needs.create-release.outputs.tag }}" \
184+
--repo "${{ github.repository }}" \
185+
--draft=false

src/extension/arrow-ext/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"build-path": "ext",
3030
"configure-options": [],
3131
"support-zts": true,
32-
"support-nts": true
32+
"support-nts": true,
33+
"download-url-method": ["pre-packaged-binary", "composer-default"],
34+
"os-families-exclude": ["windows"]
3335
}
3436
}

0 commit comments

Comments
 (0)