@napi-rs/cli 3.0.0-alpha.4 → 3.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/cli.mjs +0 -0
  2. package/dist/api/artifacts.js +5 -2
  3. package/dist/api/artifacts.js.map +1 -0
  4. package/dist/api/build.d.ts +1 -1
  5. package/dist/api/build.js +98 -27
  6. package/dist/api/build.js.map +1 -0
  7. package/dist/api/create-npm-dirs.js +1 -0
  8. package/dist/api/create-npm-dirs.js.map +1 -0
  9. package/dist/api/load-wasi-template.d.ts +1 -0
  10. package/dist/api/load-wasi-template.js +63 -0
  11. package/dist/api/load-wasi-template.js.map +1 -0
  12. package/dist/api/new.js +2 -1
  13. package/dist/api/new.js.map +1 -0
  14. package/dist/api/pre-publish.js +1 -0
  15. package/dist/api/pre-publish.js.map +1 -0
  16. package/dist/api/rename.js +1 -0
  17. package/dist/api/rename.js.map +1 -0
  18. package/dist/api/templates/.gitignore.d.ts +1 -1
  19. package/dist/api/templates/.gitignore.js +2 -0
  20. package/dist/api/templates/.gitignore.js.map +1 -0
  21. package/dist/api/templates/.npmignore.js +1 -0
  22. package/dist/api/templates/.npmignore.js.map +1 -0
  23. package/dist/api/templates/build.rs.js +1 -0
  24. package/dist/api/templates/build.rs.js.map +1 -0
  25. package/dist/api/templates/cargo.toml.js +1 -0
  26. package/dist/api/templates/cargo.toml.js.map +1 -0
  27. package/dist/api/templates/ci-template.js +48 -35
  28. package/dist/api/templates/ci-template.js.map +1 -0
  29. package/dist/api/templates/ci.yml.d.ts +1 -1
  30. package/dist/api/templates/ci.yml.js +10 -3
  31. package/dist/api/templates/ci.yml.js.map +1 -0
  32. package/dist/api/templates/index.js +1 -0
  33. package/dist/api/templates/index.js.map +1 -0
  34. package/dist/api/templates/js-binding.d.ts +1 -1
  35. package/dist/api/templates/js-binding.js +49 -13
  36. package/dist/api/templates/js-binding.js.map +1 -0
  37. package/dist/api/templates/lib.rs.js +1 -0
  38. package/dist/api/templates/lib.rs.js.map +1 -0
  39. package/dist/api/templates/package.json.js +30 -27
  40. package/dist/api/templates/package.json.js.map +1 -0
  41. package/dist/api/universalize.js +1 -0
  42. package/dist/api/universalize.js.map +1 -0
  43. package/dist/api/version.js +1 -0
  44. package/dist/api/version.js.map +1 -0
  45. package/dist/api/wasi-worker-template.d.ts +1 -0
  46. package/dist/api/wasi-worker-template.js +53 -0
  47. package/dist/api/wasi-worker-template.js.map +1 -0
  48. package/dist/cli.js +1 -0
  49. package/dist/cli.js.map +1 -0
  50. package/dist/commands/artifacts.js +2 -2
  51. package/dist/commands/artifacts.js.map +1 -0
  52. package/dist/commands/build.js +1 -0
  53. package/dist/commands/build.js.map +1 -0
  54. package/dist/commands/create-npm-dirs.js +1 -0
  55. package/dist/commands/create-npm-dirs.js.map +1 -0
  56. package/dist/commands/help.js +2 -2
  57. package/dist/commands/help.js.map +1 -0
  58. package/dist/commands/new.js +2 -4
  59. package/dist/commands/new.js.map +1 -0
  60. package/dist/commands/pre-publish.js +1 -0
  61. package/dist/commands/pre-publish.js.map +1 -0
  62. package/dist/commands/rename.js +1 -0
  63. package/dist/commands/rename.js.map +1 -0
  64. package/dist/commands/universalize.js +1 -0
  65. package/dist/commands/universalize.js.map +1 -0
  66. package/dist/commands/version.js +1 -0
  67. package/dist/commands/version.js.map +1 -0
  68. package/dist/def/artifacts.js +2 -2
  69. package/dist/def/artifacts.js.map +1 -0
  70. package/dist/def/build.js +2 -2
  71. package/dist/def/build.js.map +1 -0
  72. package/dist/def/create-npm-dirs.js +2 -2
  73. package/dist/def/create-npm-dirs.js.map +1 -0
  74. package/dist/def/new.js +2 -2
  75. package/dist/def/new.js.map +1 -0
  76. package/dist/def/pre-publish.js +2 -2
  77. package/dist/def/pre-publish.js.map +1 -0
  78. package/dist/def/rename.js +2 -2
  79. package/dist/def/rename.js.map +1 -0
  80. package/dist/def/universalize.js +2 -2
  81. package/dist/def/universalize.js.map +1 -0
  82. package/dist/def/version.js +2 -2
  83. package/dist/def/version.js.map +1 -0
  84. package/dist/index.cjs +2921 -7847
  85. package/dist/index.js +1 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/utils/__tests__/target.spec.js +1 -0
  88. package/dist/utils/__tests__/target.spec.js.map +1 -0
  89. package/dist/utils/__tests__/typegen.spec.js +2 -1
  90. package/dist/utils/__tests__/typegen.spec.js.map +1 -0
  91. package/dist/utils/__tests__/version.spec.js +1 -0
  92. package/dist/utils/__tests__/version.spec.js.map +1 -0
  93. package/dist/utils/cargo.js +1 -0
  94. package/dist/utils/cargo.js.map +1 -0
  95. package/dist/utils/ci.js +1 -0
  96. package/dist/utils/ci.js.map +1 -0
  97. package/dist/utils/config.d.ts +9 -1
  98. package/dist/utils/config.js +1 -0
  99. package/dist/utils/config.js.map +1 -0
  100. package/dist/utils/index.js +1 -0
  101. package/dist/utils/index.js.map +1 -0
  102. package/dist/utils/log.js +1 -0
  103. package/dist/utils/log.js.map +1 -0
  104. package/dist/utils/metadata.js +1 -0
  105. package/dist/utils/metadata.js.map +1 -0
  106. package/dist/utils/misc.js +1 -0
  107. package/dist/utils/misc.js.map +1 -0
  108. package/dist/utils/target.d.ts +4 -3
  109. package/dist/utils/target.js +10 -0
  110. package/dist/utils/target.js.map +1 -0
  111. package/dist/utils/typegen.d.ts +4 -1
  112. package/dist/utils/typegen.js +21 -1
  113. package/dist/utils/typegen.js.map +1 -0
  114. package/dist/utils/version.js +3 -2
  115. package/dist/utils/version.js.map +1 -0
  116. package/package.json +47 -15
  117. package/src/api/artifacts.ts +7 -4
  118. package/src/api/build.ts +133 -25
  119. package/src/api/load-wasi-template.ts +65 -0
  120. package/src/api/new.ts +1 -4
  121. package/src/api/pre-publish.ts +8 -5
  122. package/src/api/templates/.gitignore.ts +1 -0
  123. package/src/api/templates/ci-template.ts +47 -35
  124. package/src/api/templates/ci.yml.ts +9 -6
  125. package/src/api/templates/js-binding.ts +52 -13
  126. package/src/api/templates/package.json.ts +31 -26
  127. package/src/api/wasi-worker-template.ts +52 -0
  128. package/src/commands/new.ts +1 -5
  129. package/src/utils/__tests__/__snapshots__/version.spec.ts.md +7 -7
  130. package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
  131. package/src/utils/__tests__/typegen.spec.ts +1 -1
  132. package/src/utils/config.ts +12 -1
  133. package/src/utils/target.ts +16 -7
  134. package/src/utils/typegen.ts +20 -1
  135. package/src/utils/version.ts +1 -1
package/src/api/build.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { spawn } from 'child_process'
2
- import { createHash } from 'crypto'
3
- import { tmpdir } from 'os'
4
- import { parse, join, resolve } from 'path'
1
+ import { spawn } from 'node:child_process'
2
+ import { createHash } from 'node:crypto'
3
+ import { createRequire } from 'node:module'
4
+ import { tmpdir } from 'node:os'
5
+ import { parse, join, resolve } from 'node:path'
5
6
 
6
7
  import * as colors from 'colorette'
7
8
 
@@ -20,6 +21,7 @@ import {
20
21
  parseMetadata,
21
22
  parseTriple,
22
23
  processTypeDef,
24
+ readFileAsync,
23
25
  readNapiConfig,
24
26
  Target,
25
27
  targetToEnvVar,
@@ -28,11 +30,14 @@ import {
28
30
  writeFileAsync,
29
31
  } from '../utils/index.js'
30
32
 
31
- import { createJsBinding } from './templates/index.js'
33
+ import { createWasiBinding } from './load-wasi-template.js'
34
+ import { createCjsBinding } from './templates/index.js'
35
+ import { WASI_WORKER_TEMPLATE } from './wasi-worker-template.js'
32
36
 
33
37
  const debug = debugFactory('build')
38
+ const require = createRequire(import.meta.url)
34
39
 
35
- type OutputKind = 'js' | 'dts' | 'node' | 'exe'
40
+ type OutputKind = 'js' | 'dts' | 'node' | 'exe' | 'wasm'
36
41
  type Output = {
37
42
  kind: OutputKind
38
43
  path: string
@@ -149,6 +154,7 @@ class Builder {
149
154
 
150
155
  const controller = new AbortController()
151
156
 
157
+ const watch = this.options.watch
152
158
  const buildTask = new Promise<void>((resolve, reject) => {
153
159
  const command =
154
160
  process.env.CARGO ?? (this.options.useCross ? 'cross' : 'cargo')
@@ -157,7 +163,7 @@ class Builder {
157
163
  ...process.env,
158
164
  ...this.envs,
159
165
  },
160
- stdio: 'inherit',
166
+ stdio: watch ? ['inherit', 'inherit', 'pipe'] : 'inherit',
161
167
  cwd: this.cwd,
162
168
  signal: controller.signal,
163
169
  })
@@ -178,6 +184,15 @@ class Builder {
178
184
  }),
179
185
  )
180
186
  })
187
+
188
+ // watch mode only, they are piped through stderr
189
+ buildProcess.stderr?.on('data', (data) => {
190
+ const output = data.toString()
191
+ console.error(output)
192
+ if (/Finished\s(dev|release)/.test(output)) {
193
+ this.postBuild().catch(() => {})
194
+ }
195
+ })
181
196
  })
182
197
 
183
198
  return {
@@ -207,6 +222,7 @@ class Builder {
207
222
  this.crateDir,
208
223
  '--',
209
224
  'cargo',
225
+ 'build',
210
226
  )
211
227
  set = true
212
228
  }
@@ -353,18 +369,35 @@ class Builder {
353
369
  const targetArch = this.target.arch === 'arm' ? 'armv7a' : 'aarch64'
354
370
  const targetPlatform =
355
371
  this.target.arch === 'arm' ? 'androideabi24' : 'android24'
372
+ const hostPlatform =
373
+ process.platform === 'darwin'
374
+ ? 'darwin'
375
+ : process.platform === 'win32'
376
+ ? 'windows'
377
+ : 'linux'
356
378
  Object.assign(this.envs, {
357
- CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER: `${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/${targetArch}-linux-android24-clang`,
358
- CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER: `${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/${targetArch}-linux-androideabi24-clang`,
359
- CC: `${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/${targetArch}-linux-${targetPlatform}-clang`,
360
- CXX: `${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/${targetArch}-linux-${targetPlatform}-clang++`,
361
- AR: `${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar`,
379
+ CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER: `${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/${hostPlatform}-x86_64/bin/${targetArch}-linux-android24-clang`,
380
+ CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER: `${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/${hostPlatform}-x86_64/bin/${targetArch}-linux-androideabi24-clang`,
381
+ CC: `${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/${hostPlatform}-x86_64/bin/${targetArch}-linux-${targetPlatform}-clang`,
382
+ CXX: `${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/${hostPlatform}-x86_64/bin/${targetArch}-linux-${targetPlatform}-clang++`,
383
+ AR: `${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/${hostPlatform}-x86_64/bin/llvm-ar`,
384
+ RANLIB: `${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/${hostPlatform}-x86_64/bin/llvm-ranlib`,
362
385
  ANDROID_NDK: ANDROID_NDK_LATEST_HOME,
363
- PATH: `${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${process.env.PATH}`,
386
+ PATH: `${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/${hostPlatform}-x86_64/bin:${process.env.PATH}`,
364
387
  })
365
388
  }
366
389
  // END LINKER
367
390
 
391
+ if (this.target.platform === 'wasi') {
392
+ const emnapi = join(
393
+ require.resolve('emnapi'),
394
+ '..',
395
+ 'lib',
396
+ 'wasm32-wasi-threads',
397
+ )
398
+ this.envs.EMNAPI_LINK_DIR = emnapi
399
+ }
400
+
368
401
  debug('Set envs: ')
369
402
  Object.entries(this.envs).forEach(([k, v]) => {
370
403
  debug(' %i', `${k}=${v}`)
@@ -452,8 +485,35 @@ class Builder {
452
485
 
453
486
  // only for cdylib
454
487
  if (this.cdyLibName) {
455
- await this.generateTypeDef()
456
- await this.writeJsBinding()
488
+ const idents = await this.generateTypeDef()
489
+ const intermediateWasiRegisterFile = this.envs.WASI_REGISTER_TMP_PATH
490
+ const wasiRegisterFunctions =
491
+ this.target.arch === 'wasm32'
492
+ ? JSON.parse(
493
+ await readFileAsync(intermediateWasiRegisterFile, 'utf8').catch(
494
+ (err) => {
495
+ console.warn(
496
+ `Read ${colors.yellowBright(
497
+ intermediateWasiRegisterFile,
498
+ )} failed, reason: ${err.message}`,
499
+ )
500
+ return `[]`
501
+ },
502
+ ),
503
+ )
504
+ : []
505
+ const jsOutput = await this.writeJsBinding(idents)
506
+ const wasmOutput = await this.writeWasiBinding(
507
+ wasiRegisterFunctions,
508
+ jsOutput?.path ?? 'index',
509
+ idents,
510
+ )
511
+ if (jsOutput) {
512
+ this.outputs.push(jsOutput)
513
+ }
514
+ if (wasmOutput) {
515
+ this.outputs.push(wasmOutput)
516
+ }
457
517
  }
458
518
 
459
519
  return this.outputs
@@ -499,6 +559,8 @@ class Builder {
499
559
  ? `lib${cdyLib}.dylib`
500
560
  : this.target.platform === 'win32'
501
561
  ? `${cdyLib}.dll`
562
+ : this.target.platform === 'wasi' || this.target.platform === 'wasm'
563
+ ? `${cdyLib}.wasm`
502
564
  : `lib${cdyLib}.so`
503
565
 
504
566
  let destName = this.config.binaryName
@@ -508,7 +570,11 @@ class Builder {
508
570
  if (this.options.platform) {
509
571
  destName += `.${this.target.platformArchABI}`
510
572
  }
511
- destName += '.node'
573
+ if (srcName.endsWith('.wasm')) {
574
+ destName += '.wasi-wasm32.wasm'
575
+ } else {
576
+ destName += '.node'
577
+ }
512
578
 
513
579
  return [srcName, destName]
514
580
  } else if (this.binName) {
@@ -523,12 +589,12 @@ class Builder {
523
589
 
524
590
  private async generateTypeDef() {
525
591
  if (!(await fileExists(this.envs.TYPE_DEF_TMP_PATH))) {
526
- return
592
+ return []
527
593
  }
528
594
 
529
595
  const dest = join(this.outputDir, this.options.dts ?? 'index.d.ts')
530
596
 
531
- const dts = await processTypeDef(
597
+ const { dts, exports } = await processTypeDef(
532
598
  this.envs.TYPE_DEF_TMP_PATH,
533
599
  !this.options.noDtsHeader
534
600
  ? this.options.dtsHeader ?? DEFAULT_TYPE_DEF_HEADER
@@ -547,27 +613,69 @@ class Builder {
547
613
  debug.error('Failed to write type def file')
548
614
  debug.error(e as Error)
549
615
  }
616
+
617
+ return exports
550
618
  }
551
619
 
552
- private async writeJsBinding() {
553
- if (!this.options.platform || this.options.noJsBinding) {
620
+ private async writeJsBinding(idents: string[]) {
621
+ if (
622
+ !this.options.platform ||
623
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
624
+ this.options.noJsBinding ||
625
+ idents.length === 0
626
+ ) {
554
627
  return
555
628
  }
556
629
 
557
- const dest = join(this.outputDir, this.options.jsBinding ?? 'index.js')
630
+ const name = parse(this.options.jsBinding ?? 'index.js').name
558
631
 
559
- const js = createJsBinding(this.config.binaryName, this.config.packageName)
632
+ const cjs = createCjsBinding(
633
+ this.config.binaryName,
634
+ this.config.packageName,
635
+ idents,
636
+ )
560
637
 
561
638
  try {
639
+ const dest = join(this.outputDir, `${name}.js`)
562
640
  debug('Writing js binding to:')
563
641
  debug(' %i', dest)
564
- await writeFileAsync(dest, js, 'utf-8')
565
- this.outputs.push({
642
+ await writeFileAsync(dest, cjs, 'utf-8')
643
+ return {
566
644
  kind: 'js',
567
645
  path: dest,
568
- })
646
+ } satisfies Output
569
647
  } catch (e) {
570
648
  throw new Error('Failed to write js binding file', { cause: e })
571
649
  }
572
650
  }
651
+
652
+ private async writeWasiBinding(
653
+ wasiRegisterFunctions: string[],
654
+ distFileName: string | undefined,
655
+ idents: string[],
656
+ ) {
657
+ if (distFileName && wasiRegisterFunctions.length) {
658
+ const { name, dir } = parse(distFileName)
659
+ const newPath = join(dir, `${name}.wasi.mjs`)
660
+ const workerPath = join(dir, 'wasi-worker.mjs')
661
+ const declareCodes = `const { ${idents.join(', ')} } = binding\n`
662
+ const exportsCode = `export {\n${idents
663
+ .map((ident) => ` ${ident}`)
664
+ .join(',\n')}\n}`
665
+ await writeFileAsync(
666
+ newPath,
667
+ createWasiBinding(this.config.binaryName, wasiRegisterFunctions) +
668
+ declareCodes +
669
+ exportsCode +
670
+ '\n',
671
+ 'utf8',
672
+ )
673
+ await writeFileAsync(workerPath, WASI_WORKER_TEMPLATE, 'utf8')
674
+ return {
675
+ kind: 'wasm',
676
+ path: newPath,
677
+ } satisfies Output
678
+ }
679
+ return null
680
+ }
573
681
  }
@@ -0,0 +1,65 @@
1
+ export const createWasiBinding = (
2
+ localName: string,
3
+ wasiRegisterFunctions: string[],
4
+ ) => `/* eslint-disable */
5
+ /* prettier-ignore */
6
+
7
+ /* auto-generated by NAPI-RS */
8
+
9
+ import * as __nodeFsPromises from 'node:fs/promises'
10
+ import * as __nodePath from 'node:path'
11
+ import { WASI as __nodeWASI } from 'node:wasi'
12
+ import { Worker } from 'node:worker_threads'
13
+ import * as __nodeURL from 'node:url'
14
+
15
+ import { instantiateNapiModule as __emnapiInstantiateNapiModule } from '@emnapi/core'
16
+ import { getDefaultContext as __emnapiGetDefaultContext } from '@emnapi/runtime'
17
+
18
+ const __wasi = new __nodeWASI({
19
+ env: process.env,
20
+ preopens: {
21
+ '/': __nodePath.join(__nodeURL.fileURLToPath(import.meta.url), '..'),
22
+ }
23
+ })
24
+
25
+ const __dirname = __nodePath.join(__nodeURL.fileURLToPath(import.meta.url), '..')
26
+
27
+ const __emnapiContext = __emnapiGetDefaultContext()
28
+
29
+ const __sharedMemory = new WebAssembly.Memory({
30
+ initial: 1024,
31
+ maximum: 10240,
32
+ shared: true,
33
+ })
34
+
35
+ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = await __emnapiInstantiateNapiModule(__nodeFsPromises.readFile(__nodePath.join(__dirname, '${localName}.wasi-wasm32.wasm')), {
36
+ context: __emnapiContext,
37
+ asyncWorkPoolSize: 4,
38
+ wasi: __wasi,
39
+ onCreateWorker() {
40
+ return new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
41
+ env: process.env,
42
+ execArgv: ['--experimental-wasi-unstable-preview1'],
43
+ })
44
+ },
45
+ overwriteImports(importObject) {
46
+ importObject.env = {
47
+ ...importObject.env,
48
+ ...importObject.napi,
49
+ ...importObject.emnapi,
50
+ memory: __sharedMemory,
51
+ }
52
+ },
53
+ beforeInit({ instance }) {
54
+ __napi_rs_initialize_modules(instance)
55
+ }
56
+ })
57
+
58
+ function __napi_rs_initialize_modules(__napiInstance) {
59
+ ${wasiRegisterFunctions
60
+ .map((name) => ` __napiInstance.exports['${name}']()`)
61
+ .join('\n')}
62
+ }
63
+
64
+ const binding = __napiModule.exports
65
+ `
package/src/api/new.ts CHANGED
@@ -157,10 +157,7 @@ function generateGithubWorkflow(options: NewOptions): Output | null {
157
157
 
158
158
  return {
159
159
  target: './.github/workflows/ci.yml',
160
- content: createGithubActionsCIYml(
161
- getBinaryName(options.name),
162
- options.targets,
163
- ),
160
+ content: createGithubActionsCIYml(options.targets),
164
161
  }
165
162
  }
166
163
 
@@ -129,11 +129,14 @@ export async function prePublish(userOptions: PrePublishOptions) {
129
129
  if (!options.dryRun) {
130
130
  await version(userOptions)
131
131
  await updatePackageJson(packageJsonPath, {
132
- optionalDependencies: targets.reduce((deps, target) => {
133
- deps[`${packageName}-${target.platformArchABI}`] = packageJson.version
134
-
135
- return deps
136
- }, {} as Record<string, string>),
132
+ optionalDependencies: targets.reduce(
133
+ (deps, target) => {
134
+ deps[`${packageName}-${target.platformArchABI}`] = packageJson.version
135
+
136
+ return deps
137
+ },
138
+ {} as Record<string, string>,
139
+ ),
137
140
  })
138
141
  }
139
142
 
@@ -195,4 +195,5 @@ Cargo.lock
195
195
  !.yarn/versions
196
196
 
197
197
  *.node
198
+ *.wasm
198
199
  `
@@ -5,6 +5,10 @@ env:
5
5
  DEBUG: 'napi:*'
6
6
  MACOSX_DEPLOYMENT_TARGET: '10.13'
7
7
 
8
+ permissions:
9
+ contents: write
10
+ id-token: write
11
+
8
12
  on:
9
13
  push:
10
14
  branches:
@@ -107,10 +111,10 @@ jobs:
107
111
  runs-on: \${{ matrix.settings.host }}
108
112
 
109
113
  steps:
110
- - uses: actions/checkout@v3
114
+ - uses: actions/checkout@v4
111
115
 
112
116
  - name: Setup node
113
- uses: actions/setup-node@v3
117
+ uses: actions/setup-node@v4
114
118
  if: \${{ !matrix.settings.docker }}
115
119
  with:
116
120
  node-version: 18
@@ -137,7 +141,7 @@ jobs:
137
141
  - uses: goto-bus-stop/setup-zig@v2
138
142
  if: \${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' }}
139
143
  with:
140
- version: 0.10.1
144
+ version: 0.11.0
141
145
 
142
146
  - name: Setup toolchain
143
147
  run: \${{ matrix.settings.setup }}
@@ -153,7 +157,7 @@ jobs:
153
157
  run: yarn install
154
158
 
155
159
  - name: Setup node x86
156
- uses: actions/setup-node@v3
160
+ uses: actions/setup-node@v4
157
161
  if: matrix.settings.target == 'i686-pc-windows-msvc'
158
162
  with:
159
163
  node-version: 18
@@ -184,34 +188,32 @@ jobs:
184
188
  runs-on: macos-12
185
189
  name: Build FreeBSD
186
190
  steps:
187
- - uses: actions/checkout@v3
191
+ - uses: actions/checkout@v4
188
192
  - name: Build
189
193
  id: build
190
- uses: vmactions/freebsd-vm@v0
194
+ uses: cross-platform-actions/action@v0.21.0
191
195
  env:
192
196
  DEBUG: 'napi:*'
193
- RUSTUP_HOME: /usr/local/rustup
194
- CARGO_HOME: /usr/local/cargo
195
197
  RUSTUP_IO_THREADS: 1
196
198
  with:
197
- envs: 'DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS'
198
- usesh: true
199
- mem: 3000
199
+ operating_system: freebsd
200
+ version: '13.2'
201
+ memory: 13G
202
+ cpu_count: 3
203
+ environment_variables: 'DEBUG RUSTUP_IO_THREADS'
204
+ shell: bash
200
205
  prepare: |
201
- pkg install -y -f curl node libnghttp2
202
- curl -qL https://www.npmjs.com/install.sh | sh
203
- npm install --location=global --ignore-scripts yarn
206
+ sudo pkg install -y -f curl node libnghttp2 npm
207
+ sudo npm install -g yarn --ignore-scripts
204
208
  curl https://sh.rustup.rs -sSf --output rustup.sh
205
- sh rustup.sh -y --profile minimal --default-toolchain beta
206
- export PATH="/usr/local/cargo/bin:$PATH"
209
+ sh rustup.sh -y --profile minimal --default-toolchain stable
210
+ source "$HOME/.cargo/env"
207
211
  echo "~~~~ rustc --version ~~~~"
208
212
  rustc --version
209
213
  echo "~~~~ node -v ~~~~"
210
214
  node -v
211
215
  echo "~~~~ yarn --version ~~~~"
212
216
  yarn --version
213
- run: |
214
- export PATH="/usr/local/cargo/bin:$PATH"
215
217
  pwd
216
218
  ls -lah
217
219
  whoami
@@ -244,13 +246,14 @@ jobs:
244
246
  - host: windows-latest
245
247
  target: 'x86_64-pc-windows-msvc'
246
248
  node: ['16', '18']
249
+ node: ['18', '20']
247
250
  runs-on: \${{ matrix.settings.host }}
248
251
 
249
252
  steps:
250
- - uses: actions/checkout@v3
253
+ - uses: actions/checkout@v4
251
254
 
252
255
  - name: Setup node
253
- uses: actions/setup-node@v3
256
+ uses: actions/setup-node@v4
254
257
  with:
255
258
  node-version: \${{ matrix.node }}
256
259
  cache: 'yarn'
@@ -279,13 +282,14 @@ jobs:
279
282
  fail-fast: false
280
283
  matrix:
281
284
  node: ['16', '18']
285
+ node: ['18', '20']
282
286
  runs-on: ubuntu-latest
283
287
 
284
288
  steps:
285
- - uses: actions/checkout@v3
289
+ - uses: actions/checkout@v4
286
290
 
287
291
  - name: Setup node
288
- uses: actions/setup-node@v3
292
+ uses: actions/setup-node@v4
289
293
  with:
290
294
  node-version: \${{ matrix.node }}
291
295
  cache: 'yarn'
@@ -314,13 +318,14 @@ jobs:
314
318
  fail-fast: false
315
319
  matrix:
316
320
  node: ['16', '18']
321
+ node: ['18', '20']
317
322
  runs-on: ubuntu-latest
318
323
 
319
324
  steps:
320
- - uses: actions/checkout@v3
325
+ - uses: actions/checkout@v4
321
326
 
322
327
  - name: Setup node
323
- uses: actions/setup-node@v3
328
+ uses: actions/setup-node@v4
324
329
  with:
325
330
  node-version: \${{ matrix.node }}
326
331
  cache: 'yarn'
@@ -351,10 +356,11 @@ jobs:
351
356
  fail-fast: false
352
357
  matrix:
353
358
  node: ['16', '18']
359
+ node: ['18', '20']
354
360
  runs-on: ubuntu-latest
355
361
 
356
362
  steps:
357
- - uses: actions/checkout@v3
363
+ - uses: actions/checkout@v4
358
364
 
359
365
  - name: Download artifacts
360
366
  uses: actions/download-artifact@v3
@@ -373,7 +379,7 @@ jobs:
373
379
  yarn install
374
380
 
375
381
  - name: Set up QEMU
376
- uses: docker/setup-qemu-action@v2
382
+ uses: docker/setup-qemu-action@v3
377
383
  with:
378
384
  platforms: arm64
379
385
  - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
@@ -392,11 +398,15 @@ jobs:
392
398
  name: Test bindings on aarch64-unknown-linux-musl - node@\${{ matrix.node }}
393
399
  needs:
394
400
  - build
401
+ strategy:
402
+ fail-fast: false
403
+ matrix:
404
+ node: ['16', '18']
395
405
 
396
406
  runs-on: ubuntu-latest
397
407
 
398
408
  steps:
399
- - uses: actions/checkout@v3
409
+ - uses: actions/checkout@v4
400
410
 
401
411
  - name: Download artifacts
402
412
  uses: actions/download-artifact@v3
@@ -415,7 +425,7 @@ jobs:
415
425
  yarn install
416
426
 
417
427
  - name: Set up QEMU
418
- uses: docker/setup-qemu-action@v2
428
+ uses: docker/setup-qemu-action@v3
419
429
  with:
420
430
  platforms: arm64
421
431
  - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
@@ -423,7 +433,7 @@ jobs:
423
433
  - name: Setup and run tests
424
434
  uses: addnab/docker-run-action@v3
425
435
  with:
426
- image: node:lts-alpine
436
+ image: node:\${{ matrix.node }}-alpine
427
437
  options: --platform linux/arm64 -v \${{ github.workspace }}:/build -w /build
428
438
  run: |
429
439
  set -e
@@ -437,10 +447,11 @@ jobs:
437
447
  fail-fast: false
438
448
  matrix:
439
449
  node: ['16', '18']
450
+ node: ['18', '20']
440
451
  runs-on: ubuntu-latest
441
452
 
442
453
  steps:
443
- - uses: actions/checkout@v3
454
+ - uses: actions/checkout@v4
444
455
 
445
456
  - name: Download artifacts
446
457
  uses: actions/download-artifact@v3
@@ -458,7 +469,7 @@ jobs:
458
469
  yarn install
459
470
 
460
471
  - name: Set up QEMU
461
- uses: docker/setup-qemu-action@v2
472
+ uses: docker/setup-qemu-action@v3
462
473
  with:
463
474
  platforms: arm
464
475
  - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
@@ -480,10 +491,10 @@ jobs:
480
491
  runs-on: macos-latest
481
492
 
482
493
  steps:
483
- - uses: actions/checkout@v3
494
+ - uses: actions/checkout@v4
484
495
 
485
496
  - name: Setup node
486
- uses: actions/setup-node@v3
497
+ uses: actions/setup-node@v4
487
498
  with:
488
499
  node-version: 18
489
500
  cache: yarn
@@ -525,10 +536,10 @@ jobs:
525
536
  - build-freebsd
526
537
 
527
538
  steps:
528
- - uses: actions/checkout@v3
539
+ - uses: actions/checkout@v4
529
540
 
530
541
  - name: Setup node
531
- uses: actions/setup-node@v3
542
+ uses: actions/setup-node@v4
532
543
  with:
533
544
  node-version: 18
534
545
  cache: 'yarn'
@@ -550,6 +561,7 @@ jobs:
550
561
 
551
562
  - name: Publish
552
563
  run: |
564
+ npm config set provenance true
553
565
  if git log -1 --pretty=%B | grep "^[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+$";
554
566
  then
555
567
  echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
@@ -17,10 +17,7 @@ const TEST_LINUX_AARCH64_MUSL = 'test-linux-aarch64-musl-binding'
17
17
  const TEST_LINUX_ARM_GNUEABIHF = 'test-linux-arm-gnueabihf-binding'
18
18
  const UNIVERSAL_MACOS = 'universal-macOS'
19
19
 
20
- export const createGithubActionsCIYml = (
21
- binaryName: string,
22
- targets: string[],
23
- ) => {
20
+ export const createGithubActionsCIYml = (targets: string[]) => {
24
21
  const allTargets = new Set(
25
22
  targets.flatMap((t) => {
26
23
  const platform = parseTriple(t)
@@ -63,10 +60,16 @@ export const createGithubActionsCIYml = (
63
60
  if (!enableWindowsX86 && !enableMacOSX86) {
64
61
  delete fullTemplate.jobs[TEST_MACOS_WINDOWS]
65
62
  } else {
66
- const filterTarget = enableWindowsX86 ? 'macos-latest' : 'windows-latest'
63
+ const filterTargets = new Set<string>()
64
+ if (enableWindowsX86) {
65
+ filterTargets.add('windows-latest')
66
+ }
67
+ if (enableMacOSUni || enableMacOSX86) {
68
+ filterTargets.add('macos-latest')
69
+ }
67
70
  fullTemplate.jobs[TEST_MACOS_WINDOWS].strategy.matrix.settings =
68
71
  fullTemplate.jobs[TEST_MACOS_WINDOWS].strategy.matrix.settings.filter(
69
- ({ host }: { host: string; target: string }) => host !== filterTarget,
72
+ ({ host }: { host: string; target: string }) => filterTargets.has(host),
70
73
  )
71
74
 
72
75
  requiredSteps.push(TEST_MACOS_WINDOWS)