diff --git a/src/bindgen/bindings.rs b/src/bindgen/bindings.rs index 410b11f30..75585106b 100644 --- a/src/bindgen/bindings.rs +++ b/src/bindgen/bindings.rs @@ -131,6 +131,28 @@ impl Bindings { fields } + /// Lists the exported symbols that can be dynamically linked, i.e. globals and functions. + pub fn dynamic_symbols_names(&self) -> Vec { + use crate::bindgen::ir::Item; + + let function_names = self.functions.iter().map(|f| f.path().name().to_string()); + let global_names = self.globals.iter().map(|g| g.export_name().to_string()); + + let mut res = Vec::new(); + res.extend(function_names); + res.extend(global_names); + res + } + + pub fn generate_symfile>(&self, symfile_path: P) { + let symbols = self.dynamic_symbols_names(); + if let Some(dir) = symfile_path.as_ref().parent() { + std::fs::create_dir_all(dir).unwrap(); + } + let mut symfile = File::create(symfile_path).unwrap(); + write!(&mut symfile, "{{\n{};\n}};\n", symbols.join(";\n")).expect("Writing symbol file failed"); + } + pub fn generate_depfile>(&self, header_path: P, depfile_path: P) { if let Some(dir) = depfile_path.as_ref().parent() { if !dir.exists() { diff --git a/src/main.rs b/src/main.rs index eb78a080b..86c110733 100644 --- a/src/main.rs +++ b/src/main.rs @@ -280,6 +280,19 @@ fn main() { This option is ignored if `--out` is missing." ) ) + .arg( + Arg::new("symfile") + .value_name("PATH") + .long("symfile") + .takes_value(true) + .min_values(1) + .max_values(1) + .required(false) + .help("Generate a list of symbols at the given Path. This list can be \ + given to a linker in order to compile an application that exposes \ + dynamic symbols. Useful when creating a plugin system with a C interface." + ) + ) .get_matches(); if !matches.is_present("out") && matches.is_present("verify") { @@ -325,7 +338,10 @@ fn main() { std::process::exit(2); } if let Some(depfile) = matches.value_of("depfile") { - bindings.generate_depfile(file, depfile) + bindings.generate_depfile(file, depfile); + } + if let Some(symfile) = matches.value_of("symfile") { + bindings.generate_symfile(symfile); } } _ => { diff --git a/tests/expectations-symbols/abi_string.c.sym b/tests/expectations-symbols/abi_string.c.sym new file mode 100644 index 000000000..6e4201885 --- /dev/null +++ b/tests/expectations-symbols/abi_string.c.sym @@ -0,0 +1,4 @@ +{ +c; +c_unwind; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/alias.c.sym b/tests/expectations-symbols/alias.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/alias.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/annotation.c.sym b/tests/expectations-symbols/annotation.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/annotation.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/array.c.sym b/tests/expectations-symbols/array.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/array.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/asserted_cast.c.sym b/tests/expectations-symbols/asserted_cast.c.sym new file mode 100644 index 000000000..8d5c6388c --- /dev/null +++ b/tests/expectations-symbols/asserted_cast.c.sym @@ -0,0 +1,3 @@ +{ +foo; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/assoc_constant.c.sym b/tests/expectations-symbols/assoc_constant.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/assoc_constant.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/associated_in_body.c.sym b/tests/expectations-symbols/associated_in_body.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/associated_in_body.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/bitfield.c.sym b/tests/expectations-symbols/bitfield.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/bitfield.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/bitflags.c.sym b/tests/expectations-symbols/bitflags.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/bitflags.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/body.c.sym b/tests/expectations-symbols/body.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/body.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/box.c.sym b/tests/expectations-symbols/box.c.sym new file mode 100644 index 000000000..e80fae417 --- /dev/null +++ b/tests/expectations-symbols/box.c.sym @@ -0,0 +1,5 @@ +{ +root; +drop_box; +drop_box_opt; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/cdecl.c.sym b/tests/expectations-symbols/cdecl.c.sym new file mode 100644 index 000000000..37b4c4e2d --- /dev/null +++ b/tests/expectations-symbols/cdecl.c.sym @@ -0,0 +1,4 @@ +{ +O; +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/cell.c.sym b/tests/expectations-symbols/cell.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/cell.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/cfg.c.sym b/tests/expectations-symbols/cfg.c.sym new file mode 100644 index 000000000..5e35f6ab5 --- /dev/null +++ b/tests/expectations-symbols/cfg.c.sym @@ -0,0 +1,5 @@ +{ +root; +root; +cond; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/cfg_2.c.sym b/tests/expectations-symbols/cfg_2.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/cfg_2.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/char.c.sym b/tests/expectations-symbols/char.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/char.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/const_generics.c.sym b/tests/expectations-symbols/const_generics.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/const_generics.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/const_generics_arrayvec.c.sym b/tests/expectations-symbols/const_generics_arrayvec.c.sym new file mode 100644 index 000000000..7432f3f4e --- /dev/null +++ b/tests/expectations-symbols/const_generics_arrayvec.c.sym @@ -0,0 +1,3 @@ +{ +push; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/const_generics_bool.c.sym b/tests/expectations-symbols/const_generics_bool.c.sym new file mode 100644 index 000000000..e132a2866 --- /dev/null +++ b/tests/expectations-symbols/const_generics_bool.c.sym @@ -0,0 +1,6 @@ +{ +new_set; +set_for_each; +new_map; +map_for_each; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/const_generics_byte.c.sym b/tests/expectations-symbols/const_generics_byte.c.sym new file mode 100644 index 000000000..bc72ad2a2 --- /dev/null +++ b/tests/expectations-symbols/const_generics_byte.c.sym @@ -0,0 +1,5 @@ +{ +init_parens_parser; +destroy_parens_parser; +init_braces_parser; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/const_generics_char.c.sym b/tests/expectations-symbols/const_generics_char.c.sym new file mode 100644 index 000000000..8bba1546a --- /dev/null +++ b/tests/expectations-symbols/const_generics_char.c.sym @@ -0,0 +1,3 @@ +{ +until_nul; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/const_generics_constant.c.sym b/tests/expectations-symbols/const_generics_constant.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/const_generics_constant.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/const_generics_thru.c.sym b/tests/expectations-symbols/const_generics_thru.c.sym new file mode 100644 index 000000000..e7c038632 --- /dev/null +++ b/tests/expectations-symbols/const_generics_thru.c.sym @@ -0,0 +1,4 @@ +{ +one; +two; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/constant.c.sym b/tests/expectations-symbols/constant.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/constant.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/constant_sort_name.c.sym b/tests/expectations-symbols/constant_sort_name.c.sym new file mode 100644 index 000000000..675f74e4f --- /dev/null +++ b/tests/expectations-symbols/constant_sort_name.c.sym @@ -0,0 +1,4 @@ +{ +C; +D; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/constant_sort_none.c.sym b/tests/expectations-symbols/constant_sort_none.c.sym new file mode 100644 index 000000000..6164d8831 --- /dev/null +++ b/tests/expectations-symbols/constant_sort_none.c.sym @@ -0,0 +1,4 @@ +{ +D; +C; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/custom_header.c.sym b/tests/expectations-symbols/custom_header.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/custom_header.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/decl_name_conflicting.c.sym b/tests/expectations-symbols/decl_name_conflicting.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/decl_name_conflicting.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/dep_v2.c.sym b/tests/expectations-symbols/dep_v2.c.sym new file mode 100644 index 000000000..3ac657824 --- /dev/null +++ b/tests/expectations-symbols/dep_v2.c.sym @@ -0,0 +1,3 @@ +{ +get_x; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/deprecated.c.sym b/tests/expectations-symbols/deprecated.c.sym new file mode 100644 index 000000000..d289c7bc7 --- /dev/null +++ b/tests/expectations-symbols/deprecated.c.sym @@ -0,0 +1,8 @@ +{ +deprecated_without_note; +deprecated_without_bracket; +deprecated_with_note; +deprecated_with_note_and_since; +deprecated_with_note_which_requires_to_be_escaped; +dummy; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/derive_eq.c.sym b/tests/expectations-symbols/derive_eq.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/derive_eq.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/derive_ostream.c.sym b/tests/expectations-symbols/derive_ostream.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/derive_ostream.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/destructor_and_copy_ctor.c.sym b/tests/expectations-symbols/destructor_and_copy_ctor.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/destructor_and_copy_ctor.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/display_list.c.sym b/tests/expectations-symbols/display_list.c.sym new file mode 100644 index 000000000..0d6ec9148 --- /dev/null +++ b/tests/expectations-symbols/display_list.c.sym @@ -0,0 +1,3 @@ +{ +push_item; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/doclength_short.c.sym b/tests/expectations-symbols/doclength_short.c.sym new file mode 100644 index 000000000..7148349f7 --- /dev/null +++ b/tests/expectations-symbols/doclength_short.c.sym @@ -0,0 +1,4 @@ +{ +root; +trunk; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/docstyle_auto.c.sym b/tests/expectations-symbols/docstyle_auto.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/docstyle_auto.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/docstyle_c99.c.sym b/tests/expectations-symbols/docstyle_c99.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/docstyle_c99.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/docstyle_doxy.c.sym b/tests/expectations-symbols/docstyle_doxy.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/docstyle_doxy.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/documentation.c.sym b/tests/expectations-symbols/documentation.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/documentation.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/documentation_attr.c.sym b/tests/expectations-symbols/documentation_attr.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/documentation_attr.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/enum.c.sym b/tests/expectations-symbols/enum.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/enum.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/enum_discriminant.c.sym b/tests/expectations-symbols/enum_discriminant.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/enum_discriminant.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/enum_self.c.sym b/tests/expectations-symbols/enum_self.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/enum_self.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/euclid.c.sym b/tests/expectations-symbols/euclid.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/euclid.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/exclude_generic_monomorph.c.sym b/tests/expectations-symbols/exclude_generic_monomorph.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/exclude_generic_monomorph.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/expand.c.sym b/tests/expectations-symbols/expand.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/expand.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/expand_default_features.c.sym b/tests/expectations-symbols/expand_default_features.c.sym new file mode 100644 index 000000000..ad575d094 --- /dev/null +++ b/tests/expectations-symbols/expand_default_features.c.sym @@ -0,0 +1,4 @@ +{ +extra_debug_fn; +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/expand_dep.c.sym b/tests/expectations-symbols/expand_dep.c.sym new file mode 100644 index 000000000..3ac657824 --- /dev/null +++ b/tests/expectations-symbols/expand_dep.c.sym @@ -0,0 +1,3 @@ +{ +get_x; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/expand_dep_v2.c.sym b/tests/expectations-symbols/expand_dep_v2.c.sym new file mode 100644 index 000000000..3ac657824 --- /dev/null +++ b/tests/expectations-symbols/expand_dep_v2.c.sym @@ -0,0 +1,3 @@ +{ +get_x; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/expand_features.c.sym b/tests/expectations-symbols/expand_features.c.sym new file mode 100644 index 000000000..fb3612bc5 --- /dev/null +++ b/tests/expectations-symbols/expand_features.c.sym @@ -0,0 +1,5 @@ +{ +extra_debug_fn; +cbindgen; +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/expand_no_default_features.c.sym b/tests/expectations-symbols/expand_no_default_features.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/expand_no_default_features.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/export_name.c.sym b/tests/expectations-symbols/export_name.c.sym new file mode 100644 index 000000000..7e8ea4699 --- /dev/null +++ b/tests/expectations-symbols/export_name.c.sym @@ -0,0 +1,3 @@ +{ +do_the_thing_with_export_name; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/extern.c.sym b/tests/expectations-symbols/extern.c.sym new file mode 100644 index 000000000..5d8dd399d --- /dev/null +++ b/tests/expectations-symbols/extern.c.sym @@ -0,0 +1,4 @@ +{ +foo; +bar; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/extern_2.c.sym b/tests/expectations-symbols/extern_2.c.sym new file mode 100644 index 000000000..f92a07326 --- /dev/null +++ b/tests/expectations-symbols/extern_2.c.sym @@ -0,0 +1,4 @@ +{ +first; +second; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/external_workspace_child.c.sym b/tests/expectations-symbols/external_workspace_child.c.sym new file mode 100644 index 000000000..c203ccfa9 --- /dev/null +++ b/tests/expectations-symbols/external_workspace_child.c.sym @@ -0,0 +1,3 @@ +{ +consume_ext; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/fns.c.sym b/tests/expectations-symbols/fns.c.sym new file mode 100644 index 000000000..6735ae9c8 --- /dev/null +++ b/tests/expectations-symbols/fns.c.sym @@ -0,0 +1,4 @@ +{ +root; +no_return; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/forward_declaration.c.sym b/tests/expectations-symbols/forward_declaration.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/forward_declaration.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/function_args.c.sym b/tests/expectations-symbols/function_args.c.sym new file mode 100644 index 000000000..f8e0f473f --- /dev/null +++ b/tests/expectations-symbols/function_args.c.sym @@ -0,0 +1,5 @@ +{ +unnamed; +pointer_test; +print_from_rust; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/function_noreturn.c.sym b/tests/expectations-symbols/function_noreturn.c.sym new file mode 100644 index 000000000..e1b054ece --- /dev/null +++ b/tests/expectations-symbols/function_noreturn.c.sym @@ -0,0 +1,4 @@ +{ +loop_forever; +normal_return; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/function_ptr.c.sym b/tests/expectations-symbols/function_ptr.c.sym new file mode 100644 index 000000000..91dcfa29e --- /dev/null +++ b/tests/expectations-symbols/function_ptr.c.sym @@ -0,0 +1,3 @@ +{ +my_function; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/function_sort_name.c.sym b/tests/expectations-symbols/function_sort_name.c.sym new file mode 100644 index 000000000..5c6ed8cb9 --- /dev/null +++ b/tests/expectations-symbols/function_sort_name.c.sym @@ -0,0 +1,6 @@ +{ +A; +B; +C; +D; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/function_sort_none.c.sym b/tests/expectations-symbols/function_sort_none.c.sym new file mode 100644 index 000000000..eff657b64 --- /dev/null +++ b/tests/expectations-symbols/function_sort_none.c.sym @@ -0,0 +1,6 @@ +{ +C; +B; +D; +A; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/generic_pointer.c.sym b/tests/expectations-symbols/generic_pointer.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/generic_pointer.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/global_variable.c.sym b/tests/expectations-symbols/global_variable.c.sym new file mode 100644 index 000000000..c44c2ef09 --- /dev/null +++ b/tests/expectations-symbols/global_variable.c.sym @@ -0,0 +1,4 @@ +{ +MUT_GLOBAL_ARRAY; +CONST_GLOBAL_ARRAY; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/ignore.c.sym b/tests/expectations-symbols/ignore.c.sym new file mode 100644 index 000000000..8e6166979 --- /dev/null +++ b/tests/expectations-symbols/ignore.c.sym @@ -0,0 +1,3 @@ +{ +no_ignore_root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/include_guard.c.sym b/tests/expectations-symbols/include_guard.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/include_guard.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/inner_mod.c.sym b/tests/expectations-symbols/inner_mod.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/inner_mod.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/item_types.c.sym b/tests/expectations-symbols/item_types.c.sym new file mode 100644 index 000000000..1ddafd702 --- /dev/null +++ b/tests/expectations-symbols/item_types.c.sym @@ -0,0 +1,3 @@ +{ +; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/item_types_renamed.c.sym b/tests/expectations-symbols/item_types_renamed.c.sym new file mode 100644 index 000000000..1ddafd702 --- /dev/null +++ b/tests/expectations-symbols/item_types_renamed.c.sym @@ -0,0 +1,3 @@ +{ +; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/lifetime_arg.c.sym b/tests/expectations-symbols/lifetime_arg.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/lifetime_arg.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/linestyle_cr.c.sym b/tests/expectations-symbols/linestyle_cr.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/linestyle_cr.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/linestyle_crlf.c.sym b/tests/expectations-symbols/linestyle_crlf.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/linestyle_crlf.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/linestyle_lf.c.sym b/tests/expectations-symbols/linestyle_lf.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/linestyle_lf.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/mangle.c.sym b/tests/expectations-symbols/mangle.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/mangle.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/manuallydrop.c.sym b/tests/expectations-symbols/manuallydrop.c.sym new file mode 100644 index 000000000..d36f2a584 --- /dev/null +++ b/tests/expectations-symbols/manuallydrop.c.sym @@ -0,0 +1,4 @@ +{ +root; +take; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/maybeuninit.c.sym b/tests/expectations-symbols/maybeuninit.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/maybeuninit.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/mod_2015.c.sym b/tests/expectations-symbols/mod_2015.c.sym new file mode 100644 index 000000000..be489bc6d --- /dev/null +++ b/tests/expectations-symbols/mod_2015.c.sym @@ -0,0 +1,4 @@ +{ +export_me; +from_really_nested_mod; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/mod_2018.c.sym b/tests/expectations-symbols/mod_2018.c.sym new file mode 100644 index 000000000..ab2cb4c3a --- /dev/null +++ b/tests/expectations-symbols/mod_2018.c.sym @@ -0,0 +1,5 @@ +{ +export_me; +export_me_2; +from_really_nested_mod; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/mod_attr.c.sym b/tests/expectations-symbols/mod_attr.c.sym new file mode 100644 index 000000000..5d8dd399d --- /dev/null +++ b/tests/expectations-symbols/mod_attr.c.sym @@ -0,0 +1,4 @@ +{ +foo; +bar; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/mod_path.c.sym b/tests/expectations-symbols/mod_path.c.sym new file mode 100644 index 000000000..4ebaf3191 --- /dev/null +++ b/tests/expectations-symbols/mod_path.c.sym @@ -0,0 +1,3 @@ +{ +export_me; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/monomorph_1.c.sym b/tests/expectations-symbols/monomorph_1.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/monomorph_1.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/monomorph_2.c.sym b/tests/expectations-symbols/monomorph_2.c.sym new file mode 100644 index 000000000..5d8dd399d --- /dev/null +++ b/tests/expectations-symbols/monomorph_2.c.sym @@ -0,0 +1,4 @@ +{ +foo; +bar; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/monomorph_3.c.sym b/tests/expectations-symbols/monomorph_3.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/monomorph_3.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/must_use.c.sym b/tests/expectations-symbols/must_use.c.sym new file mode 100644 index 000000000..cd00b9a07 --- /dev/null +++ b/tests/expectations-symbols/must_use.c.sym @@ -0,0 +1,3 @@ +{ +maybe_consume; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/namespace_constant.c.sym b/tests/expectations-symbols/namespace_constant.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/namespace_constant.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/namespaces_constant.c.sym b/tests/expectations-symbols/namespaces_constant.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/namespaces_constant.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/no_includes.c.sym b/tests/expectations-symbols/no_includes.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/no_includes.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/non_pub_extern.c.sym b/tests/expectations-symbols/non_pub_extern.c.sym new file mode 100644 index 000000000..24baa8dc0 --- /dev/null +++ b/tests/expectations-symbols/non_pub_extern.c.sym @@ -0,0 +1,6 @@ +{ +first; +renamed; +FIRST; +RENAMED; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/nonnull.c.sym b/tests/expectations-symbols/nonnull.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/nonnull.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/nonnull_attribute.c.sym b/tests/expectations-symbols/nonnull_attribute.c.sym new file mode 100644 index 000000000..590d79578 --- /dev/null +++ b/tests/expectations-symbols/nonnull_attribute.c.sym @@ -0,0 +1,10 @@ +{ +value_arg; +mutltiple_args; +ref_arg; +mut_ref_arg; +optional_ref_arg; +optional_mut_ref_arg; +nullable_const_ptr; +nullable_mut_ptr; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/nonzero.c.sym b/tests/expectations-symbols/nonzero.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/nonzero.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/opaque.c.sym b/tests/expectations-symbols/opaque.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/opaque.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/pin.c.sym b/tests/expectations-symbols/pin.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/pin.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/pragma_once.c.sym b/tests/expectations-symbols/pragma_once.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/pragma_once.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/prefix.c.sym b/tests/expectations-symbols/prefix.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/prefix.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/prefixed_struct_literal.c.sym b/tests/expectations-symbols/prefixed_struct_literal.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/prefixed_struct_literal.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/prefixed_struct_literal_deep.c.sym b/tests/expectations-symbols/prefixed_struct_literal_deep.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/prefixed_struct_literal_deep.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/ptrs_as_arrays.c.sym b/tests/expectations-symbols/ptrs_as_arrays.c.sym new file mode 100644 index 000000000..2a5e603f8 --- /dev/null +++ b/tests/expectations-symbols/ptrs_as_arrays.c.sym @@ -0,0 +1,7 @@ +{ +ptr_as_array; +ptr_as_array1; +ptr_as_array2; +ptr_as_array_wrong_syntax; +ptr_as_array_unnamed; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/raw_ident.c.sym b/tests/expectations-symbols/raw_ident.c.sym new file mode 100644 index 000000000..08dfba6a1 --- /dev/null +++ b/tests/expectations-symbols/raw_ident.c.sym @@ -0,0 +1,4 @@ +{ +fn; +STATIC; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/raw_lines.c.sym b/tests/expectations-symbols/raw_lines.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/raw_lines.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/rename.c.sym b/tests/expectations-symbols/rename.c.sym new file mode 100644 index 000000000..e66806014 --- /dev/null +++ b/tests/expectations-symbols/rename.c.sym @@ -0,0 +1,4 @@ +{ +root; +G; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/rename_case.c.sym b/tests/expectations-symbols/rename_case.c.sym new file mode 100644 index 000000000..71d19dfd0 --- /dev/null +++ b/tests/expectations-symbols/rename_case.c.sym @@ -0,0 +1,7 @@ +{ +test_camel_case; +test_pascal_case; +test_snake_case; +test_screaming_snake_case; +test_gecko_case; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/rename_crate.c.sym b/tests/expectations-symbols/rename_crate.c.sym new file mode 100644 index 000000000..1baeb705c --- /dev/null +++ b/tests/expectations-symbols/rename_crate.c.sym @@ -0,0 +1,5 @@ +{ +root; +renamed_func; +no_extern_func; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/renaming_overrides_prefixing.c.sym b/tests/expectations-symbols/renaming_overrides_prefixing.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/renaming_overrides_prefixing.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/reserved.c.sym b/tests/expectations-symbols/reserved.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/reserved.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/sentinel.c.sym b/tests/expectations-symbols/sentinel.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/sentinel.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/simplify_option_ptr.c.sym b/tests/expectations-symbols/simplify_option_ptr.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/simplify_option_ptr.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/size_types.c.sym b/tests/expectations-symbols/size_types.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/size_types.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/static.c.sym b/tests/expectations-symbols/static.c.sym new file mode 100644 index 000000000..b43b3d0aa --- /dev/null +++ b/tests/expectations-symbols/static.c.sym @@ -0,0 +1,6 @@ +{ +root; +NUMBER; +FOO; +BAR; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/std_lib.c.sym b/tests/expectations-symbols/std_lib.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/std_lib.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/struct.c.sym b/tests/expectations-symbols/struct.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/struct.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/struct_literal.c.sym b/tests/expectations-symbols/struct_literal.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/struct_literal.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/struct_literal_order.c.sym b/tests/expectations-symbols/struct_literal_order.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/struct_literal_order.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/struct_self.c.sym b/tests/expectations-symbols/struct_self.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/struct_self.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/swift_name.c.sym b/tests/expectations-symbols/swift_name.c.sym new file mode 100644 index 000000000..4b70e6d45 --- /dev/null +++ b/tests/expectations-symbols/swift_name.c.sym @@ -0,0 +1,21 @@ +{ +rust_print_hello_world; +SelfTypeTestStruct_should_exist_ref; +SelfTypeTestStruct_should_exist_ref_mut; +SelfTypeTestStruct_should_not_exist_box; +SelfTypeTestStruct_should_not_exist_return_box; +SelfTypeTestStruct_should_exist_annotated_self; +SelfTypeTestStruct_should_exist_annotated_mut_self; +SelfTypeTestStruct_should_exist_annotated_by_name; +SelfTypeTestStruct_should_exist_annotated_mut_by_name; +SelfTypeTestStruct_should_exist_unannotated; +SelfTypeTestStruct_should_exist_mut_unannotated; +free_function_should_exist_ref; +free_function_should_exist_ref_mut; +unnamed_argument; +free_function_should_not_exist_box; +free_function_should_exist_annotated_by_name; +free_function_should_exist_annotated_mut_by_name; +PointerToOpaque_create; +PointerToOpaque_sayHello; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/transform_op.c.sym b/tests/expectations-symbols/transform_op.c.sym new file mode 100644 index 000000000..8d5c6388c --- /dev/null +++ b/tests/expectations-symbols/transform_op.c.sym @@ -0,0 +1,3 @@ +{ +foo; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/transparent.c.sym b/tests/expectations-symbols/transparent.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/transparent.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/typedef.c.sym b/tests/expectations-symbols/typedef.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/typedef.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/union.c.sym b/tests/expectations-symbols/union.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/union.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/union_self.c.sym b/tests/expectations-symbols/union_self.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/union_self.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/using_namespaces.c.sym b/tests/expectations-symbols/using_namespaces.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/using_namespaces.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/va_list.c.sym b/tests/expectations-symbols/va_list.c.sym new file mode 100644 index 000000000..bd09ae566 --- /dev/null +++ b/tests/expectations-symbols/va_list.c.sym @@ -0,0 +1,4 @@ +{ +va_list_test; +va_list_test2; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/workspace.c.sym b/tests/expectations-symbols/workspace.c.sym new file mode 100644 index 000000000..c203ccfa9 --- /dev/null +++ b/tests/expectations-symbols/workspace.c.sym @@ -0,0 +1,3 @@ +{ +consume_ext; +}; \ No newline at end of file diff --git a/tests/expectations-symbols/zst.c.sym b/tests/expectations-symbols/zst.c.sym new file mode 100644 index 000000000..f018156fc --- /dev/null +++ b/tests/expectations-symbols/zst.c.sym @@ -0,0 +1,3 @@ +{ +root; +}; \ No newline at end of file diff --git a/tests/tests.rs b/tests/tests.rs index 3846f326e..1679d6fc6 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,6 +1,7 @@ extern crate cbindgen; use cbindgen::*; +use tempfile::NamedTempFile; use std::collections::HashSet; use std::fs::File; use std::io::Read; @@ -19,6 +20,12 @@ fn style_str(style: Style) -> &'static str { } } +struct CBindgenOutput { + bindings_content: Vec, + depfile_content: Option, + symfile_content: Option, +} + fn run_cbindgen( path: &Path, output: Option<&Path>, @@ -26,20 +33,30 @@ fn run_cbindgen( cpp_compat: bool, style: Option