Skip to content

Commit 9583447

Browse files
committed
Build intl dynamic extension for php wasm web JSPI 8.3
1 parent 73f30e5 commit 9583447

File tree

18 files changed

+390
-141
lines changed

18 files changed

+390
-141
lines changed

packages/php-wasm/compile/build.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ const argParser = yargs(process.argv.slice(2))
9191
choices: ['yes', 'no'],
9292
description: 'Build with mbregex support',
9393
},
94-
WITH_INTL: {
95-
type: 'string',
96-
choices: ['yes', 'no'],
97-
description: 'Build with intl support',
98-
},
9994
WITH_CLI_SAPI: {
10095
type: 'string',
10196
choices: ['yes', 'no'],
@@ -262,8 +257,6 @@ await asyncSpawn(
262257
'--build-arg',
263258
getArg('WITH_MBREGEX'),
264259
'--build-arg',
265-
getArg('WITH_INTL'),
266-
'--build-arg',
267260
getArg('WITH_CLI_SAPI'),
268261
'--build-arg',
269262
getArg('WITH_OPENSSL'),
@@ -331,17 +324,6 @@ await asyncSpawn(
331324
{ cwd: sourceDir, stdio: 'inherit' }
332325
);
333326

334-
// Copy data files
335-
const libDir = path.resolve(process.cwd(), 'packages/php-wasm/compile');
336-
const publicDir = `${path.dirname(path.dirname(outputDir))}`;
337-
if (getArg('WITH_INTL').endsWith('yes') && platform === 'web') {
338-
await asyncSpawn(
339-
'cp',
340-
[`${libDir}/libintl/icudt74l.dat`, `${publicDir}/shared/icudt74l.dat`],
341-
{ cwd: sourceDir, stdio: 'inherit' }
342-
);
343-
}
344-
345327
function asyncSpawn(...args) {
346328
console.log('Running', args[0], args[1].join(' '), '...');
347329
return new Promise((resolve, reject) => {

packages/php-wasm/compile/php/Dockerfile

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ COPY ./libsqlite3/ /root/builds/libsqlite3
4545
COPY ./libxml2/ /root/builds/libxml2
4646
COPY ./libz/ /root/builds/libz
4747
COPY ./oniguruma/ /root/builds/oniguruma
48-
COPY ./libintl/ /root/builds/libintl
4948

5049
RUN if [ "$WITH_JSPI" = "yes" ]; then \
5150
cp -r /root/builds/*/jspi/dist/root/lib/* /root/lib; \
@@ -71,11 +70,6 @@ else \
7170
cp -r /root/builds-libopenssl/asyncify/dist/root/lib /libs/libopenssl; \
7271
fi
7372

74-
# Workaround to add ICU FLAGS to intl below 7.3 to inject -fPIC.
75-
RUN if [[ "${PHP_VERSION:0:1}" -eq "7" && "${PHP_VERSION:2:1}" -eq "2" ]]; then \
76-
sed -i "s/\$ICU_INCS/\$ICU_INCS \$ICU_CFLAGS/" /root/php-src/ext/intl/config.m4; \
77-
fi;
78-
7973
# Workaround to unbundle sqlite from PHP <7.4.
8074
# Prior to 7.4, PHP bundled sqlite internally,
8175
# leading compilation to fail with : wasm-ld: error: duplicate symbol: [sqlite3_xxx]
@@ -135,7 +129,6 @@ ARG OUTPUT_DIR_ON_HOST
135129
ARG WITH_DEBUG
136130
ARG DEBUG_DWARF_COMPILATION_DIR
137131
ARG WITH_WS_NETWORKING_PROXY
138-
ARG WITH_INTL
139132

140133
# The platform to build for: web or node
141134
ARG EMSCRIPTEN_ENVIRONMENT=web
@@ -321,26 +314,6 @@ RUN if [ "$WITH_EXIF" = "yes" ]; \
321314
echo -n ' --disable-exif ' >> /root/.php-configure-flags; \
322315
fi;
323316

324-
# Add intl if needed
325-
RUN if [ "$WITH_INTL" = "yes" ]; \
326-
then \
327-
if [ "${PHP_VERSION:0:1}" -eq "8" ] || [[ "${PHP_VERSION:0:1}" -eq "7" && "${PHP_VERSION:2:1}" -ge "2" ]]; then \
328-
echo -n ' --enable-intl ' >> /root/.php-configure-flags; \
329-
echo -n ' /root/lib/lib/libicudata.a /root/lib/lib/libicui18n.a /root/lib/lib/libicuio.a /root/lib/lib/libicutest.a /root/lib/lib/libicutu.a /root/lib/lib/libicuuc.a ' >> /root/.emcc-php-wasm-sources; \
330-
331-
if [[ "${PHP_VERSION:0:1}" -eq "7" && "${PHP_VERSION:2:1}" -le "3" ]]; then \
332-
/root/replace.sh 's/UBool operator/bool operator/' /root/php-src/ext/intl/breakiterator/codepointiterator_internal.h; \
333-
/root/replace.sh 's/UBool CodePointBreakIterator::operator/bool CodePointBreakIterator::operator/' /root/php-src/ext/intl/breakiterator/codepointiterator_internal.cpp; \
334-
/root/replace.sh 's/ getArg/ phpGetArg/g; s/::getArg/::phpGetArg/g; s/ getMessage/ phpGetMessage/g; s/::getMessage/::phpGetMessage/g' /root/php-src/ext/intl/msgformat/msgformat_helpers.cpp; \
335-
fi; \
336-
337-
if [[ "${PHP_VERSION:0:1}" -eq "7" && "${PHP_VERSION:2:1}" -eq "2" ]]; then \
338-
files=( /root/php-src/ext/intl/collator/collator_sort.c /root/php-src/ext/intl/normalizer/normalizer_normalize.c /root/php-src/ext/intl/dateformat/dateformat_attr.c /root/php-src/ext/intl/timezone/timezone_class.cpp /root/php-src/ext/intl/timezone/timezone_methods.cpp /root/php-src/ext/intl/breakiterator/codepointiterator_internal.cpp ); \
339-
for file in "${files[@]}"; do /root/replace.sh 's/\bFALSE\b/false/g; s/\bTRUE\b/true/g' "$file"; done; \
340-
fi; \
341-
fi; \
342-
fi
343-
344317
# Add mbregex if needed
345318
RUN if [ "$WITH_MBREGEX" = "yes" ] && [ "${PHP_VERSION:0:3}" != "7.0" ]; \
346319
then \

packages/php-wasm/compile/shared/build.js

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,23 @@ const argParser = yargs(process.argv.slice(2))
1919
required: true,
2020
},
2121
OUTPUT_DIR: {
22-
type: 'string',
22+
type: 'array',
2323
description: 'The output directory',
2424
required: true,
2525
},
26+
SHARED_DIR: {
27+
type: 'array',
28+
description: 'The shared directory',
29+
required: true,
30+
},
2631
WITH_DEBUG: {
2732
type: 'string',
2833
choices: ['yes', 'no'],
2934
description: 'Build with DWARF debug information.',
3035
},
3136
WITH_JSPI: {
32-
type: 'boolean',
33-
default: false,
37+
type: 'string',
38+
choices: ['yes', 'no'],
3439
description: 'Build with JSPI support',
3540
},
3641
});
@@ -66,7 +71,9 @@ if (!requestedVersion || requestedVersion === 'undefined') {
6671
}
6772

6873
const sourceDir = path.dirname(new URL(import.meta.url).pathname);
69-
const outputDir = path.resolve(process.cwd(), args['OUTPUT_DIR']);
74+
const outputDirs = args['OUTPUT_DIR'].map((dir) =>
75+
path.resolve(process.cwd(), dir)
76+
);
7077

7178
// Build the base image
7279
await asyncSpawn('make', ['base-image'], {
@@ -98,27 +105,29 @@ await asyncSpawn(
98105

99106
const version = args['PHP_VERSION'].replace('.', '_');
100107

101-
// Store the shared library
102-
await asyncSpawn(
103-
'docker',
104-
[
105-
'run',
106-
'--name',
107-
'playground-php-wasm-tmp',
108-
'--rm',
109-
'-v',
110-
`${outputDir}:/output`,
111-
`playground-php-wasm:${library}`,
112-
// Use sh -c because wildcards are a shell feature and
113-
// they don't work without running cp through shell.
114-
'sh',
115-
'-c',
116-
`rm -rf /output/extensions/${library}/${version} && \
117-
mkdir -p /output/extensions/${library}/${version} && \
118-
cp -rf /root/${library}/modules/* /output/extensions/${library}/${version}`,
119-
],
120-
{ cwd: path.dirname(sourceDir), stdio: 'inherit' }
121-
);
108+
// Store the shared library in output directories
109+
for (const outputDir of outputDirs) {
110+
await asyncSpawn(
111+
'docker',
112+
[
113+
'run',
114+
'--name',
115+
'playground-php-wasm-tmp',
116+
'--rm',
117+
'-v',
118+
`${outputDir}:/output`,
119+
`playground-php-wasm:${library}`,
120+
// Use sh -c because wildcards are a shell feature and
121+
// they don't work without running cp through shell.
122+
'sh',
123+
'-c',
124+
`rm -rf /output/extensions/${library}/${version} && \
125+
mkdir -p /output/extensions/${library}/${version} && \
126+
cp -rf /root/${library}/modules/* /output/extensions/${library}/${version}`,
127+
],
128+
{ cwd: path.dirname(sourceDir), stdio: 'inherit' }
129+
);
130+
}
122131

123132
// Store the shared data if any
124133
await asyncSpawn(
@@ -142,16 +151,19 @@ await asyncSpawn(
142151
{ cwd: path.dirname(sourceDir), stdio: 'inherit' }
143152
);
144153

154+
const sharedDirs = args['SHARED_DIR'].map((dir) =>
155+
path.resolve(process.cwd(), dir)
156+
);
157+
145158
// Copy data files
146159
if (fs.existsSync(`${sourceDir}/${library}/data`)) {
147-
const publicDir = `${path.dirname(
148-
outputDir
149-
)}/src/lib/extensions/${library}/shared`;
150-
await asyncSpawn(
151-
'sh',
152-
['-c', `cp ${sourceDir}/${library}/data/* ${publicDir}`],
153-
{ cwd: sourceDir, stdio: 'inherit' }
154-
);
160+
for (const sharedDir of sharedDirs) {
161+
await asyncSpawn(
162+
'sh',
163+
['-c', `cp ${sourceDir}/${library}/data/* ${sharedDir}`],
164+
{ cwd: sourceDir, stdio: 'inherit' }
165+
);
166+
}
155167
}
156168

157169
function asyncSpawn(...args) {

packages/php-wasm/compile/shared/project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"executor": "nx:run-commands",
77
"options": {
88
"commands": [
9-
"node packages/php-wasm/compile/shared/build.js --LIBRARY_NAME=intl --OUTPUT_DIR=packages/php-wasm/node/jspi --WITH_JSPI=yes"
9+
"node packages/php-wasm/compile/shared/build.js --LIBRARY_NAME=intl --WITH_JSPI=yes --OUTPUT_DIR=packages/php-wasm/node/jspi --SHARED_DIR=packages/php-wasm/node/src/lib/extensions/intl/shared --OUTPUT_DIR=packages/php-wasm/web/public/php/jspi --SHARED_DIR=packages/php-wasm/web/public/shared"
1010
],
1111
"parallel": false
1212
}
@@ -31,7 +31,7 @@
3131
"executor": "nx:run-commands",
3232
"options": {
3333
"commands": [
34-
"node packages/php-wasm/compile/shared/build.js --LIBRARY_NAME=intl --OUTPUT_DIR=packages/php-wasm/node/asyncify"
34+
"node packages/php-wasm/compile/shared/build.js --LIBRARY_NAME=intl --OUTPUT_DIR=packages/php-wasm/node/asyncify --SHARED_DIR=packages/php-wasm/node/src/lib/extensions/intl/shared --OUTPUT_DIR=packages/php-wasm/web/public/php/asyncify --SHARED_DIR=packages/php-wasm/web/public/shared"
3535
],
3636
"parallel": false
3737
}
36 Bytes
Binary file not shown.

packages/php-wasm/web/project.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,6 @@
115115
"maxWarnings": 0
116116
}
117117
},
118-
"test": {
119-
"executor": "@nx/vite:test",
120-
"outputs": ["{workspaceRoot}/coverage/packages/php-wasm/web"],
121-
"options": {
122-
"passWithNoTests": true,
123-
"reportsDirectory": "../../coverage/packages/php-wasm/web"
124-
}
125-
},
126118
"typecheck": {
127119
"executor": "nx:run-commands",
128120
"options": {

packages/php-wasm/web/public/php/asyncify/extensions/intl/8_3/intl.la

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
-16 MB
Binary file not shown.
-2.76 MB
Binary file not shown.

0 commit comments

Comments
 (0)