@@ -24,6 +24,8 @@ pub struct Context<'a> {
24
24
pub typescript : String ,
25
25
pub exposed_globals : HashSet < & ' static str > ,
26
26
pub required_internal_exports : HashSet < & ' static str > ,
27
+ pub imported_functions : HashSet < String > ,
28
+ pub imported_statics : HashSet < String > ,
27
29
pub config : & ' a Bindgen ,
28
30
pub module : & ' a mut Module ,
29
31
@@ -1884,6 +1886,12 @@ impl<'a, 'b> SubContext<'a, 'b> {
1884
1886
info : & shared:: Import ,
1885
1887
import : & shared:: ImportStatic ,
1886
1888
) -> 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
+
1887
1895
// TODO: should support more types to import here
1888
1896
let obj = self . import_name ( info, & import. name ) ?;
1889
1897
self . cx . expose_add_heap_object ( ) ;
@@ -1911,6 +1919,12 @@ impl<'a, 'b> SubContext<'a, 'b> {
1911
1919
return Ok ( ( ) ) ;
1912
1920
}
1913
1921
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
+
1914
1928
let descriptor = match self . cx . describe ( & import. shim ) {
1915
1929
None => return Ok ( ( ) ) ,
1916
1930
Some ( d) => d,
0 commit comments