Skip to content

Commit 85fd49f

Browse files
committed
Fix importing same types in two modules/crates
This'll hopefully fix fallout from 4f4da74
1 parent 0f787e4 commit 85fd49f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

crates/cli-support/src/js/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub struct Context<'a> {
2424
pub typescript: String,
2525
pub exposed_globals: HashSet<&'static str>,
2626
pub required_internal_exports: HashSet<&'static str>,
27+
pub imported_functions: HashSet<String>,
28+
pub imported_statics: HashSet<String>,
2729
pub config: &'a Bindgen,
2830
pub module: &'a mut Module,
2931

@@ -1884,6 +1886,12 @@ impl<'a, 'b> SubContext<'a, 'b> {
18841886
info: &shared::Import,
18851887
import: &shared::ImportStatic,
18861888
) -> Result<(), Error> {
1889+
// The same static can be imported in multiple locations, so only
1890+
// generate bindings once for it.
1891+
if !self.cx.imported_statics.insert(import.shim.clone()) {
1892+
return Ok(())
1893+
}
1894+
18871895
// TODO: should support more types to import here
18881896
let obj = self.import_name(info, &import.name)?;
18891897
self.cx.expose_add_heap_object();
@@ -1911,6 +1919,12 @@ impl<'a, 'b> SubContext<'a, 'b> {
19111919
return Ok(());
19121920
}
19131921

1922+
// It's possible for the same function to be imported in two locations,
1923+
// but we only want to generate one.
1924+
if !self.cx.imported_functions.insert(import.shim.clone()) {
1925+
return Ok(());
1926+
}
1927+
19141928
let descriptor = match self.cx.describe(&import.shim) {
19151929
None => return Ok(()),
19161930
Some(d) => d,

crates/cli-support/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ impl Bindgen {
201201
function_table_needed: false,
202202
interpreter: &mut instance,
203203
memory_init: None,
204+
imported_functions: Default::default(),
205+
imported_statics: Default::default(),
204206
};
205207
for program in programs.iter() {
206208
js::SubContext {

0 commit comments

Comments
 (0)