Dont pass original crate name in generator CLI (as there are multiple)
authorMatt Corallo <git@bluematt.me>
Mon, 12 Apr 2021 17:59:20 +0000 (13:59 -0400)
committerMatt Corallo <git@bluematt.me>
Thu, 15 Apr 2021 22:01:27 +0000 (18:01 -0400)
c-bindings-gen/src/main.rs
genbindings.sh

index 0d002bbbeb40421598b34add308071dc7afe6532..e217bab57aa97723ed7389e480fa092842333118 100644 (file)
@@ -1300,8 +1300,9 @@ fn writeln_fn<'a, 'b, W: std::io::Write>(w: &mut W, f: &'a syn::ItemFn, types: &
 /// Do the Real Work of mapping an original file to C-callable wrappers. Creates a new file at
 /// `out_path` and fills it with wrapper structs/functions to allow calling the things in the AST
 /// at `module` from C.
 /// Do the Real Work of mapping an original file to C-callable wrappers. Creates a new file at
 /// `out_path` and fills it with wrapper structs/functions to allow calling the things in the AST
 /// at `module` from C.
-fn convert_file<'a, 'b>(libast: &'a FullLibraryAST, crate_types: &CrateTypes<'a>, out_dir: &str, orig_crate: &str, header_file: &mut File, cpp_header_file: &mut File) {
+fn convert_file<'a, 'b>(libast: &'a FullLibraryAST, crate_types: &CrateTypes<'a>, out_dir: &str, header_file: &mut File, cpp_header_file: &mut File) {
        for (module, astmod) in libast.modules.iter() {
        for (module, astmod) in libast.modules.iter() {
+               let orig_crate = module.splitn(2, "::").next().unwrap();
                let ASTModule { ref attrs, ref items, ref submods } = astmod;
                assert_eq!(export_status(&attrs), ExportStatus::Export);
 
                let ASTModule { ref attrs, ref items, ref submods } = astmod;
                assert_eq!(export_status(&attrs), ExportStatus::Export);
 
@@ -1454,10 +1455,11 @@ fn walk_private_mod<'a>(ast_storage: &'a FullLibraryAST, orig_crate: &str, modul
 }
 
 /// Walk the FullLibraryAST, deciding how things will be mapped and adding tracking to CrateTypes.
 }
 
 /// Walk the FullLibraryAST, deciding how things will be mapped and adding tracking to CrateTypes.
-fn walk_ast<'a>(ast_storage: &'a FullLibraryAST, orig_crate: &str, crate_types: &mut CrateTypes<'a>) {
+fn walk_ast<'a>(ast_storage: &'a FullLibraryAST, crate_types: &mut CrateTypes<'a>) {
        for (module, astmod) in ast_storage.modules.iter() {
                let ASTModule { ref attrs, ref items, submods: _ } = astmod;
                assert_eq!(export_status(&attrs), ExportStatus::Export);
        for (module, astmod) in ast_storage.modules.iter() {
                let ASTModule { ref attrs, ref items, submods: _ } = astmod;
                assert_eq!(export_status(&attrs), ExportStatus::Export);
+               let orig_crate = module.splitn(2, "::").next().unwrap();
                let import_resolver = ImportResolver::new(orig_crate, &ast_storage.dependencies, module, items);
 
                for item in items.iter() {
                let import_resolver = ImportResolver::new(orig_crate, &ast_storage.dependencies, module, items);
 
                for item in items.iter() {
@@ -1573,17 +1575,17 @@ fn walk_ast<'a>(ast_storage: &'a FullLibraryAST, orig_crate: &str, crate_types:
 
 fn main() {
        let args: Vec<String> = env::args().collect();
 
 fn main() {
        let args: Vec<String> = env::args().collect();
-       if args.len() != 6 {
-               eprintln!("Usage: target/dir source_crate_name derived_templates.rs extra/includes.h extra/cpp/includes.hpp");
+       if args.len() != 5 {
+               eprintln!("Usage: target/dir derived_templates.rs extra/includes.h extra/cpp/includes.hpp");
                process::exit(1);
        }
 
        let mut derived_templates = std::fs::OpenOptions::new().write(true).create(true).truncate(true)
                process::exit(1);
        }
 
        let mut derived_templates = std::fs::OpenOptions::new().write(true).create(true).truncate(true)
-               .open(&args[3]).expect("Unable to open new header file");
+               .open(&args[2]).expect("Unable to open new header file");
        let mut header_file = std::fs::OpenOptions::new().write(true).create(true).truncate(true)
        let mut header_file = std::fs::OpenOptions::new().write(true).create(true).truncate(true)
-               .open(&args[4]).expect("Unable to open new header file");
+               .open(&args[3]).expect("Unable to open new header file");
        let mut cpp_header_file = std::fs::OpenOptions::new().write(true).create(true).truncate(true)
        let mut cpp_header_file = std::fs::OpenOptions::new().write(true).create(true).truncate(true)
-               .open(&args[5]).expect("Unable to open new header file");
+               .open(&args[4]).expect("Unable to open new header file");
 
        writeln!(header_file, "#if defined(__GNUC__)").unwrap();
        writeln!(header_file, "#define MUST_USE_STRUCT __attribute__((warn_unused))").unwrap();
 
        writeln!(header_file, "#if defined(__GNUC__)").unwrap();
        writeln!(header_file, "#define MUST_USE_STRUCT __attribute__((warn_unused))").unwrap();
@@ -1609,10 +1611,10 @@ fn main() {
        // ...then walk the ASTs tracking what types we will map, and how, so that we can resolve them
        // when parsing other file ASTs...
        let mut libtypes = CrateTypes::new(&mut derived_templates, &libast);
        // ...then walk the ASTs tracking what types we will map, and how, so that we can resolve them
        // when parsing other file ASTs...
        let mut libtypes = CrateTypes::new(&mut derived_templates, &libast);
-       walk_ast(&libast, &args[2], &mut libtypes);
+       walk_ast(&libast, &mut libtypes);
 
        // ... finally, do the actual file conversion/mapping, writing out types as we go.
 
        // ... finally, do the actual file conversion/mapping, writing out types as we go.
-       convert_file(&libast, &libtypes, &args[1], &args[2], &mut header_file, &mut cpp_header_file);
+       convert_file(&libast, &libtypes, &args[1], &mut header_file, &mut cpp_header_file);
 
        // For container templates which we created while walking the crate, make sure we add C++
        // mapped types so that C++ users can utilize the auto-destructors available.
 
        // For container templates which we created while walking the crate, make sure we add C++
        // mapped types so that C++ users can utilize the auto-destructors available.
index 67489a669ec49c7411788da9ce96fd2699b9ab3d..ff90b3ad4b33e0a2240bfaeb605b8f5e55d38367 100755 (executable)
@@ -55,7 +55,7 @@ else
 fi
 echo "}" >> /tmp/lightning-crate-source.txt
 
 fi
 echo "}" >> /tmp/lightning-crate-source.txt
 
-cat /tmp/lightning-crate-source.txt | RUST_BACKTRACE=1 "$BIN" "$OUT/" lightning "$OUT_TEMPL" "$OUT_F" "$OUT_CPP"
+cat /tmp/lightning-crate-source.txt | RUST_BACKTRACE=1 "$BIN" "$OUT/" "$OUT_TEMPL" "$OUT_F" "$OUT_CPP"
 popd
 
 if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then
 popd
 
 if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then