diff --git a/cli.ts b/cli.ts index f96ec91..bd2e294 100644 --- a/cli.ts +++ b/cli.ts @@ -7,8 +7,7 @@ const release = !!flags.release; const fetchPrefix = typeof flags.release == "string" ? flags.release - : "target/debug"; -const profile = release ? "release" : "debug"; + : "../target/" + (release ? "release" : "debug"); async function build() { const cmd = ["cargo", "build"]; diff --git a/codegen.ts b/codegen.ts index d7b07df..59845d3 100644 --- a/codegen.ts +++ b/codegen.ts @@ -113,7 +113,7 @@ function encode(v: string | Uint8Array): Uint8Array { } const opts = { name: "${name}", - url: "${fetchPrefix}" + url: (new URL("${fetchPrefix}", import.meta.url)).toString(), }; const _lib = await Plug.prepare(opts, { ${ diff --git a/example/bindings/bindings.ts b/example/bindings/bindings.ts index 5aaf9b6..7a6d5a1 100644 --- a/example/bindings/bindings.ts +++ b/example/bindings/bindings.ts @@ -6,14 +6,9 @@ function encode(v: string | Uint8Array): Uint8Array { } const opts = { name: "add", - url: "target/debug", + url: (new URL("../target/debug", import.meta.url)).toString(), } const _lib = await Plug.prepare(opts, { - test_str: { - parameters: ["buffer", "usize"], - result: "void", - nonblocking: false, - }, test_mixed_order: { parameters: ["i32", "buffer", "usize", "i32"], result: "i32", @@ -24,8 +19,14 @@ const _lib = await Plug.prepare(opts, { result: "void", nonblocking: false, }, + add: { parameters: ["i32", "i32"], result: "i32", nonblocking: false }, add2: { parameters: ["buffer", "usize"], result: "i32", nonblocking: false }, sleep: { parameters: ["u64"], result: "void", nonblocking: true }, + test_str: { + parameters: ["buffer", "usize"], + result: "void", + nonblocking: false, + }, test_mixed: { parameters: ["isize", "buffer", "usize"], result: "i32", @@ -41,14 +42,7 @@ const _lib = await Plug.prepare(opts, { result: "u8", nonblocking: false, }, - add: { parameters: ["i32", "i32"], result: "i32", nonblocking: false }, }) -export type MyStruct = { - arr: Array -} -export type OptionStruct = { - maybe: string | undefined | null -} export type PlainEnum = | { a: { @@ -70,9 +64,11 @@ export type Input = { a: number b: number } -export function test_str(a0: string) { - const a0_buf = encode(a0) - return _lib.symbols.test_str(a0_buf, a0_buf.byteLength) as null +export type OptionStruct = { + maybe: string | undefined | null +} +export type MyStruct = { + arr: Array } export function test_mixed_order(a0: number, a1: Input, a2: number) { const a1_buf = encode(JSON.stringify(a1)) @@ -87,6 +83,9 @@ export function test_mut_buf(a0: Uint8Array) { const a0_buf = encode(a0) return _lib.symbols.test_mut_buf(a0_buf, a0_buf.byteLength) as null } +export function add(a0: number, a1: number) { + return _lib.symbols.add(a0, a1) as number +} export function add2(a0: Input) { const a0_buf = encode(JSON.stringify(a0)) return _lib.symbols.add2(a0_buf, a0_buf.byteLength) as number @@ -94,6 +93,10 @@ export function add2(a0: Input) { export function sleep(a0: number) { return _lib.symbols.sleep(a0) as Promise } +export function test_str(a0: string) { + const a0_buf = encode(a0) + return _lib.symbols.test_str(a0_buf, a0_buf.byteLength) as null +} export function test_mixed(a0: number, a1: Input) { const a1_buf = encode(JSON.stringify(a1)) return _lib.symbols.test_mixed(a0, a1_buf, a1_buf.byteLength) as number @@ -106,6 +109,3 @@ export function test_serde(a0: MyStruct) { const a0_buf = encode(JSON.stringify(a0)) return _lib.symbols.test_serde(a0_buf, a0_buf.byteLength) as number } -export function add(a0: number, a1: number) { - return _lib.symbols.add(a0, a1) as number -} diff --git a/example/src/lib.rs b/example/src/lib.rs index e42089b..cb5a105 100644 --- a/example/src/lib.rs +++ b/example/src/lib.rs @@ -50,7 +50,6 @@ fn test_serde(s: MyStruct) -> u8 { } // Typescript codegen tests - #[deno_bindgen] struct OptionStruct { maybe: Option,