Simplified glue code generation for Deno FFI libraries written in Rust.

Overview

deno_bindgen

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

Quickstart

# install CLI
deno install -Afq -n deno_bindgen https://deno.land/x/deno_bindgen/cli.ts
# Cargo.toml
[dependencies]
deno_bindgen = "0.1"
// add.rs
use deno_bindgen::deno_bindgen;

#[deno_bindgen]
pub struct Input {
  a: i32,
  b: i32,
}

#[deno_bindgen]
fn add(input: Input) -> i32 {
  input.a + input.b
}
$ deno_bindgen
// add.ts
import { add } from "./bindings/bindings.ts";

add({ a: 1, b: 2 }); // 3

LICENSE

MIT

Issues
  • Empty bindings.json file breaks build

    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
    opened by lucsoft 9
  • Publishing a library

    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.

    enhancement help wanted 
    opened by littledivy 2
  • Stable rustc

    Stable rustc

    Just need to get rid of box pattern feature.

    good first issue 
    opened by littledivy 1
  • rewrite: struct support

    rewrite: struct support

    Closes #3

    opened by littledivy 1
  • Mark functions non-blocking with macro attributes

    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.

    opened by littledivy 1
  • Add support for `enum`s

    Add support for `enum`s

    null

    opened by littledivy 0
  • 0.2.0

    0.2.0

    null

    opened by littledivy 0
  • support mutable buffers - `&mut [u8]`

    support mutable buffers - `&mut [u8]`

    null

    opened by littledivy 0
  • Pluggable serialization

    Pluggable serialization

    Having an option to override the default JSON serialization would be nice.

    For example the https://github.com/Adelost/javascript-serialization-benchmark list other more performant options such as AVRO.

    opened by rracariu 0
  • Move the Rust/Deno type mapping into the Rust macro

    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.

    opened by andreubotella 0
Releases(0.3.1)
  • 0.3.1(Nov 15, 2021)

    deno_bindgen 0.3.1

    Changes

    • support mutable buffers - &mut [u8] https://github.com/littledivy/deno_bindgen/pull/22
    • improvements to README and source refactor https://github.com/littledivy/deno_bindgen/pull/24
    • use import.meta for loading lib relative to module https://github.com/littledivy/deno_bindgen/pull/25
    • delete previous bindings metadata https://github.com/littledivy/deno_bindgen/pull/28
    • Force reload cache on debug builds. Enforce lifetimes for `&'a mut
    • Support lifetimes in enums and #[serde(borrow)] for wrappers
    • Stable rustc
    • Handle malformed bindings.json. #30
    • Support serde's tag and content enum attributes. #32

    Full Changelog: https://github.com/littledivy/deno_bindgen/compare/0.2.0...0.3.1

    Upgrade to 0.3

    Install the new CLI:

    deno install -n deno_bindgen -f -A --unstable https://deno.land/x/[email protected]/cli.ts
    

    and update your Cargo.toml dependency:

    [dependencies]
    deno_bindgen = "0.3.1"
    
    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Oct 20, 2021)

    deno_bindgen 0.2.0

    New features

    • --release accepts URLs and pass them to plug by @littledivy in https://github.com/littledivy/deno_bindgen/pull/10
    • preserve Rust docs in JS bindings by @littledivy in https://github.com/littledivy/deno_bindgen/pull/13
    • support non_blocking attribute for symbols by @littledivy in https://github.com/littledivy/deno_bindgen/pull/14
    • add support for &str by @littledivy in https://github.com/littledivy/deno_bindgen/pull/15
    • add support for &[u8] by @littledivy in https://github.com/littledivy/deno_bindgen/pull/16
    • Add support for enums by @littledivy in https://github.com/littledivy/deno_bindgen/pull/17
    • add support for serde attributes by @littledivy in https://github.com/littledivy/deno_bindgen/pull/18
    • autoformat with dprint WASM by @littledivy in https://github.com/littledivy/deno_bindgen/pull/19

    Usage

    use deno_bindgen::deno_bindgen;
    
    #[deno_bindgen]
    pub struct Input {
      /// Doc comments are transformed into
      /// jsdocs.
      a: Vec<Vec<String>>,
    }
    
    #[deno_bindgen(non_blocking)]
    pub fn say_hello(message: &str) {
      println!("{}", message);
    }
    

    Generated bindings will look like this:

    // bindings/binding.ts
    // ... <init code here>
    type Input = {
      /**
       * Doc comments are transformed into
       * jsdocs.
       **/
      a: Array<Array<string>>;
    };
    
    export async function say_hello(message: string) {
      // ... <glue code for symbol here>
    }
    

    These bindings contain nessecary code to open the shared library, define symbols and expose type definitions. They can be simply imported into Deno code:

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

    Full Changelog: https://github.com/littledivy/deno_bindgen/compare/0.1.1...0.2.0

    Source code(tar.gz)
    Source code(zip)
  • 0.1.1(Oct 14, 2021)

  • 0.1.0(Oct 13, 2021)

    deno_bindgen 0.1.0

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

    Quickstart

    # install CLI
    deno install -Afq -n deno_bindgen https://deno.land/x/deno_bindgen/cli.ts
    
    # Cargo.toml
    [dependencies]
    deno_bindgen = "0.1"
    
    // add.rs
    use deno_bindgen::deno_bindgen;
    
    #[deno_bindgen]
    pub struct Input {
      a: i32,
      b: i32,
    }
    
    #[deno_bindgen]
    fn add(input: Input) -> i32 {
      input.a + input.b
    }
    
    $ deno_bindgen
    
    // add.ts
    import { add } from "./bindings/bindings.ts";
    
    add({ a: 1, b: 2 }); // 3
    
    Source code(tar.gz)
    Source code(zip)
Owner
Divy Srivastava
17. Contributing to @denoland. Rust, Go and Typescript. Core team @useverto @nestdotland
Divy Srivastava
A simplified but faster version of Routerify

Routerify lite Routerify-lite is a simplified but faster version of Routerify. It only provides below functions: path matching error handling Why not

jinhua luo 6 Aug 24, 2021
Easy to use Rust i18n library based on code generation

rosetta-i18n rosetta-i18n is an easy-to-use and opinionated Rust internationalization (i18n) library powered by code generation. rosetta_i18n::include

null 31 Oct 29, 2021
Membrane is an opinionated crate that generates a Dart package from a Rust library. Extremely fast performance with strict typing and zero copy returns over the FFI boundary via bincode.

Membrane is an opinionated crate that generates a Dart package from a Rust library. Extremely fast performance with strict typing and zero copy returns over the FFI boundary via bincode.

Jerel Unruh 8 Nov 17, 2021
Arkworks bindings to Circom's R1CS, for Groth16 Proof and Witness generation in Rust.

ark-circom Arkworks bindings to Circom's R1CS, for Groth16 Proof and Witness generation in Rust.

Georgios Konstantopoulos 46 Nov 29, 2021
Fegeya Gretea (aka green tea), new generation programming language.

Fegeya Gretea Gretea (aka green tea), new generation programming language. A taste of Gretea's syntax: import tea.green.fmt module hello { fn hel

Ferhat Geçdoğan 14 Nov 18, 2021
PartiQL libraries and tools in Rust.

This is a collection of crates to provide Rust support for the PartiQL query language.

null 22 Nov 15, 2021
mollusc is a collection of pure-Rust libraries for parsing, interpreting, and analyzing LLVM.

mollusc is a collection of pure-Rust libraries for parsing, interpreting, and analyzing LLVM.

William Woodruff 22 Nov 30, 2021
Mobile safari / webview remote debugging and e2e testing libraries

Canter (WIP) (WIP) Mobile safari / webview remote debugging and e2e testing libraries. Developed for safari/webview e2e testing on iPhone. Works only

Han Lee 8 Nov 23, 2021
A simple code boilerplate generator written in Rust.

?? Cgen What is Cgen? A modern, cross-platform, multi-language boilerplate generator aimed to make your code generation less hectic! If you wish to su

Rithul Kamesh 2 Nov 15, 2021
Migrate C code to Rust

C2Rust helps you migrate C99-compliant code to Rust. The translator (or transpiler) produces unsafe Rust code that closely mirrors the input C code. T

Immunant 2.1k Nov 29, 2021
Minimal, flexible framework for implementing solutions to Advent of Code in Rust

This is advent_of_code_traits, a minimal, flexible framework for implementing solutions to Advent of Code in Rust.

David 5 May 27, 2021
Mix async code with CPU-heavy thread pools using Tokio + Rayon

tokio-rayon Mix async code with CPU-heavy thread pools using Tokio + Rayon Resources Documentation crates.io TL;DR Sometimes, you're doing async stuff

Andy Barron 32 Nov 8, 2021
Waits until the exit code of a program is zero

Waitz A rust utility to wait that a program exits with 0. You need to wait for something to start up and don't know when it finishes?

Max Strübing 13 Jun 28, 2021
Sample code for compute shader 101 training

Sample code for Compute Shader 101 This repo contains sample code to help you get started writing applications using compute shaders.

Google Fonts 259 Nov 20, 2021
Detect if code is running inside a virtual machine (x86 and x86-64 only).

inside-vm Detect if code is running inside a virtual machine. Only works on x86 and x86-64. How does it work Measure average cpu cycles when calling c

null 32 Nov 15, 2021
Doku is a framework for building documentation with code-as-data methodology in mind.

Doku is a framework for building documentation with code-as-data methodology in mind. Say goodbye to stale, hand-written documentation - with D

ANIXE 63 Nov 14, 2021
A tool to run web applications on AWS Lambda without changing code.

AWS Lambda Adapter A tool to run web applications on AWS Lambda without changing code. How does it work? AWS Lambda Adapter supports AWS Lambda functi

AWS Samples 50 Nov 20, 2021
Dynamically invoke arbitrary unmanaged code.

DInvoke_rs Rust port of Dinvoke. DInvoke_rs may be used for many purposes such as PE parsing, dynamic exported functions resolution, dynamically loadi

Kurosh Dabbagh Escalante 41 Nov 19, 2021
A document-code sync tools for document engineering.

Writing A document-code sync tools for document engineering. Writing 是一个自动 “文档-代码” 同步工具。解析 Markdown 中的代码定义,读取目标代码,并嵌入到新的文档中。 Language parse support by

Inherd OS Team (硬核开源小组) 18 Nov 8, 2021