From ce45e33ecd8aa780fccff6885c4073250b5018f7 Mon Sep 17 00:00:00 2001 From: vectronic Date: Tue, 13 Sep 2022 12:27:28 +0100 Subject: [PATCH 1/2] docs: fix typo --- deno_bindgen/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deno_bindgen/lib.rs b/deno_bindgen/lib.rs index d181f8f..9ff0de3 100644 --- a/deno_bindgen/lib.rs +++ b/deno_bindgen/lib.rs @@ -41,7 +41,7 @@ //! // ... //! } //! ``` -//! 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: //! ``` From d85a50b3b4bf11b35ad84fcd64c18f8d0a51dbde Mon Sep 17 00:00:00 2001 From: vectronic Date: Tue, 13 Sep 2022 12:29:49 +0100 Subject: [PATCH 2/2] fix: revert non-working changes made in https://github.com/denoland/deno_bindgen/issues/72 --- cli.ts | 6 +---- deno_bindgen_macro/src/lib.rs | 41 ++++++++++++++--------------------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/cli.ts b/cli.ts index 8ef0436..ac72ff8 100644 --- a/cli.ts +++ b/cli.ts @@ -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"]; diff --git a/deno_bindgen_macro/src/lib.rs b/deno_bindgen_macro/src/lib.rs index de1623a..7f84618 100644 --- a/deno_bindgen_macro/src/lib.rs +++ b/deno_bindgen_macro/src/lib.rs @@ -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; @@ -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; @@ -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::(input.clone()) {