Skip to content

Commit f54d3c5

Browse files
committed
Update intl Dockerfile for Node JSPI
1 parent 92789e9 commit f54d3c5

File tree

4 files changed

+144
-107
lines changed

4 files changed

+144
-107
lines changed

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

Lines changed: 56 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,50 @@ import yargs from 'yargs';
88
const argParser = yargs(process.argv.slice(2))
99
.usage('Usage: $0 [options]')
1010
.options({
11-
LIBRARY_NAME: {
11+
LIBRARY: {
1212
type: 'string',
13-
description: 'The library to build',
1413
required: true,
14+
description: 'The library to build',
1515
},
1616
PHP_VERSION: {
1717
type: 'string',
18+
default: '8.0.24',
1819
description: 'The PHP version to build',
19-
required: true,
2020
},
21-
OUTPUT_DIR: {
22-
type: 'array',
23-
description: 'The output directory',
24-
required: true,
21+
PLATFORM: {
22+
type: 'string',
23+
choices: ['web', 'node'],
24+
default: 'web',
25+
description: 'The platform to build for',
2526
},
26-
SHARED_DIR: {
27-
type: 'array',
28-
description: 'The shared directory',
29-
required: true,
27+
JSPI: {
28+
type: 'string',
29+
choices: ['yes', 'no'],
30+
default: 'no',
31+
description: 'Build with JSPI support',
3032
},
31-
WITH_DEBUG: {
33+
DEBUG: {
3234
type: 'string',
3335
choices: ['yes', 'no'],
36+
default: 'no',
3437
description: 'Build with DWARF debug information.',
3538
},
36-
WITH_JSPI: {
39+
OUTPUT_DIR: {
3740
type: 'string',
38-
choices: ['yes', 'no'],
39-
description: 'Build with JSPI support',
41+
required: true,
42+
description: 'The output directory',
43+
},
44+
SHARED_DIR: {
45+
type: 'string',
46+
required: true,
47+
description: 'The shared directory',
4048
},
4149
});
4250

4351
const args = argParser.argv;
4452

45-
const platformDefaults = {
46-
all: {
47-
PHP_VERSION: '8.0.24',
48-
WITH_DEBUG: 'no',
49-
WITH_JSPI: 'no',
50-
},
51-
};
52-
5353
const getArg = (name) => {
54-
let value =
55-
name in args
56-
? args[name]
57-
: name in platformDefaults.all
58-
? platformDefaults.all[name]
59-
: 'no';
54+
let value = name in args ? args[name] : 'no';
6055
if (name === 'PHP_VERSION') {
6156
value = fullyQualifiedPHPVersion(value);
6257
}
@@ -71,17 +66,15 @@ if (!requestedVersion || requestedVersion === 'undefined') {
7166
}
7267

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

7871
// Build the base image
7972
await asyncSpawn('make', ['base-image'], {
8073
cwd: path.dirname(sourceDir),
8174
stdio: 'inherit',
8275
});
8376

84-
const library = args['LIBRARY_NAME'];
77+
const library = args['LIBRARY'];
8578

8679
// Build the shared library
8780
await asyncSpawn(
@@ -96,38 +89,38 @@ await asyncSpawn(
9689
'--build-arg',
9790
getArg('PHP_VERSION'),
9891
'--build-arg',
99-
getArg('WITH_DEBUG'),
92+
getArg('PLATFORM'),
93+
'--build-arg',
94+
getArg('DEBUG'),
10095
'--build-arg',
101-
getArg('WITH_JSPI'),
96+
getArg('JSPI'),
10297
],
10398
{ cwd: path.dirname(sourceDir), stdio: 'inherit' }
10499
);
105100

106101
const version = args['PHP_VERSION'].replace('.', '_');
107102

108103
// 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-
}
104+
await asyncSpawn(
105+
'docker',
106+
[
107+
'run',
108+
'--name',
109+
'playground-php-wasm-tmp',
110+
'--rm',
111+
'-v',
112+
`${outputDir}:/output`,
113+
`playground-php-wasm:${library}`,
114+
// Use sh -c because wildcards are a shell feature and
115+
// they don't work without running cp through shell.
116+
'sh',
117+
'-c',
118+
`rm -rf /output/extensions/${library}/${version} && \
119+
mkdir -p /output/extensions/${library}/${version} && \
120+
cp -rf /root/${library}/modules/* /output/extensions/${library}/${version}`,
121+
],
122+
{ cwd: path.dirname(sourceDir), stdio: 'inherit' }
123+
);
131124

132125
// Store the shared data if any
133126
await asyncSpawn(
@@ -151,19 +144,15 @@ await asyncSpawn(
151144
{ cwd: path.dirname(sourceDir), stdio: 'inherit' }
152145
);
153146

154-
const sharedDirs = args['SHARED_DIR'].map((dir) =>
155-
path.resolve(process.cwd(), dir)
156-
);
147+
const sharedDir = path.resolve(process.cwd(), args['SHARED_DIR']);
157148

158149
// Copy data files
159150
if (fs.existsSync(`${sourceDir}/${library}/data`)) {
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-
}
151+
await asyncSpawn(
152+
'sh',
153+
['-c', `cp ${sourceDir}/${library}/data/* ${sharedDir}`],
154+
{ cwd: sourceDir, stdio: 'inherit' }
155+
);
167156
}
168157

169158
function asyncSpawn(...args) {

packages/php-wasm/compile/shared/intl/Dockerfile

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ FROM playground-php-wasm:base
66
# compatible with a particular Zend Engine API version.
77
ARG PHP_VERSION
88

9-
ARG WITH_JSPI
9+
ARG PLATFORM
1010

11-
ARG WITH_DEBUG
11+
ARG JSPI
12+
13+
ARG DEBUG
1214

1315
# Install Bison, required to build PHP
1416
RUN mkdir -p /libs
@@ -115,13 +117,15 @@ RUN set -euxo pipefail; \
115117
make -j1; \
116118
make install; \
117119

118-
# Calling close() on a file descriptor acquired through WASI syscalls can trigger a JS call/await
119-
# during a non-resumable C++ stack frame, leading to "RuntimeError: trying to suspend JS frames".
120-
# Since ICU maps the file into memory and does not require the descriptor after mapping
121-
# under our build context, skipping close(fd) avoids that suspension error.
122-
# NOTE: This means the file descriptor will remain open until process teardown.
123-
# This is acceptable here because ICU data files are loaded only once at startup.
124-
/root/replace.sh 's/close\(fd\);//' /root/icu/source/common/umapfile.cpp; \
120+
if [ "$PLATFORM" = "node" ]; then \
121+
# Calling close() on a file descriptor acquired through WASI syscalls can trigger a JS call/await
122+
# during a non-resumable C++ stack frame, leading to "RuntimeError: trying to suspend JS frames".
123+
# Since ICU maps the file into memory and does not require the descriptor after mapping
124+
# under our build context, skipping close(fd) avoids that suspension error.
125+
# NOTE: This means the file descriptor will remain open until process teardown.
126+
# This is acceptable here because ICU data files are loaded only once at startup.
127+
/root/replace.sh 's/close\(fd\);//' /root/icu/source/common/umapfile.cpp; \
128+
fi; \
125129

126130
cd /root/icu/source; \
127131
mkdir -p /root; \
@@ -176,21 +180,15 @@ RUN set -euxo pipefail; \
176180
/root/replace.sh 's|INTL_SHARED_LIBADD\s*=.*||' Makefile; \
177181
fi; \
178182

179-
# The generated Makefile incorrectly sets INTL_SHARED_LIBADD to include static ICU libraries.
180-
# This breaks building a dynamic intl extension with Emscripten.
181-
if [[ "${PHP_VERSION:0:1}" -eq "7" && "${PHP_VERSION:2:1}" -le "3" ]]; then \
182-
/root/replace.sh 's|INTL_SHARED_LIBADD\s*=.*||' Makefile; \
183-
fi; \
184-
185183
export EMCC_FLAGS="-sSIDE_MODULE -D__x86_64__"; \
186184

187-
if [ "$WITH_DEBUG" = "yes" ]; then \
185+
if [ "$DEBUG" = "yes" ]; then \
188186
export EMCC_FLAGS="${EMCC_FLAGS} -O0 -g3"; \
189187
else \
190188
export EMCC_FLAGS="${EMCC_FLAGS} -O3"; \
191189
fi; \
192190

193-
if [ "$WITH_JSPI" = "yes" ]; then \
191+
if [ "$JSPI" = "yes" ]; then \
194192
export EMCC_FLAGS="${EMCC_FLAGS} -sJSPI"; \
195193
else \
196194
export EMCC_FLAGS="${EMCC_FLAGS} -sASYNCIFY -sASYNCIFY_ADVISE"; \

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

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,103 @@
11
{
22
"name": "php-wasm-compile-shared",
3-
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
3+
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
44
"targets": {
5-
"intl:jspi": {
5+
"intl:node:jspi": {
66
"executor": "nx:run-commands",
77
"options": {
88
"commands": [
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"
9+
"node packages/php-wasm/compile/shared/build.js --LIBRARY=intl --PLATFORM=node --JSPI=yes --OUTPUT_DIR=packages/php-wasm/node/jspi --SHARED_DIR=packages/php-wasm/node/src/lib/extensions/intl/shared"
1010
],
1111
"parallel": false
1212
}
1313
},
14-
"intl:jspi:all": {
14+
"intl:node:jspi:all": {
1515
"executor": "nx:run-commands",
1616
"options": {
1717
"commands": [
18-
"nx run php-wasm-compile-shared:intl:jspi --PHP_VERSION=8.4",
19-
"nx run php-wasm-compile-shared:intl:jspi --PHP_VERSION=8.3",
20-
"nx run php-wasm-compile-shared:intl:jspi --PHP_VERSION=8.2",
21-
"nx run php-wasm-compile-shared:intl:jspi --PHP_VERSION=8.1",
22-
"nx run php-wasm-compile-shared:intl:jspi --PHP_VERSION=8.0",
23-
"nx run php-wasm-compile-shared:intl:jspi --PHP_VERSION=7.4",
24-
"nx run php-wasm-compile-shared:intl:jspi --PHP_VERSION=7.3",
25-
"nx run php-wasm-compile-shared:intl:jspi --PHP_VERSION=7.2"
18+
"nx run php-wasm-compile-shared:intl:node:jspi --PHP_VERSION=8.4",
19+
"nx run php-wasm-compile-shared:intl:node:jspi --PHP_VERSION=8.3",
20+
"nx run php-wasm-compile-shared:intl:node:jspi --PHP_VERSION=8.2",
21+
"nx run php-wasm-compile-shared:intl:node:jspi --PHP_VERSION=8.1",
22+
"nx run php-wasm-compile-shared:intl:node:jspi --PHP_VERSION=8.0",
23+
"nx run php-wasm-compile-shared:intl:node:jspi --PHP_VERSION=7.4",
24+
"nx run php-wasm-compile-shared:intl:node:jspi --PHP_VERSION=7.3",
25+
"nx run php-wasm-compile-shared:intl:node:jspi --PHP_VERSION=7.2"
2626
],
2727
"parallel": false
2828
}
2929
},
30-
"intl:asyncify": {
30+
"intl:node:asyncify": {
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 --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"
34+
"node packages/php-wasm/compile/shared/build.js --LIBRARY=intl --PLATFORM=node --OUTPUT_DIR=packages/php-wasm/node/asyncify --SHARED_DIR=packages/php-wasm/node/src/lib/extensions/intl/shared"
3535
],
3636
"parallel": false
3737
}
3838
},
39-
"intl:asyncify:all": {
39+
"intl:node:asyncify:all": {
4040
"executor": "nx:run-commands",
4141
"options": {
4242
"commands": [
43-
"nx run php-wasm-compile-shared:intl:asyncify --PHP_VERSION=8.4",
44-
"nx run php-wasm-compile-shared:intl:asyncify --PHP_VERSION=8.3",
45-
"nx run php-wasm-compile-shared:intl:asyncify --PHP_VERSION=8.2",
46-
"nx run php-wasm-compile-shared:intl:asyncify --PHP_VERSION=8.1",
47-
"nx run php-wasm-compile-shared:intl:asyncify --PHP_VERSION=8.0",
48-
"nx run php-wasm-compile-shared:intl:asyncify --PHP_VERSION=7.4",
49-
"nx run php-wasm-compile-shared:intl:asyncify --PHP_VERSION=7.3",
50-
"nx run php-wasm-compile-shared:intl:asyncify --PHP_VERSION=7.2"
43+
"nx run php-wasm-compile-shared:intl:node:asyncify --PHP_VERSION=8.4",
44+
"nx run php-wasm-compile-shared:intl:node:asyncify --PHP_VERSION=8.3",
45+
"nx run php-wasm-compile-shared:intl:node:asyncify --PHP_VERSION=8.2",
46+
"nx run php-wasm-compile-shared:intl:node:asyncify --PHP_VERSION=8.1",
47+
"nx run php-wasm-compile-shared:intl:node:asyncify --PHP_VERSION=8.0",
48+
"nx run php-wasm-compile-shared:intl:node:asyncify --PHP_VERSION=7.4",
49+
"nx run php-wasm-compile-shared:intl:node:asyncify --PHP_VERSION=7.3",
50+
"nx run php-wasm-compile-shared:intl:node:asyncify --PHP_VERSION=7.2"
51+
],
52+
"parallel": false
53+
}
54+
},
55+
"intl:web:jspi": {
56+
"executor": "nx:run-commands",
57+
"options": {
58+
"commands": [
59+
"node packages/php-wasm/compile/shared/build.js --LIBRARY=intl --JSPI=yes --OUTPUT_DIR=packages/php-wasm/web/public/php/jspi --SHARED_DIR=packages/php-wasm/web/public/shared"
60+
],
61+
"parallel": false
62+
}
63+
},
64+
"intl:web:jspi:all": {
65+
"executor": "nx:run-commands",
66+
"options": {
67+
"commands": [
68+
"nx run php-wasm-compile-shared:intl:web:jspi --PHP_VERSION=8.4",
69+
"nx run php-wasm-compile-shared:intl:web:jspi --PHP_VERSION=8.3",
70+
"nx run php-wasm-compile-shared:intl:web:jspi --PHP_VERSION=8.2",
71+
"nx run php-wasm-compile-shared:intl:web:jspi --PHP_VERSION=8.1",
72+
"nx run php-wasm-compile-shared:intl:web:jspi --PHP_VERSION=8.0",
73+
"nx run php-wasm-compile-shared:intl:web:jspi --PHP_VERSION=7.4",
74+
"nx run php-wasm-compile-shared:intl:web:jspi --PHP_VERSION=7.3",
75+
"nx run php-wasm-compile-shared:intl:web:jspi --PHP_VERSION=7.2"
76+
],
77+
"parallel": false
78+
}
79+
},
80+
"intl:web:asyncify": {
81+
"executor": "nx:run-commands",
82+
"options": {
83+
"commands": [
84+
"node packages/php-wasm/compile/shared/build.js --LIBRARY=intl --OUTPUT_DIR=packages/php-wasm/web/public/php/asyncify --SHARED_DIR=packages/php-wasm/web/public/shared"
85+
],
86+
"parallel": false
87+
}
88+
},
89+
"intl:web:asyncify:all": {
90+
"executor": "nx:run-commands",
91+
"options": {
92+
"commands": [
93+
"nx run php-wasm-compile-shared:intl:web:asyncify --PHP_VERSION=8.4",
94+
"nx run php-wasm-compile-shared:intl:web:asyncify --PHP_VERSION=8.3",
95+
"nx run php-wasm-compile-shared:intl:web:asyncify --PHP_VERSION=8.2",
96+
"nx run php-wasm-compile-shared:intl:web:asyncify --PHP_VERSION=8.1",
97+
"nx run php-wasm-compile-shared:intl:web:asyncify --PHP_VERSION=8.0",
98+
"nx run php-wasm-compile-shared:intl:web:asyncify --PHP_VERSION=7.4",
99+
"nx run php-wasm-compile-shared:intl:web:asyncify --PHP_VERSION=7.3",
100+
"nx run php-wasm-compile-shared:intl:web:asyncify --PHP_VERSION=7.2"
51101
],
52102
"parallel": false
53103
}
-22 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)