Skip to content

Commit

Permalink
fix: workaround for this rust-lang/docs.rs#1823 (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
vectronic authored Sep 7, 2022
1 parent c865dfd commit 1ef4183
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
44 changes: 22 additions & 22 deletions bindings/bindings.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
// Auto-generated with deno_bindgen
import { CachePolicy, prepare } from "https://deno.land/x/[email protected]/plug.ts"
import { CachePolicy, prepare } from "https://deno.land/x/[email protected]/plug.ts";

function encode(v: string | Uint8Array): Uint8Array {
if (typeof v !== "string") return v
return new TextEncoder().encode(v)
if (typeof v !== "string") return v;
return new TextEncoder().encode(v);
}

function decode(v: Uint8Array): string {
return new TextDecoder().decode(v)
return new TextDecoder().decode(v);
}

function readPointer(v: any): Uint8Array {
const ptr = new Deno.UnsafePointerView(v as bigint)
const lengthBe = new Uint8Array(4)
const view = new DataView(lengthBe.buffer)
ptr.copyInto(lengthBe, 0)
const buf = new Uint8Array(view.getUint32(0))
ptr.copyInto(buf, 4)
return buf
const ptr = new Deno.UnsafePointerView(v as bigint);
const lengthBe = new Uint8Array(4);
const view = new DataView(lengthBe.buffer);
ptr.copyInto(lengthBe, 0);
const buf = new Uint8Array(view.getUint32(0));
ptr.copyInto(buf, 4);
return buf;
}

const url = new URL("../target/debug", import.meta.url)
let uri = url.toString()
if (!uri.endsWith("/")) uri += "/"
const url = new URL("../target/debug", import.meta.url);
let uri = url.toString();
if (!uri.endsWith("/")) uri += "/";

let darwin: string | { aarch64: string; x86_64: string } = uri
+ "libflowscripter_template_deno_rust_library.dylib"
let darwin: string | { aarch64: string; x86_64: string } = uri +
"libflowscripter_template_deno_rust_library.dylib";

if (url.protocol !== "file:") {
// Assume that remote assets follow naming scheme
// for each macOS artifact.
darwin = {
aarch64: uri + "libflowscripter_template_deno_rust_library_arm64.dylib",
x86_64: uri + "libflowscripter_template_deno_rust_library.dylib",
}
};
}

const opts = {
Expand All @@ -44,13 +44,13 @@ const opts = {
linux: uri + "libflowscripter_template_deno_rust_library.so",
},
policy: CachePolicy.NONE,
}
};
const _lib = await prepare(opts, {
add: { parameters: ["i32", "i32"], result: "i32", nonblocking: false },
})
});

export function add(a0: number, a1: number) {
let rawResult = _lib.symbols.add(a0, a1)
const result = rawResult
return result
let rawResult = _lib.symbols.add(a0, a1);
const result = rawResult;
return result;
}
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// empty build script to ensure OUT_DIR is set when deno_bindgen proc macro is run
// to work around this problem: https://github.com/rust-lang/docs.rs/issues/1823
fn main() {}

0 comments on commit 1ef4183

Please sign in to comment.