Skip to content

Commit 9555ef6

Browse files
committed
refactor(yoga-layout): keep flag arrays as arrays instead of strings
- Keep cxxFlags, linkerFlags, and wasmOptFlags as arrays - Join them only when passing to cmake as string arguments - Spread them directly when using with spawn for em++ and wasm-opt - Cleaner and more maintainable code
1 parent 13ef983 commit 9555ef6

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

packages/yoga-layout/scripts/build.mjs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async function configure() {
128128
'-fdata-sections', // Separate data sections.
129129
'-ffast-math', // Fast math optimizations (performance).
130130
'-fno-finite-math-only', // Re-enable infinity checks (Yoga needs this).
131-
].join(' ')
131+
]
132132

133133
const linkerFlags = [
134134
'--closure 1', // Google Closure Compiler (aggressive minification).
@@ -146,24 +146,24 @@ async function configure() {
146146
'-s STACK_SIZE=16KB', // Small stack.
147147
'-s SUPPORT_LONGJMP=0', // No longjmp (smaller).
148148
'-s WASM_ASYNC_COMPILATION=0', // CRITICAL: Synchronous instantiation for bundling.
149-
].join(' ')
149+
]
150150

151151
const cmakeArgs = [
152152
'cmake',
153153
`-DCMAKE_TOOLCHAIN_FILE=${toolchainFile}`,
154154
'-DCMAKE_BUILD_TYPE=Release',
155-
`-DCMAKE_CXX_FLAGS=${cxxFlags}`,
156-
`-DCMAKE_EXE_LINKER_FLAGS=${linkerFlags}`,
157-
`-DCMAKE_SHARED_LINKER_FLAGS=${linkerFlags}`,
155+
`-DCMAKE_CXX_FLAGS=${cxxFlags.join(' ')}`,
156+
`-DCMAKE_EXE_LINKER_FLAGS=${linkerFlags.join(' ')}`,
157+
`-DCMAKE_SHARED_LINKER_FLAGS=${linkerFlags.join(' ')}`,
158158
`-S`,
159159
YOGA_SOURCE_DIR,
160160
`-B`,
161161
cmakeBuildDir,
162162
]
163163

164164
printStep('Optimization flags:')
165-
printStep(` CXX: ${cxxFlags}`)
166-
printStep(` Linker: ${linkerFlags}`)
165+
printStep(` CXX: ${cxxFlags.join(' ')}`)
166+
printStep(` Linker: ${linkerFlags.join(' ')}`)
167167

168168
await spawn('emcmake', cmakeArgs, { shell: WIN32, stdio: 'inherit' })
169169

@@ -207,7 +207,7 @@ async function build() {
207207
'-fdata-sections',
208208
'-ffast-math',
209209
'-fno-finite-math-only',
210-
].join(' ')
210+
]
211211

212212
const linkerFlags = [
213213
'--closure 1',
@@ -225,15 +225,15 @@ async function build() {
225225
'-s STACK_SIZE=16KB',
226226
'-s SUPPORT_LONGJMP=0',
227227
'--bind',
228-
].join(' ')
228+
]
229229

230230
// Compile and link in one step.
231231
const emArgs = [
232232
`-I${path.join(BUILD_DIR, 'yoga-source')}`,
233-
...cxxFlags.split(' '),
233+
...cxxFlags,
234234
bindingsFile,
235235
staticLib,
236-
...linkerFlags.split(' '),
236+
...linkerFlags,
237237
'-o',
238238
jsOutput,
239239
]
@@ -296,9 +296,9 @@ async function optimize() {
296296
'--strip-dwarf',
297297
'--strip-producers',
298298
'--strip-target-features',
299-
].join(' ')
299+
]
300300

301-
await spawn('wasm-opt', [...wasmOptFlags.split(' '), wasmFile, '-o', wasmFile], {
301+
await spawn('wasm-opt', [...wasmOptFlags, wasmFile, '-o', wasmFile], {
302302
shell: WIN32,
303303
stdio: 'inherit',
304304
})

0 commit comments

Comments
 (0)