33 * Builds a Javy plugin .plugin.wasm from extension crates.
44 * Used by examples that need a pre-built plugin (e.g. lib_alpha).
55 */
6- import { existsSync , mkdirSync , mkdtempSync , rmSync } from 'node:fs'
6+ import { copyFileSync , existsSync , mkdirSync , mkdtempSync , rmSync } from 'node:fs'
77import { tmpdir } from 'node:os'
88import path , { dirname , join , resolve } from 'node:path'
99import { fileURLToPath } from 'node:url'
@@ -27,17 +27,23 @@ async function main() {
2727 const argv = process . argv . slice ( 2 )
2828 const creExports : string [ ] = [ ]
2929 let outputPath : string | null = null
30+ let lockfilePath : string | null = null
3031 for ( let i = 0 ; i < argv . length ; i ++ ) {
3132 if ( argv [ i ] === '--cre-exports' && i + 1 < argv . length ) {
3233 creExports . push ( argv [ i + 1 ] )
3334 i ++
3435 } else if ( argv [ i ] === '-o' && i + 1 < argv . length ) {
3536 outputPath = argv [ i + 1 ]
3637 i ++
38+ } else if ( argv [ i ] === '--lockfile' && i + 1 < argv . length ) {
39+ lockfilePath = resolve ( argv [ i + 1 ] )
40+ i ++
3741 }
3842 }
3943 if ( creExports . length === 0 || outputPath === null ) {
40- console . error ( 'Usage: build-plugin.ts --cre-exports <path>... -o <output.plugin.wasm>' )
44+ console . error (
45+ 'Usage: build-plugin.ts --cre-exports <path>... -o <output.plugin.wasm> [--lockfile <path>]' ,
46+ )
4147 process . exit ( 1 )
4248 }
4349
@@ -47,8 +53,14 @@ async function main() {
4753 const extensions = resolveExtensions ( creExports )
4854 generateHostCrate ( tmpDir , pluginDir , extensions )
4955
56+ const cargoArgs = [ 'build' , '--target' , 'wasm32-wasip1' , '--release' ]
57+ if ( lockfilePath ) {
58+ copyFileSync ( lockfilePath , join ( tmpDir , 'Cargo.lock' ) )
59+ cargoArgs . splice ( 1 , 0 , '--locked' )
60+ }
61+
5062 const [ , javyPath ] = await Promise . all ( [
51- run ( 'cargo' , [ 'build' , '--target' , 'wasm32-wasip1' , '--release' ] , tmpDir , {
63+ run ( 'cargo' , cargoArgs , tmpDir , {
5264 CARGO_TARGET_DIR : sharedTargetDir ,
5365 } ) ,
5466 ensureJavy ( { version : JAVY_VERSION } ) ,
0 commit comments