Skip to content

Commit d6c0d85

Browse files
committed
Add the asmjs-unknown-emscripten triple. Add cfgs to libs.
Backtraces, and the compilation of libbacktrace for asmjs, are disabled. This port doesn't use jemalloc so, like pnacl, it disables jemalloc *for all targets* in the configure file. It disables stack protection.
1 parent 34af2de commit d6c0d85

File tree

24 files changed

+181
-19
lines changed

24 files changed

+181
-19
lines changed

configure

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,12 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
13051305
putvar CFG_DISABLE_JEMALLOC
13061306
;;
13071307

1308+
*-emscripten)
1309+
step_msg "targeting emscripten, disabling jemalloc"
1310+
CFG_DISABLE_JEMALLOC=1
1311+
putvar CFG_DISABLE_JEMALLOC
1312+
;;
1313+
13081314
*)
13091315
;;
13101316
esac

mk/cfg/asmjs-unknown-emscripten.mk

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# asmjs-unknown-emscripten configuration
2+
CC_asmjs-unknown-emscripten=emcc
3+
CXX_asmjs-unknown-emscripten=em++
4+
CPP_asmjs-unknown-emscripten=$(CPP)
5+
AR_asmjs-unknown-emscripten=emar
6+
CFG_LIB_NAME_asmjs-unknown-emscripten=lib$(1).so
7+
CFG_STATIC_LIB_NAME_asmjs-unknown-emscripten=lib$(1).a
8+
CFG_LIB_GLOB_asmjs-unknown-emscripten=lib$(1)-*.so
9+
CFG_LIB_DSYM_GLOB_asmjs-unknown-emscripten=lib$(1)-*.dylib.dSYM
10+
CFG_JEMALLOC_CFLAGS_asmjs-unknown-emscripten := -m32 $(CFLAGS)
11+
CFG_GCCISH_CFLAGS_asmjs-unknown-emscripten := -Wall -Werror -g -fPIC -m32 $(CFLAGS)
12+
CFG_GCCISH_CXXFLAGS_asmjs-unknown-emscripten := -fno-rtti $(CXXFLAGS)
13+
CFG_GCCISH_LINK_FLAGS_asmjs-unknown-emscripten := -shared -fPIC -ldl -pthread -lrt -g -m32
14+
CFG_GCCISH_DEF_FLAG_asmjs-unknown-emscripten := -Wl,--export-dynamic,--dynamic-list=
15+
CFG_LLC_FLAGS_asmjs-unknown-emscripten :=
16+
CFG_INSTALL_NAME_asmjs-unknown-emscripten =
17+
CFG_EXE_SUFFIX_asmjs-unknown-emscripten =
18+
CFG_WINDOWSY_asmjs-unknown-emscripten :=
19+
CFG_UNIXY_asmjs-unknown-emscripten := 1
20+
CFG_LDPATH_asmjs-unknown-emscripten :=
21+
CFG_RUN_asmjs-unknown-emscripten=$(2)
22+
CFG_RUN_TARG_asmjs-unknown-emscripten=$(call CFG_RUN_asmjs-unknown-emscripten,,$(2))
23+
CFG_GNU_TRIPLE_asmjs-unknown-emscripten := asmjs-unknown-emscripten

mk/rt.mk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,15 @@ ifeq ($$(findstring freebsd,$(1)),freebsd)
254254
COMPRT_CFLAGS_$(1) += -I/usr/include/c++/v1
255255
endif
256256

257+
ifeq ($$(findstring emscripten,$(1)),emscripten)
258+
259+
# FIXME: emscripten doesn't use compiler-rt and can't build it without
260+
# further hacks
261+
$$(COMPRT_LIB_$(1)):
262+
touch $$@
263+
264+
else
265+
257266
$$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS)
258267
@$$(call E, make: compiler-rt)
259268
$$(Q)$$(MAKE) -C "$(S)src/compiler-rt" \
@@ -266,7 +275,10 @@ $$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS)
266275
TargetTriple=$(1) \
267276
triple-builtins
268277
$$(Q)cp $$(COMPRT_BUILD_DIR_$(1))/triple/builtins/libcompiler_rt.a $$@
278+
279+
endif # if emscripten
269280
endif
281+
270282
################################################################################
271283
# libbacktrace
272284
#
@@ -301,6 +313,12 @@ $$(BACKTRACE_LIB_$(1)):
301313
touch $$@
302314
else
303315

316+
ifeq ($$(findstring emscripten,$(1)),emscripten)
317+
# FIXME: libbacktrace doesn't understand the emscripten triple
318+
$$(BACKTRACE_LIB_$(1)):
319+
touch $$@
320+
else
321+
304322
ifdef CFG_ENABLE_FAST_MAKE
305323
BACKTRACE_DEPS := $(S)/.gitmodules
306324
else
@@ -348,6 +366,7 @@ $$(BACKTRACE_LIB_$(1)): $$(BACKTRACE_BUILD_DIR_$(1))/Makefile $$(MKFILE_DEPS)
348366
INCDIR=$(S)src/libbacktrace
349367
$$(Q)cp $$(BACKTRACE_BUILD_DIR_$(1))/.libs/libbacktrace.a $$@
350368

369+
endif # endif for emscripten
351370
endif # endif for msvc
352371
endif # endif for ios
353372
endif # endif for darwin

src/liballoc_system/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ extern crate libc;
3030
target_arch = "arm",
3131
target_arch = "mips",
3232
target_arch = "powerpc",
33-
target_arch = "powerpc64")))]
33+
target_arch = "powerpc64",
34+
target_arch = "asmjs")))]
3435
const MIN_ALIGN: usize = 8;
3536
#[cfg(all(any(target_arch = "x86_64",
3637
target_arch = "aarch64")))]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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() -> Target {
14+
let opts = TargetOptions {
15+
linker: "emcc".to_string(),
16+
ar: "emar".to_string(),
17+
18+
dynamic_linking: false,
19+
executables: true,
20+
exe_suffix: ".js".to_string(),
21+
no_compiler_rt: true,
22+
linker_is_gnu: true,
23+
allow_asm: false,
24+
archive_format: "gnu".to_string(),
25+
.. Default::default()
26+
};
27+
Target {
28+
llvm_target: "asmjs-unknown-emscripten".to_string(),
29+
target_endian: "little".to_string(),
30+
target_pointer_width: "32".to_string(),
31+
target_os: "emscripten".to_string(),
32+
target_env: "".to_string(),
33+
target_vendor: "unknown".to_string(),
34+
arch: "asmjs".to_string(),
35+
options: opts,
36+
}
37+
}

src/librustc_back/target/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,8 @@ impl Target {
461461
x86_64_pc_windows_msvc,
462462
i686_pc_windows_msvc,
463463

464-
le32_unknown_nacl
464+
le32_unknown_nacl,
465+
asmjs_unknown_emscripten
465466
);
466467

467468

src/librustc_trans/trans/cabi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use trans::cabi_aarch64;
2121
use trans::cabi_powerpc;
2222
use trans::cabi_powerpc64;
2323
use trans::cabi_mips;
24+
use trans::cabi_asmjs;
2425
use trans::type_::Type;
2526

2627
#[derive(Clone, Copy, PartialEq)]
@@ -129,6 +130,7 @@ pub fn compute_abi_info(ccx: &CrateContext,
129130
"mips" => cabi_mips::compute_abi_info(ccx, atys, rty, ret_def),
130131
"powerpc" => cabi_powerpc::compute_abi_info(ccx, atys, rty, ret_def),
131132
"powerpc64" => cabi_powerpc64::compute_abi_info(ccx, atys, rty, ret_def),
133+
"asmjs" => cabi_asmjs::compute_abi_info(ccx, atys, rty, ret_def),
132134
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a)
133135
),
134136
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2012-2013 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 trans::cabi::FnType;
12+
use trans::cabi_arm;
13+
use trans::context::CrateContext;
14+
use trans::type_::Type;
15+
16+
pub fn compute_abi_info(ccx: &CrateContext,
17+
atys: &[Type],
18+
rty: Type,
19+
ret_def: bool) -> FnType {
20+
cabi_arm::compute_abi_info(ccx, atys, rty, ret_def,
21+
cabi_arm::Flavor::General)
22+
}

src/librustc_trans/trans/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ mod builder;
3030
mod cabi;
3131
mod cabi_aarch64;
3232
mod cabi_arm;
33+
mod cabi_asmjs;
3334
mod cabi_mips;
3435
mod cabi_powerpc;
3536
mod cabi_powerpc64;

src/libstd/dynamic_lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ mod tests {
197197
target_os = "bitrig",
198198
target_os = "netbsd",
199199
target_os = "openbsd",
200-
target_os = "solaris"))]
200+
target_os = "solaris",
201+
target_os = "emscripten"))]
201202
mod dl {
202203
use prelude::v1::*;
203204

0 commit comments

Comments
 (0)