Skip to content

Commit

Permalink
use import.meta for loading lib relative to module (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy authored Oct 30, 2021
1 parent 2f195b4 commit 14b0169
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
3 changes: 1 addition & 2 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
2 changes: 1 addition & 1 deletion codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
${
Expand Down
38 changes: 19 additions & 19 deletions example/bindings/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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<string>
}
export type OptionStruct = {
maybe: string | undefined | null
}
export type PlainEnum =
| {
a: {
Expand All @@ -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<string>
}
export function test_mixed_order(a0: number, a1: Input, a2: number) {
const a1_buf = encode(JSON.stringify(a1))
Expand All @@ -87,13 +83,20 @@ 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
}
export function sleep(a0: number) {
return _lib.symbols.sleep(a0) as Promise<null>
}
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
Expand All @@ -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
}
1 change: 0 additions & 1 deletion example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ fn test_serde(s: MyStruct) -> u8 {
}

// Typescript codegen tests

#[deno_bindgen]
struct OptionStruct {
maybe: Option<String>,
Expand Down

0 comments on commit 14b0169

Please sign in to comment.