Skip to content

Commit

Permalink
Merge pull request #5 from littledivy/buffer_structs_stuff
Browse files Browse the repository at this point in the history
rewrite: struct support
  • Loading branch information
littledivy authored Oct 7, 2021
2 parents e3e6687 + 7e8a0ba commit a3a7624
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 319 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

- uses: denoland/setup-deno@v1
with:
deno-version: v1.13.1
deno-version: ab2e0a465e4eafe4de2cc6ac7ef61d1655db4c2d

- name: Install rust
uses: hecrj/setup-rust-action@v1
Expand All @@ -30,6 +30,4 @@ jobs:
run: |
cd example
deno run -A ../cli.ts
deno test --allow-ffi --unstable
deno test --no-check --allow-ffi --unstable
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ deno_bindgen = { git = "https://github.com/littledivy/deno_bindgen" }
use deno_bindgen::deno_bindgen;

#[deno_bindgen]
fn add(a: i32, b: i32) -> i32 {
a + b
pub struct Input {
a: i32,
b: i32,
}

#[deno_bindgen]
fn add(input: Input) -> i32 {
input.a + input.b
}
```

Expand All @@ -33,5 +39,6 @@ $ deno_bindgen
```typescript
// add.ts
import { add } from "./bindings/bindings.ts";
add(1, 2); // 3

add({ a: 1, b: 2 }); // 3
```
21 changes: 16 additions & 5 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,34 @@ if (Deno.build.os == "windows") {

let source = null;
async function generate() {
let conf;
try {
const conf = JSON.parse(await Deno.readTextFile("bindings.json"));
const pkgName = conf.name;
source = "// Auto-generated with deno_bindgen\n";

source += codegen(`target/${profile}/lib${pkgName}${ext}`, conf.bindings);
conf = JSON.parse(await Deno.readTextFile("bindings.json"));
} catch (_) {
// Nothing to update.
return;
}

console.log(conf);
const pkgName = conf.name;

source = "// Auto-generated with deno_bindgen\n";
source += codegen(
`target/${profile}/lib${pkgName}${ext}`,
conf.type_defs,
conf.bindings,
{
le: conf.le,
}
);
await Deno.remove("bindings.json");
}

await build();
await generate();

if (source != null) {

await ensureDir("bindings");
await Deno.writeTextFile("bindings/bindings.ts", source);
}
Loading

0 comments on commit a3a7624

Please sign in to comment.