Allow DSO export for C Rust bindings.
This option to the 'cxxbridge' command line tool allows
users to specify (for example)
__attribute__((visibility("default")))
or
__declspec(dllexport)
on C functions which may be exported from a shared object
as they may be required by Rust code in different binaries.
diff --git a/gen/src/write.rs b/gen/src/write.rs
index 46b6151..04d8e3e 100644
--- a/gen/src/write.rs
+++ b/gen/src/write.rs
@@ -86,13 +86,13 @@
out.begin_block("extern \"C\"");
write_exception_glue(out, apis);
for api in apis {
- let (efn, write): (_, fn(_, _, _)) = match api {
+ let (efn, write): (_, fn(_, _, _, _)) = match api {
Api::CxxFunction(efn) => (efn, write_cxx_function_shim),
Api::RustFunction(efn) => (efn, write_rust_function_decl),
_ => continue,
};
out.next_section();
- write(out, efn, types);
+ write(out, efn, types, &opt.cxx_impl_annotations);
}
out.end_block("extern \"C\"");
}
@@ -399,7 +399,17 @@
}
}
-fn write_cxx_function_shim(out: &mut OutFile, efn: &ExternFn, types: &Types) {
+fn write_cxx_function_shim(
+ out: &mut OutFile,
+ efn: &ExternFn,
+ types: &Types,
+ impl_annotations: &Option<String>,
+) {
+ if !out.header {
+ if let Some(annotation) = impl_annotations {
+ write!(out, "{} ", annotation);
+ }
+ }
if efn.throws {
write!(out, "::rust::Str::Repr ");
} else {
@@ -560,7 +570,7 @@
write_rust_function_shim_impl(out, &c_trampoline, f, types, &r_trampoline, indirect_call);
}
-fn write_rust_function_decl(out: &mut OutFile, efn: &ExternFn, types: &Types) {
+fn write_rust_function_decl(out: &mut OutFile, efn: &ExternFn, types: &Types, _: &Option<String>) {
let link_name = mangle::extern_fn(&out.namespace, efn);
let indirect_call = false;
write_rust_function_decl_impl(out, &link_name, efn, types, indirect_call);