Skip to content

Commit 908a7a7

Browse files
committed
Implement WebAssembly + WASI GH actions
WebAssembly + WASI GH actions have specific tasks for the following steps: - apt: an existing PHP installation will be used as the test runner, as opposed to the binary being built. It also installs other dependencies used by later stages, such as Wasmtime (WebAssembly runtime), and Binaryen (contains `wasm-opt`, to be used on the optimization phase.) - configure-wasi: specific configure values. - optimize-wasi (new action): performs binaryen optimization passes on the resulting binary. - test-wasi: requires a wrapper that will use `wasmtime` to run the `php` CLI compiled to WebAssembly.
1 parent 0e4ef52 commit 908a7a7

File tree

5 files changed

+190
-0
lines changed

5 files changed

+190
-0
lines changed

.github/actions/apt-wasi/action.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: apt
2+
inputs:
3+
wasi_sdk_version:
4+
default: 19
5+
wasmtime_version:
6+
default: 5.0.0
7+
binaryen_version:
8+
default: 111
9+
runs:
10+
using: composite
11+
steps:
12+
- shell: bash
13+
run: |
14+
set -x
15+
16+
sudo apt-get update
17+
sudo apt-get install \
18+
php \
19+
libtool-bin \
20+
bison \
21+
re2c \
22+
tcl
23+
- shell: bash
24+
run: |
25+
set -x
26+
27+
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${{ inputs.wasi_sdk_version }}/wasi-sdk_${{ inputs.wasi_sdk_version }}.0_amd64.deb
28+
sudo dpkg -i wasi-sdk_${{ inputs.wasi_sdk_version }}.0_amd64.deb
29+
- shell: bash
30+
run: |
31+
echo /opt/wasi-sdk/bin >> $GITHUB_PATH
32+
- shell: bash
33+
run: |
34+
set -x
35+
36+
mkdir -p /opt/bin
37+
38+
wget https://github.com/bytecodealliance/wasmtime/releases/download/v${{ inputs.wasmtime_version }}/wasmtime-v${{ inputs.wasmtime_version }}-x86_64-linux.tar.xz
39+
tar -xvf wasmtime-v${{ inputs.wasmtime_version }}-x86_64-linux.tar.xz
40+
mv wasmtime-v${{ inputs.wasmtime_version }}-x86_64-linux/wasmtime /opt/bin/
41+
- shell: bash
42+
run: |
43+
set -x
44+
45+
mkdir -p /opt/bin
46+
47+
wget https://github.com/WebAssembly/binaryen/releases/download/version_${{ inputs.binaryen_version }}/binaryen-version_${{ inputs.binaryen_version }}-x86_64-linux.tar.gz
48+
tar -xvf binaryen-version_${{ inputs.binaryen_version }}-x86_64-linux.tar.gz --strip-components=2 -C /opt/bin binaryen-version_${{ inputs.binaryen_version }}/bin/wasm-opt
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: ./configure
2+
inputs:
3+
configurationParameters:
4+
default: ''
5+
required: false
6+
runs:
7+
using: composite
8+
steps:
9+
- shell: bash
10+
run: |
11+
set -x
12+
13+
./buildconf --force
14+
./configure \
15+
--host=wasm32-wasi host_alias=wasm32-musl-wasi \
16+
--target=wasm32-wasi target_alias=wasm32-musl-wasi \
17+
--disable-all \
18+
--disable-ctype \
19+
--disable-dom \
20+
--disable-fiber-asm \
21+
--disable-fileinfo \
22+
--disable-filter \
23+
--disable-flatfile \
24+
--disable-huge-code-pages \
25+
--disable-inifile \
26+
--disable-mbregex \
27+
--disable-mysqlnd-compression-support \
28+
--disable-opcache \
29+
--disable-opcache-jit \
30+
--disable-pdo \
31+
--disable-phar \
32+
--disable-posix \
33+
--disable-session \
34+
--disable-simplexml \
35+
--disable-tokenizer \
36+
--disable-xml \
37+
--disable-xmlreader \
38+
--disable-xmlwriter \
39+
--disable-zend-signals \
40+
--without-cdb \
41+
--without-libxml \
42+
--without-openssl \
43+
--without-pcre-jit \
44+
--without-pear \
45+
--without-sqlite3 \
46+
CFLAGS="-D_WASI_EMULATED_GETPID -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS" \
47+
LDFLAGS="-lwasi-emulated-getpid -lwasi-emulated-signal -lwasi-emulated-process-clocks" \
48+
${{ inputs.configurationParameters }}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Optimize
2+
runs:
3+
using: composite
4+
steps:
5+
- shell: bash
6+
run: |
7+
set -x
8+
9+
/opt/bin/wasm-opt -O sapi/cli/php -o sapi/cli/php.optimized
10+
- shell: bash
11+
run: |
12+
set -x
13+
14+
/opt/bin/wasm-opt -O sapi/cgi/php-cgi -o sapi/cgi/php-cgi.optimized

.github/actions/test-wasi/action.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Test
2+
inputs:
3+
testArtifacts:
4+
default: null
5+
required: false
6+
runTestsParameters:
7+
default: ''
8+
required: false
9+
runs:
10+
using: composite
11+
steps:
12+
- shell: bash
13+
run: |
14+
cat <<-'EOF' > /opt/bin/wasmtime-run-cli.sh
15+
#!/bin/bash
16+
WASMTIME_BACKTRACE_DETAILS=1 /opt/bin/wasmtime run --mapdir /::/ "$PWD/sapi/cli/php.optimized" 2> /dev/null -- "$@"
17+
EOF
18+
chmod +x /opt/bin/wasmtime-run-cli.sh
19+
cat <<-'EOF' > /opt/bin/wasmtime-run-cgi.sh
20+
#!/bin/bash
21+
WASMTIME_BACKTRACE_DETAILS=1 /opt/bin/wasmtime run --mapdir /::/ "$PWD/sapi/cgi/php-cgi.optimized" 2> /dev/null -- "$@"
22+
EOF
23+
chmod +x /opt/bin/wasmtime-run-cgi.sh
24+
- shell: bash
25+
run: |
26+
set -x
27+
export SKIP_IO_CAPTURE_TESTS=1
28+
export TEST_PHP_JUNIT=junit.out.xml
29+
export STACK_LIMIT_DEFAULTS_CHECK=1
30+
export TEST_PHP_EXECUTABLE=/opt/bin/wasmtime-run-cli.sh
31+
export TEST_PHP_CGI_EXECUTABLE=/opt/bin/wasmtime-run-cgi.sh
32+
export TEST_PHPDBG_EXECUTABLE=""
33+
php run-tests.php -q ${{ inputs.runTestsParameters }} \
34+
-j$(/usr/bin/nproc) \
35+
-g FAIL,BORK,LEAK,XLEAK \
36+
--no-progress \
37+
--offline \
38+
--show-diff \
39+
--show-slow 1000 \
40+
--set-timeout 120
41+
- uses: actions/upload-artifact@v3
42+
if: always() && inputs.testArtifacts != null
43+
with:
44+
name: ${{ github.job }}_${{ inputs.testArtifacts }}
45+
path: ${{ github.workspace }}/junit.out.xml
46+
retention-days: 5

.github/workflows/push.yml

+34
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,37 @@ jobs:
312312
${{ github.sha }} \
313313
$(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.sha }}) \
314314
> $GITHUB_STEP_SUMMARY
315+
WASM32_WASI:
316+
name: "WASM32_WASI_${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}"
317+
runs-on: ubuntu-20.04
318+
env:
319+
CC: clang
320+
CXX: clang++
321+
LD: wasm-ld
322+
AR: llvm-ar
323+
RANLIB: llvm-ranlib
324+
steps:
325+
- name: git checkout
326+
uses: actions/checkout@v3
327+
- name: apt
328+
uses: ./.github/actions/apt-wasi
329+
- name: ./configure
330+
uses: ./.github/actions/configure-wasi
331+
with:
332+
configurationParameters: >-
333+
--${{ matrix.debug && 'enable' || 'disable' }}-debug
334+
--${{ matrix.zts && 'enable' || 'disable' }}-zts
335+
- name: make
336+
env:
337+
CFLAGS: "-D_WASI_EMULATED_GETPID -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS"
338+
LDFLAGS: "-lwasi-emulated-getpid -lwasi-emulated-signal -lwasi-emulated-process-clocks"
339+
run: make -j$(/usr/bin/nproc) cgi cli
340+
- name: Optimize
341+
uses: ./.github/actions/optimize-wasi
342+
# To be defined how to approach test coverage on this platform.
343+
# - name: Test
344+
# uses: ./.github/actions/test-wasi
345+
# with:
346+
# testArtifacts: ${{ matrix.debug && 'DEBUG' || 'RELEASE' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}
347+
# - name: Verify generated files are up to date
348+
# uses: ./.github/actions/verify-generated-files

0 commit comments

Comments
 (0)