GithubHelp home page GithubHelp logo

denoland / deno_bindgen Goto Github PK

View Code? Open in Web Editor NEW
262.0 20.0 33.0 782 KB

Write high-level Deno FFI libraries in Rust.

License: MIT License

Rust 79.89% TypeScript 18.58% Makefile 0.64% JavaScript 0.63% Shell 0.27%
rust deno ffi bindgen

deno_bindgen's Introduction

deno_bindgen

ci crates docs

This tool aims to simplify glue code generation for Deno FFI libraries written in Rust.

Install

Install the command-line via cargo:

cargo install deno_bindgen_cli

Usage

use deno_bindgen::deno_bindgen;

// Export `add` function to JavaScript.
#[deno_bindgen]
fn add(a: u32, b: u32) -> u32 {
    a + b
}

Use the exported functions directly in ESM with TypeScript typings

import { add } from "./bindings/mod.ts";

add(1, 2);

Design

The tool is designed to make it very easy to write high performance FFI bindings. A lot of the things have been redesigned in 0.10 to prevent perf footguns.

TypeScript types are generated and supported OOTB.

All class handles support disposing memory via the Explicit Resource Management API (using).

#[deno_bindgen]
pub struct Foo;

#[deno_bindgen]
impl Foo {
  #[constructor]
  pub fn new() -> Self {
    Self
  }

  pub fn bar(&self) {
    // ...
  }
}
import { Foo } from "@ffi/example";

{
  using foo = new Foo();
  foo.bar();
  // foo is disposed here...
}

High performance. Codegen tries its best to take the fastest possible path for all bindings as-if they were written by hand to properly leverage the power of the Deno FFI JIT calls.

> make bench
cpu: Apple M1
runtime: deno 1.38.0 (aarch64-apple-darwin)

file:///Users/divy/gh/deno_bindgen/example/bench.js
benchmark      time (avg)        iter/s             (min … max)       p75       p99      p995
--------------------------------------------------------------- -----------------------------
add             6.88 ns/iter 145,297,626.6    (6.78 ns … 13.33 ns)   6.81 ns   8.22 ns    9.4 ns
bytelen         8.05 ns/iter 124,278,976.3     (7.81 ns … 18.1 ns)   8.09 ns  10.39 ns  11.64 ns

Publishing

By default, deno_bindgen generates bindings for local development. To publish a cross-platform binding, you can use the --lazy-init flag, this gives you full control on how you want to host pre-built shared libraries and pull them in at runtime.

deno_bindgen --release --lazy-init
import { add, load } from "./example/mod.ts";
import { cache } from "https://deno.land/x/cache/mod.ts";

// Download the shared library from a CDN
const file = await cache("https://example.com/example.so");
load(file.path);

add(1, 2);

deno_bindgen's People

Contributors

crowlkats avatar dsherret avatar grian32 avatar hashrock avatar jhechtf avatar kayac-chang avatar kt3k avatar lino-levan avatar littledivy avatar load1n9 avatar natoandro avatar sigmasd avatar skanehira avatar sno2 avatar tsar-boomba avatar ultirequiem avatar usrtax avatar vectronic avatar zifeo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deno_bindgen's Issues

Support `Vec<T: Serialize>` return types

Currently, one has to wrap it around another struct and return it. The macro should parse Vec<T> something like this:

use deno_bindgen::deno_bindgen;

#[deno_bindgen]
pub struct UsbDevice {
  // ...
}

#[deno_bindgen(non_blocking)]
pub fn devices() -> Vec<UsbDevice> {
  let ctx = crate::Context::init().unwrap();
  let devices = ctx.devices().unwrap();
  devices
}

Workaround:

#[deno_bindgen]
pub struct Devices {
  devices: Vec<UsbDevice>,
}

#[deno_bindgen(non_blocking)]
pub fn devices() -> Devices {
  let ctx = crate::Context::init().unwrap();
  let devices = ctx.devices().unwrap();
  Devices { devices }
}

Publishing a library

First pass, authors will be able to pass the target triplet and the corresponding download URL (maybe using a JSON file). The CLI will generate code to download and cache the library.

After that is implemented, authors should also be able to provide a git repository URL or source (zip/tar/...) or crates.io publish and deno_bindgen will generate relevant glue code to build the crate from source using the available Rust toolchain on the user's machine.

deno_bindgen does not work properly on Windows.

Summary

deno_bindgen does not work properly on Windows.

Details

When I install latest deno_bindgen and run deno_bindgen in Windows(on GitHub Actions), the path of dll is incorrect.
I think correct path is file:///D:/a/deno-clippy/deno-clippy/bindings/../target/debug/deno_clippy.dll

Check file:///D:/a/deno-clippy/deno-clippy/mod_test.ts
Check file:///D:/a/deno-clippy/deno-clippy/platform/mod_test.ts
Download file:///D:/a/deno-clippy/deno-clippy/bindings/..argetdebug/deno_clippy.dll
Uncaught error from ./mod_test.ts FAILED
running 2 tests from ./platform/mod_test.ts
read write text ... ok (1s)
error: Test failed
read write image ... ok (982ms)

 ERRORS 

./mod_test.ts (uncaught error)
error: (in promise) CacheError: D:\a\deno-clippy\deno-clippy\bindings\..argetdebug\deno_clippy.dll is not valid.
    throw new CacheError(`${path} is not valid.`);

CI result.

https://github.com/skanehira/deno-clippy/runs/8170198161?check_suite_focus=true#step:9:99

CI definition.

https://github.com/skanehira/deno-clippy/blob/fbbb1908a4220ec4b7c5e7b672d7d90ad71e4ea0/.github/workflows/ci.yaml#L64-L72

Prevent returning mutable slices

There is not such thing like returning mutable slices in Deno FFI at the time. Since the slice gets copied into JS, it can lead to undesirable behavior. deno_bindgen should error in this case.

Empty bindings.json file breaks build

  • When deno_bindgen errors out it creates a empty bindings.json which should be fixed
  • Marko should check before if the file is a valid json if not recreate it

don't cache development builds

I have to rm -rf ~/Library/Caches/deno/plug/ after every rebuild to keep the cache up to date. We should just disable caching local plugins.

implement `impl` as classes

Doable with Box<T>. Reference/Mutable reference for methods and deallocate box when consumed/finalization

pub struct NonSerializable {
  inner: i32,
}

#[deno_bindgen]
impl NonSerializable {
  pub fn add(&mut self, a: i32) {
    self.inner += a;
  }
  
  #[deno_bindgen(constructor)]
  pub fn new() -> Self {
    Self { inner: 0 }
  }
}
const ptr = new NonSerializable();
ptr.add(10)

Bug: Runtime type error when return String in non_blocking mode

Problem

Rust Source Code

#[deno_bindgen(non_blocking)]
fn say_hello() -> String {
    String::from("Hello, kirby")
}

Deno Source Code

import { say_hello } from "./bindings/bindings.ts";
say_hello();

Throw Error below 😢

error: TS2345 [ERROR]: Argument of type 'Promise<Uint8Array>' is not assignable to parameter of type 'Uint8Array'.
  Type 'Promise<Uint8Array>' is missing the following properties from type 'Uint8Array': BYTES_PER_ELEMENT, buffer, byteLength, byteOffset, and 28 more.
  return decode(result)
                ~~~~~~

TS2773 [ERROR]:     Did you forget to use 'await'?
      return decode(result)
                    ~~~~~~

Possible Solution

take a look #77

Bug: Program crash after deno_bindgen rebuild

Environment:

OS:

MacOS Monterey version 12.4

Hardware:

Model Name: MacBook Pro
Chip: Apple M1
Memory: 16 GB

Steps To Reproduce

  1. first run deno_bindgen to build first ffi
  2. run deno run --allow-all --unstable main.ts, we can get Hello, world print out
  3. update src/lib.rs source code, like change Hello, world to Hello, kirby
  4. run deno_bindgen again
  5. run deno run --allow-all --unstable main.ts will crash without any error
$ deno run --allow-all --unstable main.ts                                                                                                                
[1]    11128 killed     deno run --allow-all --unstable main.ts

Link to code example:
https://github.com/kayac-chang/test-deno-bindgen

Problem

I think because of this line,
but I don't know the reason why need to use system cache,
because there's no useful document to point out intention.

Temporary Solution

Currently, I fork plug
and add the following code to skip the cache,
this will solve the issue temporarily.

  ...

  if (options.policy === CachePolicy.NONE) {
    return new URL(url).pathname;
  }

  const file = await plug.cache(url, policy);

  return file.path;
}

feat: no auto initialization

Hello, it would be nice if instead of eagerly loading the binary library synchronously deno_bindgen would export a function called something like load which would be a function that does Deno.dlopen and attaches all of the helper functions to an object that is returned. Therefore, people could instantiate multiple instances of their library in cases where there is different state that they want instead of having to write multiple awkward dynamic imports. Also, it would help when enabling testing and benchmarking in sub libraries that use deno bindgen to not always need to wait for the synchronous Deno.dlopen call to finish at the start of each run when it may not be needed.

Encode as cstring instead of ptr + len

Currently encode encodes as u8 array and then gives the ptr and array len.

I suggest to use cstrings instead so encoding as an u8 array that ends with a null byte.

The why is the current use method requires Deno.UnsafePointer.of(), which requires unbounded --allow-ffi (similar issue denoland/deno#15511)

With the second method, there is no issue, and I can use --allow-ffi=lib

Unable to run deno_bindgen

I'm unable to run deno_bindgen always throwing following error

error: Uncaught (in promise) NotFound: No such file or directory (os error 2), remove 'bindings.json'
await build().catch((_) => Deno.removeSync("bindings.json"));
                                ^
    at Object.opSync (deno:core/01_core.js:170:12)
    at Object.removeSync (deno:runtime/js/30_fs.js:150:10)
    at https://deno.land/x/[email protected]/cli.ts:56:33
    at async https://deno.land/x/[email protected]/cli.ts:56:1

To be sure that's not my mistake I've even tried running deno_bindgen command in example directory, same thing.

OS: Manjaro 21.3.3
deno --version:

deno 1.23.4 (release, x86_64-unknown-linux-gnu)
v8 10.4.132.8
typescript 4.7.4

Conditional field attributes do not work

use deno_bindgen::deno_bindgen;

#[deno_bindgen]
pub struct UsbDevice {
  // Not supposed to be serialized or included in typings.
  #[cfg(not(feature = "deno_ffi"))]
  non_serializable_handle: Device,
}

Output:

type UsbDevice = {
  non_serializable_handle: Device, // <-- should not be included
};

Expected output:

type UsbDevice = {};

feat: Support for C and perhaps other languages too

It would be nice to have support for more languages than just rust, but I understand if that is out of the scope of the project at the moment. Anyways I propose splitting up codegen into a different crate and removing serde instead opting for encoding and decoding repr(C) objects in js directly using the new UnsafePointerView (wrote a small prototype in ts to prove that this works which it does).

This approach would let us continue using the macro for rust, and possibly reusing the codegen for analyzing other languages such as C header files while being more intuitive and most likely performant.

error: custom attribute panicked

full stack trace:

error: custom attribute panicked
 --> src/lib.rs:3:1
  |
3 | #[deno_bindgen]
  | ^^^^^^^^^^^^^^^
  |
  = help: message: called `Result::unwrap()` on an `Err` value: Error("EOF while parsing a value", line: 1, column: 0)

repro code:

#[deno_bindgen::deno_bindgen]
fn greet() -> i32 {
    return 42;
}

Fixed by deleting bindings.json in project root

Generate jsdoc from Rust doc attributes

/// I am a happy data structure
/// :D
#[deno_bindgen]
struct Happy { 
  /// This field is a mess for
  /// some reason.
  inner: Vec<Vec<Vec<String>>>,
}

transforms to:

/**
* I am a happy data structure
* :D
**/
export type Happy = {
  /**
  * This field is a mess for
  * some reason.
  **/
  inner: Array<Array<Array<string>>>;
};

feat: Have release builds always generate a new bindings.ts file

As the title states, it would be nice if on a release the bindings.ts file was updated, especially in the case where a value was passed as the --release argument. Otherwise the committed version is going to be used, and if you are pointing to a github release or something then there is going to be a new URL that should be used for the accompanying files.

Use environment variable OUT_DIR for the location of bindings.json

I have a docs.rs build issue when the deno_bindgen attribute is encountered:

https://docs.rs/crate/flowscripter_template_deno_rust_library/1.0.6/builds/556217

From what I can tell this is because deno_bindgen is writing (always) the bindings.json file to the root of the project and this will fail on docs.rs because of readonly permissions:

https://docs.rs/about/builds#read-only-directories

The proposed fix for this is to write build output files into the cargo output directory defined in the environment variable OUT_DIR.

Mark functions non-blocking with macro attributes

#[deno_bindgen(nonblocking)]
fn sleep(ms: usize) { ... }

Will mark the symbol as nonblocking when opening library with Deno.dlopen. Function will be exported as an async function from the bindings.

Support reserved keyword escaping

Rust allows reserved keywords to be escaped in struct member naming. deno_bindgen does not handle this at present.

Example: Try to create bindings for the following struct:

#[deno_bindgen]
struct Payload {
    r#type: String,
    value: Vec<u32>,
}

The type field of the struct has been escaped since it name clashes type keyword. The expected TypeScript type for this would be

interface Payload {
  type: string;
  value: Array<number>;
}

However, the actual result is:

interface Payload {
  r#type: string;
  value: Array<number>;
}

memery leak for deno_bindgen

deno 1.26.0 (release, x86_64-unknown-linux-gnu)
v8 10.7.193.3
typescript 4.8.3

code is there https://github.com/usrtax/deno_bindgen_test

use deno_bindgen::deno_bindgen;

#[deno_bindgen]
fn add3() -> &'static [u8] {
    &[
        1, 2, 3, 4, 5, 6, 7, 9, 0, 1, 2, 3, 4, 5, 6, 7, 9, 0, 1, 2, 3, 4, 5, 6, 7, 9, 0, 1, 2, 3,
    ]
}

test code https://github.com/usrtax/deno_bindgen_test/blob/main/lib/test.js

#!/usr/bin/env -S node --es-module-specifier-resolution=node --trace-uncaught --expose-gc --unhandled-rejections=strict
var main, n, sleep;

import {
  add3
} from '../bindings/bindings.ts';

sleep = () => {
  return new Promise((resolve) => {
    return setTimeout(resolve, 10);
  });
};

n = 0;

while (true) {
  main();
  if (n++ % 10000 === 0) {
    gc();
    await sleep();
    console.log(n, Deno.memoryUsage());
  }
}

run as begin
image

run 3mintues RES 1040M
image

run 10minutes RES 2177M

run 1hour RES 14.9G
image

Deno.memoryUsage doesn't seem to be very accurate, pay more attention to the memory usage in top

Add // @ts-ignore above UnsafePointerView

Hi, I wanted to know if it is possible to automatically add // @ts-ignore above UnsafePointerView to prevent VSCode and other editors to show: Property 'UnsafePointerView' does not exist on type 'typeof Deno'.deno-ts(2339):
Like this:

// @ts-ignore
  const ptr = new Deno.UnsafePointerView(v as Deno.UnsafePointer)

At least until the API can be stabilized.
By the way, really nice job. Already tested winit.
Thanks.

feat: remove generated code dependencies

The generated glue code should be able to be ran without requiring the internet the first time and there are also security vulnerabilities that can spawn from relying on third-party code. The external import for deno.land/x/plug makes the calling of the FFI stuff does make it easier to cache in our code. However, I don't really think we should depend on external code sources, especially deno.land/x. If this project is under the same guise as the standard library's code manual (which I think it should), then it would violate the first STD-specific rule:

Do not depend on external code.

https://deno.land/std/ is intended to be baseline functionality that all Deno programs can rely on. We want to guarantee to users that this code does not include potentially unreviewed third party code.

The fact of the matter is that it would need to be ensured with every version bump that all of the dependencies in the tree from /x/plug would need to be reviewed after every version for the dependency to remain safe. Every single person that uses this bindgen helper would be vulnerable if someone accidentally bumped the plug version without realizing there was a bad egg three levels down in the dependency tree that did some malicious stuff. Or, if x/plug or a sub dependency was using an untagged dependency in which case code that had been previously reviewed could have changed so no one would have ever known there was even a vulnerability.

Now, I don't really have a good solution to this, though, as the caching implemented by /x/cache and /x/plug is really good. The only problem is that it's external code. Therefore, I'd just like to open this issue to open it for discussion and put out the idea of this being a possible issue along the line that we might need to fix.

Move the Rust/Deno type mapping into the Rust macro

Currently, the deno_bindgen macro only records the exported function signatures and changes them to extern "C", with the type mapping to Deno's FFI types happening on cli.ts. This works fine for the time being, while all allowed types are numbers, but it wouldn't really work once #2 is implemented, since you would want a user to be able to use the &str type rather than having to work unsafely with *const c_char.

Moving the Rust/Deno type mapping to the macro would also make it possible to show "type not supported" errors highlighted in context, as per usual with rustc.

JSON.encode doesn't support Map

Rust's HashMap type gets translated to the Map type in typescript. It is possible to use a struct containing a map as a parameter. However the generated glue code incorrectly uses JSON.stringify to convert the parameter into a string. This doesn't work on the Map member as the contained values are ignored. The code thus outputs an empty objects which doesn't contain the values of the Map.

Rust code:

use deno_bindgen::deno_bindgen;
use std::collections::HashMap;

#[deno_bindgen]
struct MyStruct {
    my_map: HashMap<String, String>,
}

#[deno_bindgen]
fn my_fn(my_struct: MyStruct) {
    println!("{:?}", my_struct.my_map);
}

Generated binding for struct:

export type MyStruct = {
  my_map: Map<string, string>
}

Faulty binding using JSON.stringify:

export function my_fn(a0: MyStruct) {
  const a0_buf = encode(JSON.stringify(a0))
  let rawResult = _lib.symbols.my_fn(a0_buf, a0_buf.byteLength)
  const result = rawResult
  return result
}

As such the follow code will not output {a:'b'} but instead {}.

import { my_fn } from "./bindings/bindings.ts";

my_fn({ my_map: new Map([["a", "b"]]) });

This could be mitigated by using Record<T, U> instead of Map<T, U> as it refers to a plain JS-Object which can be properly converted by JSON.stringify.

why &[u8] use TextEncoder ? can't pass binary ...

use deno_bindgen::deno_bindgen;
use image::{load_from_memory, EncodableLayout};
use webp::Encoder;

#[deno_bindgen]
pub struct Img {
    bin: Option<Vec<u8>>,
}

#[deno_bindgen]
pub fn toWebp(img: &[u8], quality: u8) -> Img {
    if let Ok(img) = load_from_memory(img) {
        let encoder = Encoder::from_image(&img).unwrap();
        let encoded_webp = encoder.encode((quality as f32) / 100.0);
        return Img {
            bin: Some(encoded_webp.as_bytes().into()),
        };
    }

    Img { bin: None }
}
export function toWebp(a0: Uint8Array, a1: number) {
  const a0_buf = encode(a0)

Accessing structs from C to Deno

Hello, I know this is a rust based codegen but I hope it's ok to ask this. What could be the best way to access structs that contains strings in Deno from C? Is it advisable just to stringify the object in C so that I can do new Deno.UnsafePointerView(ptr).getCString() in Deno?

Example

typedef struct { char name; int age; } SampleObject;

async codegen type decls missing & no promise resolving of number/void types

Using deno_bindgen==0.7.0 I'm facing some issues with non_blocking / async codegen.

Given the following defs:

#[deno_bindgen(non_blocking)]
pub fn test_str_async() -> String {
    "test".to_string()
}

#[deno_bindgen(non_blocking)]
pub fn test_u32_async() -> u32 {
    1
}

#[deno_bindgen(non_blocking)]
pub fn test_void_async() {}

Generates the following TS:

...

const _lib = await prepare(opts, {
  test_str_async: { parameters: [], result: "pointer", nonblocking: true },
  test_u32_async: { parameters: [], result: "u32", nonblocking: true },
  test_void_async: { parameters: [], result: "void", nonblocking: true },
})

export function test_str_async() {
  let rawResult = _lib.symbols.test_str_async()
  const result = rawResult.then(readPointer)
  return result.then(decode)
}
export function test_u32_async() {
  let rawResult = _lib.symbols.test_u32_async()
  const result = rawResult
  return result
}
export function test_void_async() {
  let rawResult = _lib.symbols.test_void_async()
  const result = rawResult
  return result
}

Some issues:

  • Function type declarations are missing and inferred as any, for test_str_async I would expect a return type of Promise<string> or the function to be marked as async function ...
  • test_u32_async & test_void_async are not resolving the promise result like test_str_async - there's no indication in the function declaration it returns a promise

support `&str` as a return type

&str is already accepted as a parameter type, but it would be nice 🌠 to be able to return a &str. (Thanks to Andreu and divy for help in the discord.)

Here's an example of a &str param from the 0.2 release announcement:

#[deno_bindgen]
pub fn say_hello(message: &str)  {
    println!("{}", message);
}

If it's changed to return a &str instead of printing it...

#[deno_bindgen]
pub fn say_hello(message: &str) -> &str {
    format!("{}", message)
}

The result is:

error: custom attribute panicked  
 --> src/lib.rs:5:1               
  |                               
5 | #[deno_bindgen]               
  | ^^^^^^^^^^^^^^^               
  |                               
  = help: message: not implemented

That's from the current version of deno_bindgen, 0.5.

This would be a really nice feature to have and would allow easily passing text across the FFI boundary.

Doesn't work with Deno v1.25.0

deno_bindgen doesn't work cause denoland/deno#15518

log
$ deno test -A --unstable
Check file:///Users/skanehira/dev/github.com/denoland/deno_bindgen/example/bindings_test.ts
error: TS2345 [ERROR]: Argument of type 'Uint8Array' is not assignable to parameter of type 'ToNativeType<"usize" | "pointer">'.
  let rawResult = _lib.symbols.add2(a0_buf, a0_buf.byteLength)
                                    ~~~~~~
    at file:///Users/skanehira/dev/github.com/denoland/deno_bindgen/example/bindings/bindings.ts:173:37

TS2345 [ERROR]: Argument of type 'Uint8Array' is not assignable to parameter of type 'ToNativeType<"usize" | "pointer">'.
  let rawResult = _lib.symbols.test_buf(a0_buf, a0_buf.byteLength)
                                        ~~~~~~
    at file:///Users/skanehira/dev/github.com/denoland/deno_bindgen/example/bindings/bindings.ts:184:41

TS2345 [ERROR]: Argument of type 'Uint8Array' is not assignable to parameter of type 'ToNativeType<"usize" | "pointer">'.
  let rawResult = _lib.symbols.test_buffer_return(a0_buf, a0_buf.byteLength)
                                                  ~~~~~~
    at file:///Users/skanehira/dev/github.com/denoland/deno_bindgen/example/bindings/bindings.ts:190:51

TS2345 [ERROR]: Argument of type 'Uint8Array' is not assignable to parameter of type 'ToNativeType<"usize" | "pointer">'.
    a0_buf,
    ~~~~~~
    at file:///Users/skanehira/dev/github.com/denoland/deno_bindgen/example/bindings/bindings.ts:197:5

TS2345 [ERROR]: Argument of type 'Uint8Array' is not assignable to parameter of type 'ToNativeType<"usize" | "pointer">'.
  let rawResult = _lib.symbols.test_lifetime(a0_buf, a0_buf.byteLength)
                                             ~~~~~~
    at file:///Users/skanehira/dev/github.com/denoland/deno_bindgen/example/bindings/bindings.ts:210:46

TS2345 [ERROR]: Argument of type 'Uint8Array' is not assignable to parameter of type 'ToNativeType<"usize" | "isize" | "pointer">'.
  let rawResult = _lib.symbols.test_mixed(a0, a1_buf, a1_buf.byteLength)
                                              ~~~~~~
    at file:///Users/skanehira/dev/github.com/denoland/deno_bindgen/example/bindings/bindings.ts:226:47

TS2345 [ERROR]: Argument of type 'Uint8Array' is not assignable to parameter of type 'ToNativeType<"i32" | "usize" | "pointer">'.
    a1_buf,
    ~~~~~~
    at file:///Users/skanehira/dev/github.com/denoland/deno_bindgen/example/bindings/bindings.ts:234:5

TS2345 [ERROR]: Argument of type 'Uint8Array' is not assignable to parameter of type 'ToNativeType<"usize" | "pointer">'.
  let rawResult = _lib.symbols.test_mut_buf(a0_buf, a0_buf.byteLength)
                                            ~~~~~~
    at file:///Users/skanehira/dev/github.com/denoland/deno_bindgen/example/bindings/bindings.ts:243:45

TS2345 [ERROR]: Argument of type 'Uint8Array' is not assignable to parameter of type 'ToNativeType<"usize" | "pointer">'.
  let rawResult = _lib.symbols.test_serde(a0_buf, a0_buf.byteLength)
                                          ~~~~~~
    at file:///Users/skanehira/dev/github.com/denoland/deno_bindgen/example/bindings/bindings.ts:264:43

TS2345 [ERROR]: Argument of type 'Uint8Array' is not assignable to parameter of type 'ToNativeType<"usize" | "pointer">'.
  let rawResult = _lib.symbols.test_str(a0_buf, a0_buf.byteLength)
                                        ~~~~~~
    at file:///Users/skanehira/dev/github.com/denoland/deno_bindgen/example/bindings/bindings.ts:270:41

TS2345 [ERROR]: Argument of type 'Uint8Array' is not assignable to parameter of type 'ToNativeType<"usize" | "pointer">'.
  let rawResult = _lib.symbols.test_tag_and_content(a0_buf, a0_buf.byteLength)
                                                    ~~~~~~
    at file:///Users/skanehira/dev/github.com/denoland/deno_bindgen/example/bindings/bindings.ts:281:53

Found 11 errors.

Generated bindings.ts no longer works with latest deno

Since denoland/deno#14915 was released in Deno v1.23.1 my bindings.ts file no longer compiles as there is a typescript error:

error: TS2345 [ERROR]: Argument of type 'UnsafePointer' is not assignable to parameter of type 'bigint'.

for a generated line such as:

const ptr = new Deno.UnsafePointerView(v as Deno.UnsafePointer)

I'm wondering if there is a plan to update deno_bindgen accordingly or is there some other direction to be looking now?

Thanks very much.

The ".dll" cache loaded by FFI cannot be cleared

// Auto-generated with deno_bindgen
import { CachePolicy, prepare } from "https://deno.land/x/[email protected]/plug.ts"
const opts = {
  name: "teyda_core",
  url: (new URL("../target/release", import.meta.url)).toString(),
  policy: undefined,
}
const _lib = await prepare(opts, {
  core_run: { parameters: [], result: "void", nonblocking: false },
  mh: { parameters: ["pointer", "usize"], result: "void", nonblocking: false },
})

export function test() {
  let rawResult = _lib.symbols.core_run()
  const result = rawResult
  return result
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.