Preliminary wasm32 support
This commit is contained in:
parent
b2dfeac690
commit
b8b50f0eda
13 changed files with 107 additions and 18 deletions
24
mk/cfg/wasm32-unknown-emscripten.mk
Normal file
24
mk/cfg/wasm32-unknown-emscripten.mk
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# wasm32-unknown-emscripten configuration
|
||||||
|
CC_wasm32-unknown-emscripten=emcc
|
||||||
|
CXX_wasm32-unknown-emscripten=em++
|
||||||
|
CPP_wasm32-unknown-emscripten=$(CPP)
|
||||||
|
AR_wasm32-unknown-emscripten=emar
|
||||||
|
CFG_LIB_NAME_wasm32-unknown-emscripten=lib$(1).so
|
||||||
|
CFG_STATIC_LIB_NAME_wasm32-unknown-emscripten=lib$(1).a
|
||||||
|
CFG_LIB_GLOB_wasm32-unknown-emscripten=lib$(1)-*.so
|
||||||
|
CFG_LIB_DSYM_GLOB_wasm32-unknown-emscripten=lib$(1)-*.dylib.dSYM
|
||||||
|
CFG_JEMALLOC_CFLAGS_wasm32-unknown-emscripten := -m32 $(CFLAGS)
|
||||||
|
CFG_GCCISH_CFLAGS_wasm32-unknown-emscripten := -g -fPIC -m32 -s BINARYEN=1 $(CFLAGS)
|
||||||
|
CFG_GCCISH_CXXFLAGS_wasm32-unknown-emscripten := -fno-rtti -s BINARYEN=1 $(CXXFLAGS)
|
||||||
|
CFG_GCCISH_LINK_FLAGS_wasm32-unknown-emscripten := -shared -fPIC -ldl -pthread -lrt -g -m32 -s BINARYEN=1
|
||||||
|
CFG_GCCISH_DEF_FLAG_wasm32-unknown-emscripten := -Wl,--export-dynamic,--dynamic-list=
|
||||||
|
CFG_LLC_FLAGS_wasm32-unknown-emscripten :=
|
||||||
|
CFG_INSTALL_NAME_wasm32-unknown-emscripten =
|
||||||
|
CFG_EXE_SUFFIX_wasm32-unknown-emscripten =
|
||||||
|
CFG_WINDOWSY_wasm32-unknown-emscripten :=
|
||||||
|
CFG_UNIXY_wasm32-unknown-emscripten := 1
|
||||||
|
CFG_LDPATH_wasm32-unknown-emscripten :=
|
||||||
|
CFG_RUN_wasm32-unknown-emscripten=$(2)
|
||||||
|
CFG_RUN_TARG_wasm32-unknown-emscripten=$(call CFG_RUN_wasm32-unknown-emscripten,,$(2))
|
||||||
|
CFG_GNU_TRIPLE_wasm32-unknown-emscripten := wasm32-unknown-emscripten
|
||||||
|
CFG_DISABLE_JEMALLOC_wasm32-unknown-emscripten := 1
|
|
@ -323,9 +323,9 @@ pub fn krate(build: &Build,
|
||||||
if target.contains("android") {
|
if target.contains("android") {
|
||||||
build.run(cargo.arg("--no-run"));
|
build.run(cargo.arg("--no-run"));
|
||||||
krate_android(build, compiler, target, mode);
|
krate_android(build, compiler, target, mode);
|
||||||
} else if target.contains("asmjs") {
|
} else if target.contains("emscripten") {
|
||||||
build.run(cargo.arg("--no-run"));
|
build.run(cargo.arg("--no-run"));
|
||||||
krate_asmjs(build, compiler, target, mode);
|
krate_emscripten(build, compiler, target, mode);
|
||||||
} else {
|
} else {
|
||||||
cargo.args(&build.flags.args);
|
cargo.args(&build.flags.args);
|
||||||
build.run(&mut cargo);
|
build.run(&mut cargo);
|
||||||
|
@ -374,10 +374,10 @@ fn krate_android(build: &Build,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn krate_asmjs(build: &Build,
|
fn krate_emscripten(build: &Build,
|
||||||
compiler: &Compiler,
|
compiler: &Compiler,
|
||||||
target: &str,
|
target: &str,
|
||||||
mode: Mode) {
|
mode: Mode) {
|
||||||
let mut tests = Vec::new();
|
let mut tests = Vec::new();
|
||||||
let out_dir = build.cargo_out(compiler, mode, target);
|
let out_dir = build.cargo_out(compiler, mode, target);
|
||||||
find_tests(&out_dir, target, &mut tests);
|
find_tests(&out_dir, target, &mut tests);
|
||||||
|
|
|
@ -29,7 +29,8 @@
|
||||||
target_arch = "mips",
|
target_arch = "mips",
|
||||||
target_arch = "powerpc",
|
target_arch = "powerpc",
|
||||||
target_arch = "powerpc64",
|
target_arch = "powerpc64",
|
||||||
target_arch = "asmjs")))]
|
target_arch = "asmjs",
|
||||||
|
target_arch = "wasm32")))]
|
||||||
const MIN_ALIGN: usize = 8;
|
const MIN_ALIGN: usize = 8;
|
||||||
#[cfg(all(any(target_arch = "x86_64",
|
#[cfg(all(any(target_arch = "x86_64",
|
||||||
target_arch = "aarch64",
|
target_arch = "aarch64",
|
||||||
|
|
|
@ -139,6 +139,10 @@ const UNWIND_DATA_REG: (i32, i32) = (6, 7); // R6, R7
|
||||||
#[cfg(target_arch = "asmjs")]
|
#[cfg(target_arch = "asmjs")]
|
||||||
const UNWIND_DATA_REG: (i32, i32) = (0, 2); // EAX, EDX
|
const UNWIND_DATA_REG: (i32, i32) = (0, 2); // EAX, EDX
|
||||||
|
|
||||||
|
// FIXME: Ditto the above
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
const UNWIND_DATA_REG: (i32, i32) = (0, 2); // EAX, EDX
|
||||||
|
|
||||||
// The following code is based on GCC's C and C++ personality routines. For reference, see:
|
// The following code is based on GCC's C and C++ personality routines. For reference, see:
|
||||||
// https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/libsupc++/eh_personality.cc
|
// https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/libsupc++/eh_personality.cc
|
||||||
// https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c
|
// https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c
|
||||||
|
|
|
@ -190,7 +190,8 @@ supported_targets! {
|
||||||
("i586-pc-windows-msvc", i586_pc_windows_msvc),
|
("i586-pc-windows-msvc", i586_pc_windows_msvc),
|
||||||
|
|
||||||
("le32-unknown-nacl", le32_unknown_nacl),
|
("le32-unknown-nacl", le32_unknown_nacl),
|
||||||
("asmjs-unknown-emscripten", asmjs_unknown_emscripten)
|
("asmjs-unknown-emscripten", asmjs_unknown_emscripten),
|
||||||
|
("wasm32-unknown-emscripten", wasm32_unknown_emscripten)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Everything `rustc` knows about how to compile for a specific target.
|
/// Everything `rustc` knows about how to compile for a specific target.
|
||||||
|
|
41
src/librustc_back/target/wasm32_unknown_emscripten.rs
Normal file
41
src/librustc_back/target/wasm32_unknown_emscripten.rs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
// Copyright 2015 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.
|
||||||
|
|
||||||
|
use super::{Target, TargetOptions};
|
||||||
|
|
||||||
|
pub fn target() -> Result<Target, String> {
|
||||||
|
let opts = TargetOptions {
|
||||||
|
linker: "emcc".to_string(),
|
||||||
|
ar: "emar".to_string(),
|
||||||
|
|
||||||
|
dynamic_linking: false,
|
||||||
|
executables: true,
|
||||||
|
// Today emcc emits two files - a .js file to bootstrap and
|
||||||
|
// possibly interpret the wasm, and a .wasm file
|
||||||
|
exe_suffix: ".js".to_string(),
|
||||||
|
linker_is_gnu: true,
|
||||||
|
allow_asm: false,
|
||||||
|
obj_is_bitcode: true,
|
||||||
|
max_atomic_width: 32,
|
||||||
|
post_link_args: vec!["-s".to_string(), "BINARYEN=1".to_string()],
|
||||||
|
.. Default::default()
|
||||||
|
};
|
||||||
|
Ok(Target {
|
||||||
|
llvm_target: "asmjs-unknown-emscripten".to_string(),
|
||||||
|
target_endian: "little".to_string(),
|
||||||
|
target_pointer_width: "32".to_string(),
|
||||||
|
target_os: "emscripten".to_string(),
|
||||||
|
target_env: "".to_string(),
|
||||||
|
target_vendor: "unknown".to_string(),
|
||||||
|
data_layout: "e-p:32:32-i64:64-v128:32:128-n32-S128".to_string(),
|
||||||
|
arch: "wasm32".to_string(),
|
||||||
|
options: opts,
|
||||||
|
})
|
||||||
|
}
|
|
@ -519,6 +519,7 @@ impl FnType {
|
||||||
"powerpc64" => cabi_powerpc64::compute_abi_info(ccx, self),
|
"powerpc64" => cabi_powerpc64::compute_abi_info(ccx, self),
|
||||||
"s390x" => cabi_s390x::compute_abi_info(ccx, self),
|
"s390x" => cabi_s390x::compute_abi_info(ccx, self),
|
||||||
"asmjs" => cabi_asmjs::compute_abi_info(ccx, self),
|
"asmjs" => cabi_asmjs::compute_abi_info(ccx, self),
|
||||||
|
"wasm32" => cabi_asmjs::compute_abi_info(ccx, self),
|
||||||
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a))
|
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -892,7 +892,18 @@ mod os {
|
||||||
pub const EXE_EXTENSION: &'static str = "pexe";
|
pub const EXE_EXTENSION: &'static str = "pexe";
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "emscripten")]
|
#[cfg(all(target_os = "emscripten", target_arch = "asmjs"))]
|
||||||
|
mod os {
|
||||||
|
pub const FAMILY: &'static str = "unix";
|
||||||
|
pub const OS: &'static str = "emscripten";
|
||||||
|
pub const DLL_PREFIX: &'static str = "lib";
|
||||||
|
pub const DLL_SUFFIX: &'static str = ".so";
|
||||||
|
pub const DLL_EXTENSION: &'static str = "so";
|
||||||
|
pub const EXE_SUFFIX: &'static str = ".js";
|
||||||
|
pub const EXE_EXTENSION: &'static str = "js";
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(target_os = "emscripten", target_arch = "wasm32"))]
|
||||||
mod os {
|
mod os {
|
||||||
pub const FAMILY: &'static str = "unix";
|
pub const FAMILY: &'static str = "unix";
|
||||||
pub const OS: &'static str = "emscripten";
|
pub const OS: &'static str = "emscripten";
|
||||||
|
@ -969,6 +980,11 @@ mod arch {
|
||||||
pub const ARCH: &'static str = "asmjs";
|
pub const ARCH: &'static str = "asmjs";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
mod arch {
|
||||||
|
pub const ARCH: &'static str = "wasm32";
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -34,7 +34,8 @@ pub use self::arch::{off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t};
|
||||||
target_arch = "le32",
|
target_arch = "le32",
|
||||||
target_arch = "powerpc",
|
target_arch = "powerpc",
|
||||||
target_arch = "arm",
|
target_arch = "arm",
|
||||||
target_arch = "asmjs"))]
|
target_arch = "asmjs",
|
||||||
|
target_arch = "wasm32"))]
|
||||||
mod arch {
|
mod arch {
|
||||||
use os::raw::{c_long, c_short, c_uint};
|
use os::raw::{c_long, c_short, c_uint};
|
||||||
|
|
||||||
|
|
|
@ -1291,7 +1291,7 @@ impl MetricMap {
|
||||||
///
|
///
|
||||||
/// This function is a no-op, and does not even read from `dummy`.
|
/// This function is a no-op, and does not even read from `dummy`.
|
||||||
#[cfg(not(any(all(target_os = "nacl", target_arch = "le32"),
|
#[cfg(not(any(all(target_os = "nacl", target_arch = "le32"),
|
||||||
target_arch = "asmjs")))]
|
target_arch = "asmjs", target_arch = "wasm32")))]
|
||||||
pub fn black_box<T>(dummy: T) -> T {
|
pub fn black_box<T>(dummy: T) -> T {
|
||||||
// we need to "use" the argument in some way LLVM can't
|
// we need to "use" the argument in some way LLVM can't
|
||||||
// introspect.
|
// introspect.
|
||||||
|
@ -1299,7 +1299,7 @@ pub fn black_box<T>(dummy: T) -> T {
|
||||||
dummy
|
dummy
|
||||||
}
|
}
|
||||||
#[cfg(any(all(target_os = "nacl", target_arch = "le32"),
|
#[cfg(any(all(target_os = "nacl", target_arch = "le32"),
|
||||||
target_arch = "asmjs"))]
|
target_arch = "asmjs", target_arch = "wasm32"))]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
pub fn black_box<T>(dummy: T) -> T {
|
pub fn black_box<T>(dummy: T) -> T {
|
||||||
dummy
|
dummy
|
||||||
|
|
|
@ -65,7 +65,7 @@ pub const unwinder_private_data_size: usize = 2;
|
||||||
#[cfg(target_arch = "s390x")]
|
#[cfg(target_arch = "s390x")]
|
||||||
pub const unwinder_private_data_size: usize = 2;
|
pub const unwinder_private_data_size: usize = 2;
|
||||||
|
|
||||||
#[cfg(target_arch = "asmjs")]
|
#[cfg(any(target_arch = "asmjs", target_arch = "wasm32"))]
|
||||||
pub const unwinder_private_data_size: usize = 20;
|
pub const unwinder_private_data_size: usize = 20;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|
|
@ -1168,7 +1168,6 @@ actual:\n\
|
||||||
"arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => {
|
"arm-linux-androideabi" | "armv7-linux-androideabi" | "aarch64-linux-android" => {
|
||||||
self._arm_exec_compiled_test(env)
|
self._arm_exec_compiled_test(env)
|
||||||
}
|
}
|
||||||
|
|
||||||
_=> {
|
_=> {
|
||||||
let aux_dir = self.aux_output_dir_name();
|
let aux_dir = self.aux_output_dir_name();
|
||||||
self.compose_and_run(self.make_run_args(),
|
self.compose_and_run(self.make_run_args(),
|
||||||
|
@ -1421,7 +1420,7 @@ actual:\n\
|
||||||
fn make_exe_name(&self) -> PathBuf {
|
fn make_exe_name(&self) -> PathBuf {
|
||||||
let mut f = self.output_base_name();
|
let mut f = self.output_base_name();
|
||||||
// FIXME: This is using the host architecture exe suffix, not target!
|
// FIXME: This is using the host architecture exe suffix, not target!
|
||||||
if self.config.target == "asmjs-unknown-emscripten" {
|
if self.config.target.contains("emscripten") {
|
||||||
let mut fname = f.file_name().unwrap().to_os_string();
|
let mut fname = f.file_name().unwrap().to_os_string();
|
||||||
fname.push(".js");
|
fname.push(".js");
|
||||||
f.set_file_name(&fname);
|
f.set_file_name(&fname);
|
||||||
|
@ -1439,8 +1438,8 @@ actual:\n\
|
||||||
let mut args = self.split_maybe_args(&self.config.runtool);
|
let mut args = self.split_maybe_args(&self.config.runtool);
|
||||||
|
|
||||||
// If this is emscripten, then run tests under nodejs
|
// If this is emscripten, then run tests under nodejs
|
||||||
if self.config.target == "asmjs-unknown-emscripten" {
|
if self.config.target.contains("emscripten") {
|
||||||
args.push("nodejs".to_owned());
|
args.push("node".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
let exe_file = self.make_exe_name();
|
let exe_file = self.make_exe_name();
|
||||||
|
|
|
@ -43,7 +43,8 @@ const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[("aarch64", "aarch
|
||||||
("sparc", "sparc"),
|
("sparc", "sparc"),
|
||||||
("x86_64", "x86_64"),
|
("x86_64", "x86_64"),
|
||||||
("xcore", "xcore"),
|
("xcore", "xcore"),
|
||||||
("asmjs", "asmjs")];
|
("asmjs", "asmjs"),
|
||||||
|
("wasm32", "wasm32")];
|
||||||
|
|
||||||
pub fn get_os(triple: &str) -> &'static str {
|
pub fn get_os(triple: &str) -> &'static str {
|
||||||
for &(triple_os, os) in OS_TABLE {
|
for &(triple_os, os) in OS_TABLE {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue