Skip to content

Commit

Permalink
Fix escaping path on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy committed Nov 12, 2023
1 parent 65b9a5b commit dcfa56e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions deno_bindgen_ir/codegen/deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;

Expand All @@ -137,8 +136,11 @@ impl<'a> Codegen<'a> {

fn lazy_dlopen<W: Write>(&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> {
Expand Down
4 changes: 2 additions & 2 deletions deno_bindgen_macro/src/fn_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn parse_type(ty: &Box<syn::Type>) -> Result<Type> {
}
}

pub fn handle_inner(
pub(crate) fn handle_inner(
fn_: ItemFn,
attrs: FnAttributes,
) -> Result<(TokenStream2, SymbolBuilder)> {
Expand Down Expand Up @@ -209,7 +209,7 @@ pub fn handle_inner(
))
}

pub fn handle(fn_: ItemFn, attrs: FnAttributes) -> Result<TokenStream2> {
pub(crate) fn handle(fn_: ItemFn, attrs: FnAttributes) -> Result<TokenStream2> {
let (ffi_fn, _) = handle_inner(fn_, attrs)?;
Ok(ffi_fn)
}
2 changes: 1 addition & 1 deletion e2e_test/bindings/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit dcfa56e

Please sign in to comment.