From dcfa56ee3e6b51d826d07f48e1f372206537c5b8 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Sun, 12 Nov 2023 23:02:05 +0530 Subject: [PATCH] Fix escaping path on Windows --- deno_bindgen_ir/codegen/deno.rs | 10 ++++++---- deno_bindgen_macro/src/fn_.rs | 4 ++-- e2e_test/bindings/mod.ts | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/deno_bindgen_ir/codegen/deno.rs b/deno_bindgen_ir/codegen/deno.rs index c3aa431..1814f51 100644 --- a/deno_bindgen_ir/codegen/deno.rs +++ b/deno_bindgen_ir/codegen/deno.rs @@ -127,8 +127,7 @@ impl<'a> Codegen<'a> { return self.lazy_dlopen(writer); } writeln!(writer, "const {{ dlopen }} = Deno;\n")?; - let target = self.target.to_string_lossy(); - writeln!(writer, "const {{ symbols }} = dlopen('{target}', {{")?; + writeln!(writer, "const {{ symbols }} = dlopen({:?}, {{", self.target)?; self.write_symbols(writer)?; writeln!(writer, "}});\n")?; @@ -137,8 +136,11 @@ impl<'a> Codegen<'a> { fn lazy_dlopen(&self, writer: &mut W) -> Result<()> { writeln!(writer, "let symbols: any;\n")?; - let target = self.target.to_string_lossy(); - writeln!(writer, "export function load(path: string = '{target}') {{")?; + writeln!( + writer, + "export function load(path: string = {:?}) {{", + self.target + )?; writeln!(writer, " const {{ dlopen }} = Deno;\n")?; writeln!(writer, " const {{ symbols: symbols_ }} = dlopen(path, {{")?; struct WrapperWriter<'a, W: Write> { diff --git a/deno_bindgen_macro/src/fn_.rs b/deno_bindgen_macro/src/fn_.rs index e320398..9e8fe68 100644 --- a/deno_bindgen_macro/src/fn_.rs +++ b/deno_bindgen_macro/src/fn_.rs @@ -72,7 +72,7 @@ fn parse_type(ty: &Box) -> Result { } } -pub fn handle_inner( +pub(crate) fn handle_inner( fn_: ItemFn, attrs: FnAttributes, ) -> Result<(TokenStream2, SymbolBuilder)> { @@ -209,7 +209,7 @@ pub fn handle_inner( )) } -pub fn handle(fn_: ItemFn, attrs: FnAttributes) -> Result { +pub(crate) fn handle(fn_: ItemFn, attrs: FnAttributes) -> Result { let (ffi_fn, _) = handle_inner(fn_, attrs)?; Ok(ffi_fn) } diff --git a/e2e_test/bindings/mod.ts b/e2e_test/bindings/mod.ts index 2801917..7951777 100644 --- a/e2e_test/bindings/mod.ts +++ b/e2e_test/bindings/mod.ts @@ -5,7 +5,7 @@ const { dlopen } = Deno; -const { symbols } = dlopen('target/debug/libdeno_bindgen_e2e.dylib', { +const { symbols } = dlopen("/Users/divy/gh/deno_bindgen/e2e_test/target/debug/libdeno_bindgen_e2e.dylib", { add: { parameters: [ 'i32',