Fix importing same types in two modules/crates

This'll hopefully fix fallout from 4f4da747ad
This commit is contained in:
Alex Crichton 2018-08-27 09:59:47 -07:00
parent 0f787e42f8
commit 85fd49f90a
2 changed files with 16 additions and 0 deletions

View File

@ -24,6 +24,8 @@ pub struct Context<'a> {
pub typescript: String,
pub exposed_globals: HashSet<&'static str>,
pub required_internal_exports: HashSet<&'static str>,
pub imported_functions: HashSet<String>,
pub imported_statics: HashSet<String>,
pub config: &'a Bindgen,
pub module: &'a mut Module,
@ -1884,6 +1886,12 @@ impl<'a, 'b> SubContext<'a, 'b> {
info: &shared::Import,
import: &shared::ImportStatic,
) -> Result<(), Error> {
// The same static can be imported in multiple locations, so only
// generate bindings once for it.
if !self.cx.imported_statics.insert(import.shim.clone()) {
return Ok(())
}
// TODO: should support more types to import here
let obj = self.import_name(info, &import.name)?;
self.cx.expose_add_heap_object();
@ -1911,6 +1919,12 @@ impl<'a, 'b> SubContext<'a, 'b> {
return Ok(());
}
// It's possible for the same function to be imported in two locations,
// but we only want to generate one.
if !self.cx.imported_functions.insert(import.shim.clone()) {
return Ok(());
}
let descriptor = match self.cx.describe(&import.shim) {
None => return Ok(()),
Some(d) => d,

View File

@ -201,6 +201,8 @@ impl Bindgen {
function_table_needed: false,
interpreter: &mut instance,
memory_init: None,
imported_functions: Default::default(),
imported_statics: Default::default(),
};
for program in programs.iter() {
js::SubContext {