]> git.lizzy.rs Git - rust.git/blob - src/librustc_target/spec/wasm32_unknown_unknown.rs
Auto merge of #68414 - michaelwoerister:share-drop-glue, r=alexcrichton
[rust.git] / src / librustc_target / spec / wasm32_unknown_unknown.rs
1 //! A "bare wasm" target representing a WebAssembly output that makes zero
2 //! assumptions about its environment.
3 //!
4 //! The `wasm32-unknown-unknown` target is intended to encapsulate use cases
5 //! that do not rely on any imported functionality. The binaries generated are
6 //! entirely self-contained by default when using the standard library. Although
7 //! the standard library is available, most of it returns an error immediately
8 //! (e.g. trying to create a TCP stream or something like that).
9 //!
10 //! This target is more or less managed by the Rust and WebAssembly Working
11 //! Group nowadays at https://github.com/rustwasm.
12
13 use super::wasm32_base;
14 use super::{LinkerFlavor, LldFlavor, Target};
15
16 pub fn target() -> Result<Target, String> {
17     let mut options = wasm32_base::options();
18     let clang_args = options.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap();
19
20     // Make sure clang uses LLD as its linker and is configured appropriately
21     // otherwise
22     clang_args.push("--target=wasm32-unknown-unknown".to_string());
23
24     // Disable attempting to link crt1.o since it typically isn't present and
25     // isn't needed currently.
26     clang_args.push("-nostdlib".to_string());
27
28     // For now this target just never has an entry symbol no matter the output
29     // type, so unconditionally pass this.
30     clang_args.push("-Wl,--no-entry".to_string());
31     options
32         .pre_link_args
33         .get_mut(&LinkerFlavor::Lld(LldFlavor::Wasm))
34         .unwrap()
35         .push("--no-entry".to_string());
36
37     Ok(Target {
38         llvm_target: "wasm32-unknown-unknown".to_string(),
39         target_endian: "little".to_string(),
40         target_pointer_width: "32".to_string(),
41         target_c_int_width: "32".to_string(),
42         target_os: "unknown".to_string(),
43         target_env: String::new(),
44         target_vendor: "unknown".to_string(),
45         data_layout: "e-m:e-p:32:32-i64:64-n32:64-S128".to_string(),
46         arch: "wasm32".to_string(),
47         linker_flavor: LinkerFlavor::Lld(LldFlavor::Wasm),
48         options,
49     })
50 }