mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-25 11:02:11 +03:00
Fix importing same types in two modules/crates
This'll hopefully fix fallout from 4f4da747ad
This commit is contained in:
parent
0f787e42f8
commit
85fd49f90a
@ -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,
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user