Skip to content

Commit 8de73bc

Browse files
authored
Rollup merge of rust-lang#67975 - EmbarkStudios:export-statics-wasm, r=alexcrichton
Export public scalar statics in wasm Fixes rust-lang#67453 I am not sure which export level statics should get when exporting them in wasm. This small change fixes the issue that I had, but this might not be the correct way to implement this.
2 parents 08c5999 + f1fb384 commit 8de73bc

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/librustc_codegen_ssa/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel
345345
if is_extern && !std_internal {
346346
let target = &tcx.sess.target.target.llvm_target;
347347
// WebAssembly cannot export data symbols, so reduce their export level
348-
if target.contains("wasm32") || target.contains("emscripten") {
348+
if target.contains("emscripten") {
349349
if let Some(Node::Item(&hir::Item { kind: hir::ItemKind::Static(..), .. })) =
350350
tcx.hir().get_if_local(sym_def_id)
351351
{

src/test/run-make/wasm-export-all-symbols/bar.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
#[no_mangle]
44
pub extern fn foo() {}
5+
6+
#[no_mangle]
7+
pub static FOO: u64 = 42;

src/test/run-make/wasm-export-all-symbols/verify.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ console.log('exports', list);
99

1010
const my_exports = {};
1111
let nexports = 0;
12+
1213
for (const entry of list) {
13-
if (entry.kind !== 'function')
14-
continue;
15-
my_exports[entry.name] = true;
16-
nexports += 1;
14+
if (entry.kind == 'function'){
15+
nexports += 1;
16+
}
17+
my_exports[entry.name] = entry.kind;
1718
}
1819

19-
if (my_exports.foo === undefined)
20+
if (my_exports.foo != "function")
2021
throw new Error("`foo` wasn't defined");
2122

23+
if (my_exports.FOO != "global")
24+
throw new Error("`FOO` wasn't defined");
25+
2226
if (my_exports.main === undefined) {
2327
if (nexports != 1)
2428
throw new Error("should only have one function export");

0 commit comments

Comments
 (0)