// runtime at all.
pub mod personalities {
#[no_mangle]
- #[cfg(not(all(target_os = "windows",
- target_env = "gnu",
- target_arch = "x86_64")))]
+ #[cfg(not(any(
+ target_arch = "wasm32",
+ all(
+ target_os = "windows",
+ target_env = "gnu",
+ target_arch = "x86_64",
+ ),
+ )))]
pub extern fn rust_eh_personality() {}
// On x86_64-pc-windows-gnu we use our own personality function that needs
Box::new(WasmLd {
cmd,
sess,
+ info: self
}) as Box<dyn Linker>
}
}
pub struct WasmLd<'a> {
cmd: Command,
sess: &'a Session,
+ info: &'a LinkerInfo,
}
impl<'a> Linker for WasmLd<'a> {
fn build_dylib(&mut self, _out_filename: &Path) {
}
- fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType) {
+ fn export_symbols(&mut self, _tmpdir: &Path, crate_type: CrateType) {
+ for sym in self.info.exports[&crate_type].iter() {
+ self.cmd.arg("--export").arg(&sym);
+ }
}
fn subsystem(&mut self, _subsystem: &str) {
--- /dev/null
+-include ../../run-make-fulldeps/tools.mk
+
+ifeq ($(TARGET),wasm32-unknown-unknown)
+all:
+ $(RUSTC) bar.rs --target wasm32-unknown-unknown
+ $(RUSTC) foo.rs --target wasm32-unknown-unknown
+ $(NODE) verify.js $(TMPDIR)/foo.wasm
+ $(RUSTC) bar.rs --target wasm32-unknown-unknown -O
+ $(RUSTC) foo.rs --target wasm32-unknown-unknown -O
+ $(NODE) verify.js $(TMPDIR)/foo.wasm
+ $(RUSTC) foo.rs --target wasm32-unknown-unknown -C lto
+ $(NODE) verify.js $(TMPDIR)/foo.wasm
+else
+all:
+endif
+
--- /dev/null
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type = "rlib"]
+
+#[no_mangle]
+pub extern fn foo() {}
--- /dev/null
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type = "cdylib"]
+
+extern crate bar;
--- /dev/null
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+const fs = require('fs');
+const process = require('process');
+const assert = require('assert');
+const buffer = fs.readFileSync(process.argv[2]);
+
+let m = new WebAssembly.Module(buffer);
+let list = WebAssembly.Module.exports(m);
+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 (nexports != 1)
+ throw new Error("should only have one function export");
+if (my_exports.foo === undefined)
+ throw new Error("`foo` wasn't defined");