Skip to content

Commit c14bc57

Browse files
committed
Don't export non-function symbols with emscripten
Emscripten only provides an export mechanism for functions. Exporting statics does not make sense conceptually in this case, and will result in emcc undefined function errors.
1 parent 131fda4 commit c14bc57

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/librustc_codegen_utils/symbol_export.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,16 @@ fn symbol_export_level(tcx: TyCtxt, sym_def_id: DefId) -> SymbolExportLevel {
388388
codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
389389

390390
if is_extern && !std_internal {
391+
// Emscripten cannot export statics, so reduce their export level here
392+
if tcx.sess.target.target.options.is_like_emscripten {
393+
if let Some(Node::Item(&hir::Item {
394+
node: hir::ItemKind::Static(..),
395+
..
396+
})) = tcx.hir.get_if_local(sym_def_id) {
397+
return SymbolExportLevel::Rust;
398+
}
399+
}
400+
391401
SymbolExportLevel::C
392402
} else {
393403
SymbolExportLevel::Rust

0 commit comments

Comments
 (0)