(config: BuildConfig)
| 4 | import { rollup } from 'rollup'; |
| 5 | |
| 6 | export async function buildWasmBinding(config: BuildConfig) { |
| 7 | const srcWasmDir = join(config.srcQwikDir, `wasm`); |
| 8 | const tmpBuildDir = join(config.tmpDir, `wasm-out`); |
| 9 | |
| 10 | ensureDir(config.distQwikPkgDir); |
| 11 | ensureDir(config.distBindingsDir); |
| 12 | emptyDir(tmpBuildDir); |
| 13 | |
| 14 | async function buildForTarget(env = {}) { |
| 15 | const cmd = `wasm-pack`; |
| 16 | const args = [`build`, '--target', 'web', `--out-dir`, tmpBuildDir, srcWasmDir]; |
| 17 | if (!config.dev) { |
| 18 | args.push(`--release`); |
| 19 | } |
| 20 | |
| 21 | await new Promise((resolve, reject) => { |
| 22 | const child = spawn(cmd, args, { |
| 23 | stdio: 'inherit', |
| 24 | shell: true, |
| 25 | env: { |
| 26 | ...process.env, |
| 27 | ...env, |
| 28 | }, |
| 29 | }); |
| 30 | child.on('error', reject); |
| 31 | |
| 32 | child.on('close', (code) => { |
| 33 | if (code === 0) { |
| 34 | resolve(child.stdout); |
| 35 | } else { |
| 36 | reject(`wasm-pack exited with code ${code}`); |
| 37 | } |
| 38 | }); |
| 39 | }); |
| 40 | return join(tmpBuildDir, 'qwik_wasm.js'); |
| 41 | } |
| 42 | |
| 43 | const wasmJsBuildPath = await buildForTarget({ |
| 44 | CARGO_PROFILE_RELEASE_LTO: true, |
| 45 | CARGO_PROFILE_RELEASE_PANIC: 'abort', |
| 46 | CARGO_PROFILE_RELEASE_OPT_LEVEL: 'z', |
| 47 | }); |
| 48 | |
| 49 | const build = await rollup({ |
| 50 | input: wasmJsBuildPath, |
| 51 | }); |
| 52 | |
| 53 | await build.write({ |
| 54 | format: 'es', |
| 55 | file: join(config.distBindingsDir, 'qwik.wasm.mjs'), |
| 56 | exports: 'named', |
| 57 | }); |
| 58 | |
| 59 | await build.write({ |
| 60 | format: 'cjs', |
| 61 | file: join(config.distBindingsDir, 'qwik.wasm.cjs'), |
| 62 | exports: 'named', |
| 63 | }); |
no test coverage detected
searching dependent graphs…