Skip to content

Commit

Permalink
fix: revert non-working changes made in denoland#72
Browse files Browse the repository at this point in the history
  • Loading branch information
vectronic committed Sep 13, 2022
1 parent ce45e33 commit d85a50b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
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/[email protected]/fs/ensure_dir.ts";
import { parse } from "https://deno.land/[email protected]/flags/mod.ts";
import { join } from "https://deno.land/[email protected]/path/mod.ts";
import { relative } from "https://deno.land/[email protected]/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
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

0 comments on commit d85a50b

Please sign in to comment.