| 5 | import { ensureDir, type BuildConfig } from './util.ts'; |
| 6 | |
| 7 | export async function buildPlatformBinding(config: BuildConfig) { |
| 8 | await new Promise((resolve, reject) => { |
| 9 | try { |
| 10 | ensureDir(config.distQwikPkgDir); |
| 11 | ensureDir(config.distBindingsDir); |
| 12 | |
| 13 | const cmd = `napi`; |
| 14 | const args = [ |
| 15 | `build`, |
| 16 | `--cargo-name`, |
| 17 | 'qwik_napi', |
| 18 | `--platform`, |
| 19 | `--config=packages/qwik/src/napi/napi.config.json`, |
| 20 | config.distBindingsDir, |
| 21 | ]; |
| 22 | |
| 23 | if (config.platformTarget) { |
| 24 | args.push(`--target`, config.platformTarget); |
| 25 | } |
| 26 | if (!config.dev) { |
| 27 | args.push(`--release`); |
| 28 | args.push(`--strip`); |
| 29 | } |
| 30 | |
| 31 | const napiCwd = join(config.rootDir); |
| 32 | |
| 33 | const child = spawn(cmd, args, { stdio: 'inherit', cwd: napiCwd }); |
| 34 | child.on('error', reject); |
| 35 | |
| 36 | child.on('close', (code) => { |
| 37 | if (code === 0) { |
| 38 | resolve(child.stdout); |
| 39 | } else { |
| 40 | reject(`napi exited with code ${code}`); |
| 41 | } |
| 42 | }); |
| 43 | } catch (e) { |
| 44 | reject(e); |
| 45 | } |
| 46 | }); |
| 47 | |
| 48 | console.log('🐯 native binding'); |
| 49 | } |
| 50 | |
| 51 | // TODO only download current target and wasm |
| 52 | export async function copyPlatformBindingWasm(config: BuildConfig) { |