Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trying to force through updated deno_bindgen fixes #19 #49

Merged
merged 1 commit into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ exclude = [".github/", "bindings/"]
crate-type = ["cdylib","lib"]

[dependencies]
deno_bindgen = "0.5.1"
deno_bindgen = "0.6.0"
serde = { version = "1.0.144", features = ["derive"] }
flowscripter_template_rust_library = "1.1.4"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![coverage](https://codecov.io/gh/flowscripter/template-deno-rust-library/branch/main/graph/badge.svg?token=EMFT2938ZF)](https://codecov.io/gh/flowscripter/template-deno-rust-library)
[![rust dependencies](https://deps.rs/repo/github/flowscripter/template-deno-rust-library/status.svg)](https://deps.rs/crate/flowscripter_template_deno_rust_library)
[![deno dependencies](https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Fupdates%2Fhttps%2Fraw.githubusercontent.com%2Fflowscripter%2Ftemplate-deno-rust-library%2Fmain%2Fmod.ts)](https://github.com/flowscripter/template-deno-rust-library/blob/main/deps.ts)
[![rust doc](https://img.shields.io/docsrs/flowscripter_template_deno_rust_library)](https://docs.rs/flowscripter_template_deno_rust_library)
[![license: MIT](https://img.shields.io/github/license/flowscripter/template-deno-rust-library)](https://github.com/flowscripter/template-deno-rust-library/blob/main/LICENSE)

> Project template for a Rust library with Deno FFI bindings.
Expand Down Expand Up @@ -46,4 +47,3 @@ PNG image generated from `images/uml_diagram.mermaid`:
## License

MIT © Flowscripter

58 changes: 17 additions & 41 deletions bindings/bindings.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,32 @@
// 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 Deno.UnsafePointer);
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 += "/"

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 = {
name: "flowscripter_template_deno_rust_library",
urls: {
darwin,
windows: uri + "flowscripter_template_deno_rust_library.dll",
linux: uri + "libflowscripter_template_deno_rust_library.so",
},
url: (new URL("../target/debug", import.meta.url)).toString(),
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;
}