Skip to content

Commit

Permalink
Rollup merge of rust-lang#67975 - EmbarkStudios:export-statics-wasm, …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Centril authored Jan 9, 2020
2 parents b0e7653 + f1fb384 commit c8693fc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel
if is_extern && !std_internal {
let target = &tcx.sess.target.target.llvm_target;
// WebAssembly cannot export data symbols, so reduce their export level
if target.contains("wasm32") || target.contains("emscripten") {
if target.contains("emscripten") {
if let Some(Node::Item(&hir::Item { kind: hir::ItemKind::Static(..), .. })) =
tcx.hir().get_if_local(sym_def_id)
{
Expand Down
3 changes: 3 additions & 0 deletions src/test/run-make/wasm-export-all-symbols/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

#[no_mangle]
pub extern fn foo() {}

#[no_mangle]
pub static FOO: u64 = 42;
14 changes: 9 additions & 5 deletions src/test/run-make/wasm-export-all-symbols/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ console.log('exports', list);

const my_exports = {};
let nexports = 0;

for (const entry of list) {
if (entry.kind !== 'function')
continue;
my_exports[entry.name] = true;
nexports += 1;
if (entry.kind == 'function'){
nexports += 1;
}
my_exports[entry.name] = entry.kind;
}

if (my_exports.foo === undefined)
if (my_exports.foo != "function")
throw new Error("`foo` wasn't defined");

if (my_exports.FOO != "global")
throw new Error("`FOO` wasn't defined");

if (my_exports.main === undefined) {
if (nexports != 1)
throw new Error("should only have one function export");
Expand Down

0 comments on commit c8693fc

Please sign in to comment.