Skip to content
Open
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
6 changes: 1 addition & 5 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

import { ensureDir } from "https://deno.land/std@0.132.0/fs/ensure_dir.ts";
import { parse } from "https://deno.land/std@0.132.0/flags/mod.ts";
import { join } from "https://deno.land/std@0.132.0/path/mod.ts";
import { relative } from "https://deno.land/std@0.132.0/path/mod.ts";
import { codegen } from "./codegen.ts";

const flags = parse(Deno.args, { "--": true });
const release = !!flags.release;

const metafile = join(
Deno.env.get("OUT_DIR") || await findRelativeTarget(),
"bindings.json",
);
const metafile = "bindings.json";

function build() {
const cmd = ["cargo", "build"];
Expand Down
2 changes: 1 addition & 1 deletion deno_bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
//! // ... <glue code for symbol here>
//! }
//! ```
//! These bindings contain nessecary code to open the shared library,
//! These bindings contain necessary code to open the shared library,
//! define symbols and expose type definitions.
//! They can be simply imported into Deno code:
//! ```
Expand Down
41 changes: 16 additions & 25 deletions deno_bindgen_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::env;
use std::fs::OpenOptions;
use std::io::Read;
use std::io::Write;
use std::path::Path;
use syn::parse_macro_input;
use syn::parse_quote;
use syn::ItemFn;
Expand All @@ -23,6 +22,8 @@ use crate::derive_struct::process_struct;
use crate::meta::Glue;
use crate::meta::Type;

const METAFILE: &str = "bindings.json";

#[cfg(target_endian = "little")]
const ENDIANNESS: bool = true;

Expand All @@ -31,35 +32,25 @@ const ENDIANNESS: bool = false;

#[proc_macro_attribute]
pub fn deno_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream {
let metafile_path: String = match env::var("OUT_DIR") {
Ok(out_dir) => Path::new(&out_dir)
.join("bindings.json")
.into_os_string()
.into_string()
.unwrap(),
Err(_e) => String::from("bindings.json"),
};

let mut metadata: Glue =
match OpenOptions::new().read(true).open(metafile_path.as_str()) {
Ok(mut fd) => {
let mut meta = String::new();
fd.read_to_string(&mut meta)
.expect("Error reading meta file");
let mut metadata: Glue = match OpenOptions::new().read(true).open(METAFILE) {
Ok(mut fd) => {
let mut meta = String::new();
fd.read_to_string(&mut meta)
.expect("Error reading meta file");

serde_json::from_str(&meta).unwrap_or_default()
}
Err(_) => Glue {
little_endian: ENDIANNESS,
name: env::var("CARGO_CRATE_NAME").unwrap_or_default(),
..Default::default()
},
};
serde_json::from_str(&meta).unwrap_or_default()
}
Err(_) => Glue {
little_endian: ENDIANNESS,
name: env::var("CARGO_CRATE_NAME").unwrap_or_default(),
..Default::default()
},
};

let mut metafile = OpenOptions::new()
.write(true)
.create(true)
.open(metafile_path.as_str())
.open(METAFILE)
.expect("Error opening meta file");

match syn::parse::<ItemFn>(input.clone()) {
Expand Down