2019-03-19 13:06:37 -07:00
|
|
|
//! A "bare wasm" target representing a WebAssembly output that makes zero
|
|
|
|
|
//! assumptions about its environment.
|
|
|
|
|
//!
|
|
|
|
|
//! The `wasm32-unknown-unknown` target is intended to encapsulate use cases
|
|
|
|
|
//! that do not rely on any imported functionality. The binaries generated are
|
|
|
|
|
//! entirely self-contained by default when using the standard library. Although
|
|
|
|
|
//! the standard library is available, most of it returns an error immediately
|
|
|
|
|
//! (e.g. trying to create a TCP stream or something like that).
|
|
|
|
|
//!
|
|
|
|
|
//! This target is more or less managed by the Rust and WebAssembly Working
|
2020-10-14 17:35:43 +02:00
|
|
|
//! Group nowadays at <https://github.com/rustwasm>.
|
2019-03-19 13:06:37 -07:00
|
|
|
|
2020-12-30 12:52:21 -06:00
|
|
|
use super::wasm_base;
|
2019-12-22 17:42:04 -05:00
|
|
|
use super::{LinkerFlavor, LldFlavor, Target};
|
2017-10-22 20:01:00 -07:00
|
|
|
|
2020-10-05 15:37:55 +03:00
|
|
|
pub fn target() -> Target {
|
2020-12-30 12:52:21 -06:00
|
|
|
let mut options = wasm_base::options();
|
2020-11-08 14:57:55 +03:00
|
|
|
options.os = "unknown".to_string();
|
2020-10-08 22:22:28 +03:00
|
|
|
options.linker_flavor = LinkerFlavor::Lld(LldFlavor::Wasm);
|
2021-03-28 02:21:36 +03:00
|
|
|
let clang_args = options.pre_link_args.entry(LinkerFlavor::Gcc).or_default();
|
2017-10-22 20:01:00 -07:00
|
|
|
|
2019-03-19 13:06:37 -07:00
|
|
|
// Make sure clang uses LLD as its linker and is configured appropriately
|
|
|
|
|
// otherwise
|
|
|
|
|
clang_args.push("--target=wasm32-unknown-unknown".to_string());
|
2018-01-30 11:54:07 -08:00
|
|
|
|
2019-03-19 13:06:37 -07:00
|
|
|
// For now this target just never has an entry symbol no matter the output
|
|
|
|
|
// type, so unconditionally pass this.
|
|
|
|
|
clang_args.push("-Wl,--no-entry".to_string());
|
2021-01-21 15:58:50 -08:00
|
|
|
|
|
|
|
|
// Rust really needs a way for users to specify exports and imports in
|
|
|
|
|
// the source code. --export-dynamic isn't the right tool for this job,
|
|
|
|
|
// however it does have the side effect of automatically exporting a lot
|
|
|
|
|
// of symbols, which approximates what people want when compiling for
|
|
|
|
|
// wasm32-unknown-unknown expect, so use it for now.
|
|
|
|
|
clang_args.push("-Wl,--export-dynamic".to_string());
|
|
|
|
|
|
|
|
|
|
// Add the flags to wasm-ld's args too.
|
2021-03-28 02:21:36 +03:00
|
|
|
let lld_args = options.pre_link_args.entry(LinkerFlavor::Lld(LldFlavor::Wasm)).or_default();
|
2021-01-21 15:58:50 -08:00
|
|
|
lld_args.push("--no-entry".to_string());
|
|
|
|
|
lld_args.push("--export-dynamic".to_string());
|
2018-10-12 17:04:31 -07:00
|
|
|
|
2020-10-05 15:37:55 +03:00
|
|
|
Target {
|
2018-06-01 10:20:00 -07:00
|
|
|
llvm_target: "wasm32-unknown-unknown".to_string(),
|
2020-10-14 18:08:12 +02:00
|
|
|
pointer_width: 32,
|
2017-10-22 20:01:00 -07:00
|
|
|
data_layout: "e-m:e-p:32:32-i64:64-n32:64-S128".to_string(),
|
|
|
|
|
arch: "wasm32".to_string(),
|
2019-03-19 13:06:37 -07:00
|
|
|
options,
|
2020-10-05 15:37:55 +03:00
|
|
|
}
|
2017-10-22 20:01:00 -07:00
|
|
|
}
|