未验证 提交 8de73bc1 编写于 作者: Y Yuki Okushi 提交者: GitHub

Rollup merge of #67975 - EmbarkStudios:export-statics-wasm, r=alexcrichton

Export public scalar statics in wasm

Fixes #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.
......@@ -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)
{
......
......@@ -2,3 +2,6 @@
#[no_mangle]
pub extern fn foo() {}
#[no_mangle]
pub static FOO: u64 = 42;
......@@ -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");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册