Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b8b50f0

Browse files
committedSep 30, 2016
Preliminary wasm32 support
1 parent b2dfeac commit b8b50f0

File tree

13 files changed

+107
-18
lines changed

13 files changed

+107
-18
lines changed
 

‎mk/cfg/wasm32-unknown-emscripten.mk

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# wasm32-unknown-emscripten configuration
2+
CC_wasm32-unknown-emscripten=emcc
3+
CXX_wasm32-unknown-emscripten=em++
4+
CPP_wasm32-unknown-emscripten=$(CPP)
5+
AR_wasm32-unknown-emscripten=emar
6+
CFG_LIB_NAME_wasm32-unknown-emscripten=lib$(1).so
7+
CFG_STATIC_LIB_NAME_wasm32-unknown-emscripten=lib$(1).a
8+
CFG_LIB_GLOB_wasm32-unknown-emscripten=lib$(1)-*.so
9+
CFG_LIB_DSYM_GLOB_wasm32-unknown-emscripten=lib$(1)-*.dylib.dSYM
10+
CFG_JEMALLOC_CFLAGS_wasm32-unknown-emscripten := -m32 $(CFLAGS)
11+
CFG_GCCISH_CFLAGS_wasm32-unknown-emscripten := -g -fPIC -m32 -s BINARYEN=1 $(CFLAGS)
12+
CFG_GCCISH_CXXFLAGS_wasm32-unknown-emscripten := -fno-rtti -s BINARYEN=1 $(CXXFLAGS)
13+
CFG_GCCISH_LINK_FLAGS_wasm32-unknown-emscripten := -shared -fPIC -ldl -pthread -lrt -g -m32 -s BINARYEN=1
14+
CFG_GCCISH_DEF_FLAG_wasm32-unknown-emscripten := -Wl,--export-dynamic,--dynamic-list=
15+
CFG_LLC_FLAGS_wasm32-unknown-emscripten :=
16+
CFG_INSTALL_NAME_wasm32-unknown-emscripten =
17+
CFG_EXE_SUFFIX_wasm32-unknown-emscripten =
18+
CFG_WINDOWSY_wasm32-unknown-emscripten :=
19+
CFG_UNIXY_wasm32-unknown-emscripten := 1
20+
CFG_LDPATH_wasm32-unknown-emscripten :=
21+
CFG_RUN_wasm32-unknown-emscripten=$(2)
22+
CFG_RUN_TARG_wasm32-unknown-emscripten=$(call CFG_RUN_wasm32-unknown-emscripten,,$(2))
23+
CFG_GNU_TRIPLE_wasm32-unknown-emscripten := wasm32-unknown-emscripten
24+
CFG_DISABLE_JEMALLOC_wasm32-unknown-emscripten := 1

‎src/bootstrap/check.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ pub fn krate(build: &Build,
323323
if target.contains("android") {
324324
build.run(cargo.arg("--no-run"));
325325
krate_android(build, compiler, target, mode);
326-
} else if target.contains("asmjs") {
326+
} else if target.contains("emscripten") {
327327
build.run(cargo.arg("--no-run"));
328-
krate_asmjs(build, compiler, target, mode);
328+
krate_emscripten(build, compiler, target, mode);
329329
} else {
330330
cargo.args(&build.flags.args);
331331
build.run(&mut cargo);
@@ -374,10 +374,10 @@ fn krate_android(build: &Build,
374374
}
375375
}
376376

377-
fn krate_asmjs(build: &Build,
378-
compiler: &Compiler,
379-
target: &str,
380-
mode: Mode) {
377+
fn krate_emscripten(build: &Build,
378+
compiler: &Compiler,
379+
target: &str,
380+
mode: Mode) {
381381
let mut tests = Vec::new();
382382
let out_dir = build.cargo_out(compiler, mode, target);
383383
find_tests(&out_dir, target, &mut tests);

‎src/liballoc_system/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
target_arch = "mips",
3030
target_arch = "powerpc",
3131
target_arch = "powerpc64",
32-
target_arch = "asmjs")))]
32+
target_arch = "asmjs",
33+
target_arch = "wasm32")))]
3334
const MIN_ALIGN: usize = 8;
3435
#[cfg(all(any(target_arch = "x86_64",
3536
target_arch = "aarch64",

‎src/libpanic_unwind/gcc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ const UNWIND_DATA_REG: (i32, i32) = (6, 7); // R6, R7
139139
#[cfg(target_arch = "asmjs")]
140140
const UNWIND_DATA_REG: (i32, i32) = (0, 2); // EAX, EDX
141141

142+
// FIXME: Ditto the above
143+
#[cfg(target_arch = "wasm32")]
144+
const UNWIND_DATA_REG: (i32, i32) = (0, 2); // EAX, EDX
145+
142146
// The following code is based on GCC's C and C++ personality routines. For reference, see:
143147
// https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/libsupc++/eh_personality.cc
144148
// https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c

‎src/librustc_back/target/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ supported_targets! {
190190
("i586-pc-windows-msvc", i586_pc_windows_msvc),
191191

192192
("le32-unknown-nacl", le32_unknown_nacl),
193-
("asmjs-unknown-emscripten", asmjs_unknown_emscripten)
193+
("asmjs-unknown-emscripten", asmjs_unknown_emscripten),
194+
("wasm32-unknown-emscripten", wasm32_unknown_emscripten)
194195
}
195196

196197
/// Everything `rustc` knows about how to compile for a specific target.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use super::{Target, TargetOptions};
12+
13+
pub fn target() -> Result<Target, String> {
14+
let opts = TargetOptions {
15+
linker: "emcc".to_string(),
16+
ar: "emar".to_string(),
17+
18+
dynamic_linking: false,
19+
executables: true,
20+
// Today emcc emits two files - a .js file to bootstrap and
21+
// possibly interpret the wasm, and a .wasm file
22+
exe_suffix: ".js".to_string(),
23+
linker_is_gnu: true,
24+
allow_asm: false,
25+
obj_is_bitcode: true,
26+
max_atomic_width: 32,
27+
post_link_args: vec!["-s".to_string(), "BINARYEN=1".to_string()],
28+
.. Default::default()
29+
};
30+
Ok(Target {
31+
llvm_target: "asmjs-unknown-emscripten".to_string(),
32+
target_endian: "little".to_string(),
33+
target_pointer_width: "32".to_string(),
34+
target_os: "emscripten".to_string(),
35+
target_env: "".to_string(),
36+
target_vendor: "unknown".to_string(),
37+
data_layout: "e-p:32:32-i64:64-v128:32:128-n32-S128".to_string(),
38+
arch: "wasm32".to_string(),
39+
options: opts,
40+
})
41+
}

‎src/librustc_trans/abi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ impl FnType {
519519
"powerpc64" => cabi_powerpc64::compute_abi_info(ccx, self),
520520
"s390x" => cabi_s390x::compute_abi_info(ccx, self),
521521
"asmjs" => cabi_asmjs::compute_abi_info(ccx, self),
522+
"wasm32" => cabi_asmjs::compute_abi_info(ccx, self),
522523
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a))
523524
}
524525

‎src/libstd/env.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,18 @@ mod os {
892892
pub const EXE_EXTENSION: &'static str = "pexe";
893893
}
894894

895-
#[cfg(target_os = "emscripten")]
895+
#[cfg(all(target_os = "emscripten", target_arch = "asmjs"))]
896+
mod os {
897+
pub const FAMILY: &'static str = "unix";
898+
pub const OS: &'static str = "emscripten";
899+
pub const DLL_PREFIX: &'static str = "lib";
900+
pub const DLL_SUFFIX: &'static str = ".so";
901+
pub const DLL_EXTENSION: &'static str = "so";
902+
pub const EXE_SUFFIX: &'static str = ".js";
903+
pub const EXE_EXTENSION: &'static str = "js";
904+
}
905+
906+
#[cfg(all(target_os = "emscripten", target_arch = "wasm32"))]
896907
mod os {
897908
pub const FAMILY: &'static str = "unix";
898909
pub const OS: &'static str = "emscripten";
@@ -969,6 +980,11 @@ mod arch {
969980
pub const ARCH: &'static str = "asmjs";
970981
}
971982

983+
#[cfg(target_arch = "wasm32")]
984+
mod arch {
985+
pub const ARCH: &'static str = "wasm32";
986+
}
987+
972988
#[cfg(test)]
973989
mod tests {
974990
use super::*;

‎src/libstd/os/linux/raw.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ pub use self::arch::{off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t};
3434
target_arch = "le32",
3535
target_arch = "powerpc",
3636
target_arch = "arm",
37-
target_arch = "asmjs"))]
37+
target_arch = "asmjs",
38+
target_arch = "wasm32"))]
3839
mod arch {
3940
use os::raw::{c_long, c_short, c_uint};
4041

‎src/libtest/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,15 +1291,15 @@ impl MetricMap {
12911291
///
12921292
/// This function is a no-op, and does not even read from `dummy`.
12931293
#[cfg(not(any(all(target_os = "nacl", target_arch = "le32"),
1294-
target_arch = "asmjs")))]
1294+
target_arch = "asmjs", target_arch = "wasm32")))]
12951295
pub fn black_box<T>(dummy: T) -> T {
12961296
// we need to "use" the argument in some way LLVM can't
12971297
// introspect.
12981298
unsafe { asm!("" : : "r"(&dummy)) }
12991299
dummy
13001300
}
13011301
#[cfg(any(all(target_os = "nacl", target_arch = "le32"),
1302-
target_arch = "asmjs"))]
1302+
target_arch = "asmjs", target_arch = "wasm32"))]
13031303
#[inline(never)]
13041304
pub fn black_box<T>(dummy: T) -> T {
13051305
dummy

‎src/libunwind/libunwind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub const unwinder_private_data_size: usize = 2;
6565
#[cfg(target_arch = "s390x")]
6666
pub const unwinder_private_data_size: usize = 2;
6767

68-
#[cfg(target_arch = "asmjs")]
68+
#[cfg(any(target_arch = "asmjs", target_arch = "wasm32"))]
6969
pub const unwinder_private_data_size: usize = 20;
7070

7171
#[repr(C)]

‎src/tools/compiletest/src/runtest.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,6 @@ actual:\n\
11681168
"arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => {
11691169
self._arm_exec_compiled_test(env)
11701170
}
1171-
11721171
_=> {
11731172
let aux_dir = self.aux_output_dir_name();
11741173
self.compose_and_run(self.make_run_args(),
@@ -1421,7 +1420,7 @@ actual:\n\
14211420
fn make_exe_name(&self) -> PathBuf {
14221421
let mut f = self.output_base_name();
14231422
// FIXME: This is using the host architecture exe suffix, not target!
1424-
if self.config.target == "asmjs-unknown-emscripten" {
1423+
if self.config.target.contains("emscripten") {
14251424
let mut fname = f.file_name().unwrap().to_os_string();
14261425
fname.push(".js");
14271426
f.set_file_name(&fname);
@@ -1439,8 +1438,8 @@ actual:\n\
14391438
let mut args = self.split_maybe_args(&self.config.runtool);
14401439

14411440
// If this is emscripten, then run tests under nodejs
1442-
if self.config.target == "asmjs-unknown-emscripten" {
1443-
args.push("nodejs".to_owned());
1441+
if self.config.target.contains("emscripten") {
1442+
args.push("node".to_owned());
14441443
}
14451444

14461445
let exe_file = self.make_exe_name();

‎src/tools/compiletest/src/util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[("aarch64", "aarch
4343
("sparc", "sparc"),
4444
("x86_64", "x86_64"),
4545
("xcore", "xcore"),
46-
("asmjs", "asmjs")];
46+
("asmjs", "asmjs"),
47+
("wasm32", "wasm32")];
4748

4849
pub fn get_os(triple: &str) -> &'static str {
4950
for &(triple_os, os) in OS_TABLE {

0 commit comments

Comments
 (0)
Please sign in to comment.