Skip to content

Commit 4382776

Browse files
mho22adamziel
andauthored
[ php-wasm ] Add intl support (#155)
Based on pull request #150 --------- Co-authored-by: Adam Zieliński <[email protected]>
1 parent cb670ec commit 4382776

File tree

518 files changed

+254692
-1231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

518 files changed

+254692
-1231
lines changed

.github/workflows/ci.yml

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: ./.github/actions/prepare-playground
2424
- run: npx nx affected --target=lint
2525
- run: npx nx affected --target=typecheck
26-
test-unit-asyncify:
26+
test-unit-asyncify-node-1-out-of-7:
2727
runs-on: wordpress-playground-private
2828
needs: [lint-and-typecheck]
2929
services:
@@ -53,6 +53,92 @@ jobs:
5353
MYSQL_DATABASE: test_db
5454
MYSQL_USER: user
5555
MYSQL_PASSWORD: password
56+
test-unit-asyncify-node-2-out-of-7:
57+
runs-on: wordpress-playground-private
58+
needs: [lint-and-typecheck]
59+
steps:
60+
- uses: actions/checkout@v4
61+
with:
62+
submodules: true
63+
- uses: ./.github/actions/prepare-playground
64+
with:
65+
node-version: 20
66+
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test-php
67+
test-unit-asyncify-node-3-out-of-7:
68+
runs-on: wordpress-playground-private
69+
needs: [lint-and-typecheck]
70+
steps:
71+
- uses: actions/checkout@v4
72+
with:
73+
submodules: true
74+
- uses: ./.github/actions/prepare-playground
75+
with:
76+
node-version: 20
77+
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test-php-asyncify-file-get-contents
78+
test-unit-asyncify-node-4-out-of-7:
79+
runs-on: wordpress-playground-private
80+
needs: [lint-and-typecheck]
81+
steps:
82+
- uses: actions/checkout@v4
83+
with:
84+
submodules: true
85+
- uses: ./.github/actions/prepare-playground
86+
with:
87+
node-version: 20
88+
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test-php-asyncify-fopen
89+
test-unit-asyncify-node-5-out-of-7:
90+
runs-on: wordpress-playground-private
91+
needs: [lint-and-typecheck]
92+
steps:
93+
- uses: actions/checkout@v4
94+
with:
95+
submodules: true
96+
- uses: ./.github/actions/prepare-playground
97+
with:
98+
node-version: 20
99+
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test-php-asyncify-fsockopen
100+
test-unit-asyncify-node-6-out-of-7:
101+
runs-on: wordpress-playground-private
102+
needs: [lint-and-typecheck]
103+
steps:
104+
- uses: actions/checkout@v4
105+
with:
106+
submodules: true
107+
- uses: ./.github/actions/prepare-playground
108+
with:
109+
node-version: 20
110+
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test-php-asyncify-gethostbyname
111+
test-unit-asyncify-node-7-out-of-7:
112+
runs-on: wordpress-playground-private
113+
needs: [lint-and-typecheck]
114+
services:
115+
mysql:
116+
image: mysql:5.7
117+
env:
118+
MYSQL_DATABASE: test_db
119+
MYSQL_USER: user
120+
MYSQL_PASSWORD: password
121+
MYSQL_ROOT_PASSWORD: rootpassword
122+
ports:
123+
- 3306:3306
124+
options: >-
125+
--health-cmd="mysqladmin ping --silent"
126+
--health-interval=10s
127+
--health-timeout=5s
128+
--health-retries=3
129+
steps:
130+
- uses: actions/checkout@v4
131+
with:
132+
submodules: true
133+
- uses: ./.github/actions/prepare-playground
134+
with:
135+
node-version: 20
136+
- run: node --expose-gc node_modules/nx/bin/nx affected --target=test-php-asyncify-mysqli
137+
env:
138+
MYSQL_DATABASE: test_db
139+
MYSQL_USER: user
140+
MYSQL_PASSWORD: password
141+
56142
# Most of these tests pass locally but the process is crashing
57143
# on the CI runner.
58144
#
@@ -173,7 +259,18 @@ jobs:
173259
github.ref == 'refs/heads/trunk' &&
174260
github.event_name == 'push'
175261
# Add a dependency to the build job
176-
needs: [test-unit-asyncify, test-e2e, build]
262+
needs:
263+
[
264+
test-unit-asyncify-node-1-out-of-7,
265+
test-unit-asyncify-node-2-out-of-7,
266+
test-unit-asyncify-node-3-out-of-7,
267+
test-unit-asyncify-node-4-out-of-7,
268+
test-unit-asyncify-node-5-out-of-7,
269+
test-unit-asyncify-node-6-out-of-7,
270+
test-unit-asyncify-node-7-out-of-7,
271+
test-e2e,
272+
build,
273+
]
177274
name: 'Deploy doc site'
178275

179276
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment

packages/php-wasm/compile/Makefile

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,26 @@ libcurl/jspi/dist/root/lib/lib/libcurl.a: base-image libz libopenssl_jspi
235235
docker cp $$(docker create playground-php-wasm:libcurl):/root/curl-7.69.1/lib/.libs ./libcurl/jspi/dist/root/lib/lib
236236
docker cp $$(docker create playground-php-wasm:libcurl):/root/curl-7.69.1/include/ ./libcurl/jspi/dist/root/lib
237237

238+
libintl_asyncify: libintl/asyncify/dist/root/lib/lib/libintl.a
239+
libintl/asyncify/dist/root/lib/lib/libintl.a: base-image
240+
mkdir -p ./libintl/asyncify/dist/root/lib
241+
docker build -f ./libintl/Dockerfile -t playground-php-wasm:libintl . --progress=plain
242+
docker cp $$(docker create playground-php-wasm:libintl):/root/lib/lib ./libintl/asyncify/dist/root/lib
243+
docker cp $$(docker create playground-php-wasm:libintl):/root/lib/include ./libintl/asyncify/dist/root/lib
244+
docker cp $$(docker create playground-php-wasm:libintl):/root/lib/data/. ./libintl/
245+
246+
247+
libintl_jspi: libintl/jspi/dist/root/lib/lib/libintl.a
248+
libintl/jspi/dist/root/lib/lib/libintl.a: base-image
249+
mkdir -p ./libintl/jspi/dist/root/lib
250+
docker build -f ./libintl/Dockerfile -t playground-php-wasm:libintl . --progress=plain --build-arg JSPI=1
251+
docker cp $$(docker create playground-php-wasm:libintl):/root/lib/lib ./libintl/jspi/dist/root/lib
252+
docker cp $$(docker create playground-php-wasm:libintl):/root/lib/include ./libintl/jspi/dist/root/lib
253+
docker cp $$(docker create playground-php-wasm:libintl):/root/lib/data/. ./libintl/
254+
238255
all: all_jspi all_asyncify
239-
all_jspi: libz_jspi libzip_jspi libpng16_jspi libjpeg_jspi libwebp_jspi libxml2_jspi libopenssl_jspi libsqlite3_jspi libiconv_jspi bison2.7 oniguruma_jspi libcurl_jspi
240-
all_asyncify: libz_asyncify libzip_asyncify libpng16_asyncify libjpeg_asyncify libwebp_asyncify libxml2_asyncify libopenssl_asyncify libsqlite3_asyncify libiconv_asyncify bison2.7 oniguruma_asyncify libcurl_asyncify
256+
all_jspi: libz_jspi libzip_jspi libpng16_jspi libjpeg_jspi libwebp_jspi libxml2_jspi libopenssl_jspi libsqlite3_jspi libiconv_jspi bison2.7 oniguruma_jspi libcurl_jspi libintl_jspi
257+
all_asyncify: libz_asyncify libzip_asyncify libpng16_asyncify libjpeg_asyncify libwebp_asyncify libxml2_asyncify libopenssl_asyncify libsqlite3_asyncify libiconv_asyncify bison2.7 oniguruma_asyncify libcurl_asyncify libintl_asyncify
241258

242259
clean:
243260
rm -rf ./libz/jspi/dist
@@ -261,3 +278,5 @@ clean:
261278
rm -rf ./bison2.7/dist
262279
rm -rf ./oniguruma/jspi/dist
263280
rm -rf ./oniguruma/asyncify/dist
281+
rm -rf ./libintl/jspi/dist
282+
rm -rf ./libintl/asyncify/dist

packages/php-wasm/compile/build.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ const argParser = yargs(process.argv.slice(2))
6666
choices: ['yes', 'no'],
6767
description: 'Build with mbregex support',
6868
},
69+
WITH_INTL: {
70+
type: 'string',
71+
choices: ['yes', 'no'],
72+
description: 'Build with intl support',
73+
},
6974
WITH_CLI_SAPI: {
7075
type: 'string',
7176
choices: ['yes', 'no'],
@@ -150,6 +155,7 @@ const platformDefaults = {
150155
WITH_GD: 'yes',
151156
WITH_MBSTRING: 'yes',
152157
WITH_MBREGEX: 'yes',
158+
WITH_INTL: 'yes',
153159
WITH_OPENSSL: 'yes',
154160
WITH_WS_NETWORKING_PROXY: 'yes',
155161
},
@@ -219,6 +225,8 @@ await asyncSpawn(
219225
'--build-arg',
220226
getArg('WITH_MBREGEX'),
221227
'--build-arg',
228+
getArg('WITH_INTL'),
229+
'--build-arg',
222230
getArg('WITH_CLI_SAPI'),
223231
'--build-arg',
224232
getArg('WITH_OPENSSL'),
@@ -273,6 +281,20 @@ await asyncSpawn(
273281
{ cwd: sourceDir, stdio: 'inherit' }
274282
);
275283

284+
// Copy data files
285+
const libDir = path.resolve(process.cwd(), 'packages/php-wasm/compile');
286+
const publicDir =
287+
platform === 'node'
288+
? `${path.dirname(outputDir)}/src/lib/data`
289+
: `${path.dirname(path.dirname(outputDir))}`;
290+
if (getArg('WITH_INTL').endsWith('yes')) {
291+
await asyncSpawn(
292+
'cp',
293+
[`${libDir}/libintl/icudt74l.dat`, `${publicDir}/shared/icudt74l.dat`],
294+
{ cwd: sourceDir, stdio: 'inherit' }
295+
);
296+
}
297+
276298
const _args = args;
277299

278300
function asyncSpawn(...args) {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
FROM playground-php-wasm:base
2+
3+
4+
ARG JSPI
5+
6+
7+
RUN set -euxo pipefail && \
8+
wget https://github.com/unicode-org/icu/releases/download/release-74-2/icu4c-74_2-src.tgz && \
9+
tar -xvf icu4c-74_2-src.tgz && \
10+
rm -rf /root/icu/source/data/ && \
11+
rm icu4c-74_2-src.tgz
12+
13+
14+
RUN set -euxo pipefail && \
15+
wget https://github.com/unicode-org/icu/releases/download/release-74-2/icu4c-74_2-data.zip && \
16+
unzip icu4c-74_2-data.zip -d /root/icu/source && \
17+
rm icu4c-74_2-data.zip
18+
19+
20+
RUN set -euxo pipefail && \
21+
mkdir -p /root/native && \
22+
cd /root/native && \
23+
/root/icu/source/runConfigureICU Linux \
24+
--disable-shared \
25+
--enable-static && \
26+
make -j"$(nproc)" && \
27+
make install
28+
29+
30+
RUN set -euxo pipefail && \
31+
cd /root/icu/source && \
32+
mkdir -p /root/lib && \
33+
source /root/emsdk/emsdk_env.sh && \
34+
emconfigure ./configure \
35+
--build=i386-pc-linux-gnu \
36+
--target=wasm32-unknown-emscripten \
37+
--prefix=/root/lib \
38+
--with-cross-build=/root/native \
39+
--with-data-packaging=archive \
40+
--disable-extras \
41+
--disable-shared \
42+
--enable-static && \
43+
export JSPI_FLAGS=$(if [ "$JSPI" = "1" ]; then echo "-sSUPPORT_LONGJMP=wasm -fwasm-exceptions"; else echo ""; fi) && \
44+
EMCC_FLAGS=" -D__x86_64__ -sSIDE_MODULE $JSPI_FLAGS " emmake make -j"$(nproc)" && \
45+
EMCC_FLAGS=" -D__x86_64__ -sSIDE_MODULE $JSPI_FLAGS " emmake make install -i;
46+
47+
48+
RUN set -euxo pipefail && \
49+
mkdir -p /root/lib/data && \
50+
mv /root/lib/share/icu/74.2/icudt74l.dat /root/lib/data

0 commit comments

Comments
 (0)