]> git.lizzy.rs Git - rust.git/blob - src/librustc_target/spec/wasm32_unknown_unknown.rs
Auto merge of #57925 - fintelia:riscv-cas, r=nagisa
[rust.git] / src / librustc_target / spec / wasm32_unknown_unknown.rs
1 // The wasm32-unknown-unknown target is currently an experimental version of a
2 // wasm-based target which does *not* use the Emscripten toolchain. Instead
3 // this toolchain is based purely on LLVM's own toolchain, using LLVM's native
4 // WebAssembly backend as well as LLD for a native linker.
5 //
6 // There's some trickery below on crate types supported and various defaults
7 // (aka panic=abort by default), but otherwise this is in general a relatively
8 // standard target.
9
10 use super::{LldFlavor, LinkerFlavor, Target, TargetOptions, PanicStrategy};
11
12 pub fn target() -> Result<Target, String> {
13     let opts = TargetOptions {
14         // we allow dynamic linking, but only cdylibs. Basically we allow a
15         // final library artifact that exports some symbols (a wasm module) but
16         // we don't allow intermediate `dylib` crate types
17         dynamic_linking: true,
18         only_cdylib: true,
19
20         // This means we'll just embed a `start` function in the wasm module
21         executables: true,
22
23         // relatively self-explanatory!
24         exe_suffix: ".wasm".to_string(),
25         dll_prefix: String::new(),
26         dll_suffix: ".wasm".to_string(),
27         linker_is_gnu: false,
28
29         max_atomic_width: Some(64),
30
31         // Unwinding doesn't work right now, so the whole target unconditionally
32         // defaults to panic=abort. Note that this is guaranteed to change in
33         // the future once unwinding is implemented. Don't rely on this.
34         panic_strategy: PanicStrategy::Abort,
35
36         // Wasm doesn't have atomics yet, so tell LLVM that we're in a single
37         // threaded model which will legalize atomics to normal operations.
38         singlethread: true,
39
40         // no dynamic linking, no need for default visibility!
41         default_hidden_visibility: true,
42
43         // we use the LLD shipped with the Rust toolchain by default
44         linker: Some("rust-lld".to_owned()),
45         lld_flavor: LldFlavor::Wasm,
46
47         // No need for indirection here, simd types can always be passed by
48         // value as the whole module either has simd or not, which is different
49         // from x86 (for example) where programs can have functions that don't
50         // enable simd features.
51         simd_types_indirect: false,
52
53         .. Default::default()
54     };
55     Ok(Target {
56         llvm_target: "wasm32-unknown-unknown".to_string(),
57         target_endian: "little".to_string(),
58         target_pointer_width: "32".to_string(),
59         target_c_int_width: "32".to_string(),
60         // This is basically guaranteed to change in the future, don't rely on
61         // this. Use `not(target_os = "emscripten")` for now.
62         target_os: "unknown".to_string(),
63         target_env: String::new(),
64         target_vendor: "unknown".to_string(),
65         data_layout: "e-m:e-p:32:32-i64:64-n32:64-S128".to_string(),
66         arch: "wasm32".to_string(),
67         linker_flavor: LinkerFlavor::Lld(LldFlavor::Wasm),
68         options: opts,
69     })
70 }