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

src/libstd/env.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,17 @@ mod os {
844844
pub const EXE_EXTENSION: &'static str = "pexe";
845845
}
846846

847+
#[cfg(target_os = "emscripten")]
848+
mod os {
849+
pub const FAMILY: &'static str = "unix";
850+
pub const OS: &'static str = "emscripten";
851+
pub const DLL_PREFIX: &'static str = "lib";
852+
pub const DLL_SUFFIX: &'static str = ".so";
853+
pub const DLL_EXTENSION: &'static str = "so";
854+
pub const EXE_SUFFIX: &'static str = ".js";
855+
pub const EXE_EXTENSION: &'static str = "js";
856+
}
857+
847858
#[cfg(target_arch = "x86")]
848859
mod arch {
849860
pub const ARCH: &'static str = "x86";
@@ -884,6 +895,11 @@ mod arch {
884895
pub const ARCH: &'static str = "le32";
885896
}
886897

898+
#[cfg(target_arch = "asmjs")]
899+
mod arch {
900+
pub const ARCH: &'static str = "asmjs";
901+
}
902+
887903
#[cfg(test)]
888904
mod tests {
889905
use prelude::v1::*;

src/libstd/os/linux/raw.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,23 @@ pub use self::arch::{off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t};
2626
#[cfg(any(target_arch = "x86",
2727
target_arch = "le32",
2828
target_arch = "powerpc",
29-
target_arch = "arm"))]
29+
target_arch = "arm",
30+
target_arch = "asmjs"))]
3031
mod arch {
3132
use super::{dev_t, mode_t};
3233
use os::raw::{c_long, c_short};
3334
use os::unix::raw::{gid_t, uid_t};
3435

3536
#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i32;
3637
#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = i32;
37-
#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u32;
38+
39+
#[stable(feature = "raw_ext", since = "1.1.0")]
40+
#[cfg(not(any(target_env = "musl", target_arch = "asmjs")))]
41+
pub type ino_t = u32;
42+
#[stable(feature = "raw_ext", since = "1.1.0")]
43+
#[cfg(any(target_env = "musl", target_arch = "asmjs"))]
44+
pub type ino_t = u64;
45+
3846
#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32;
3947
#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i32;
4048
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;

src/libstd/os/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ pub use sys::ext as windows;
3232
#[cfg(target_os = "openbsd")] pub mod openbsd;
3333
#[cfg(target_os = "solaris")] pub mod solaris;
3434

35+
// Emscripten is just like linux
36+
#[cfg(target_os = "emscripten")]
37+
#[path = "linux/mod.rs"]
38+
pub mod emscripten;
39+
3540
pub mod raw;

src/libstd/os/raw.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
#![stable(feature = "raw_os", since = "1.1.0")]
1414

1515
#[cfg(any(target_os = "android",
16+
target_os = "emscripten",
1617
all(target_os = "linux", any(target_arch = "aarch64",
1718
target_arch = "arm",
1819
target_arch = "powerpc",
1920
target_arch = "powerpc64"))))]
2021
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
2122
#[cfg(not(any(target_os = "android",
23+
target_os = "emscripten",
2224
all(target_os = "linux", any(target_arch = "aarch64",
2325
target_arch = "arm",
2426
target_arch = "powerpc",

src/libstd/sys/common/args.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ pub fn clone() -> Option<Vec<Vec<u8>>> { imp::clone() }
3939
target_os = "bitrig",
4040
target_os = "netbsd",
4141
target_os = "openbsd",
42-
target_os = "solaris"))]
42+
target_os = "solaris",
43+
target_os = "emscripten"))]
4344
mod imp {
4445
use prelude::v1::*;
4546

src/libstd/sys/common/libunwind.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ pub const unwinder_private_data_size: usize = 2;
8686
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
8787
pub const unwinder_private_data_size: usize = 2;
8888

89+
#[cfg(target_arch = "asmjs")]
90+
// FIXME: Copied from arm. Need to confirm.
91+
pub const unwinder_private_data_size: usize = 20;
92+
8993
#[repr(C)]
9094
pub struct _Unwind_Exception {
9195
pub exception_class: _Unwind_Exception_Class,

src/libstd/sys/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub mod unwind;
4545
pub mod util;
4646
pub mod wtf8;
4747

48-
#[cfg(any(all(unix, not(any(target_os = "macos", target_os = "ios"))),
48+
#[cfg(any(all(unix, not(any(target_os = "macos", target_os = "ios", target_os = "emscripten"))),
4949
all(windows, target_env = "gnu")))]
5050
pub mod gnu;
5151

src/libstd/sys/unix/backtrace/printing/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
pub use self::imp::print;
1212

13-
#[cfg(any(target_os = "macos", target_os = "ios"))]
13+
#[cfg(any(target_os = "macos", target_os = "ios",
14+
target_os = "emscripten"))]
1415
#[path = "dladdr.rs"]
1516
mod imp;
1617

17-
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
18+
#[cfg(not(any(target_os = "macos", target_os = "ios",
19+
target_os = "emscripten")))]
1820
#[path = "gnu.rs"]
1921
mod imp;

src/libstd/sys/unix/fs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ impl DirEntry {
293293
#[cfg(any(target_os = "macos",
294294
target_os = "ios",
295295
target_os = "linux",
296-
target_os = "solaris"))]
296+
target_os = "solaris",
297+
target_os = "emscripten"))]
297298
pub fn ino(&self) -> raw::ino_t {
298299
self.entry.d_ino
299300
}
@@ -326,7 +327,8 @@ impl DirEntry {
326327
}
327328
}
328329
#[cfg(any(target_os = "android",
329-
target_os = "linux"))]
330+
target_os = "linux",
331+
target_os = "emscripten"))]
330332
fn name_bytes(&self) -> &[u8] {
331333
unsafe {
332334
CStr::from_ptr(self.entry.d_name.as_ptr()).to_bytes()

src/libstd/sys/unix/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use ops::Neg;
2626
#[cfg(target_os = "netbsd")] pub use os::netbsd as platform;
2727
#[cfg(target_os = "openbsd")] pub use os::openbsd as platform;
2828
#[cfg(target_os = "solaris")] pub use os::solaris as platform;
29+
#[cfg(target_os = "emscripten")] pub use os::emscripten as platform;
2930

3031
pub mod backtrace;
3132
pub mod condvar;

src/libstd/sys/unix/os.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ static ENV_LOCK: StaticMutex = StaticMutex::new();
3838
/// Returns the platform-specific value of errno
3939
pub fn errno() -> i32 {
4040
extern {
41-
#[cfg_attr(any(target_os = "linux"), link_name = "__errno_location")]
41+
#[cfg_attr(any(target_os = "linux", target_os = "emscripten"),
42+
link_name = "__errno_location")]
4243
#[cfg_attr(any(target_os = "bitrig",
4344
target_os = "netbsd",
4445
target_os = "openbsd",
@@ -235,7 +236,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
235236
}
236237
}
237238

238-
#[cfg(any(target_os = "linux", target_os = "android"))]
239+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
239240
pub fn current_exe() -> io::Result<PathBuf> {
240241
::fs::read_link("/proc/self/exe")
241242
}
@@ -385,7 +386,8 @@ pub fn args() -> Args {
385386
target_os = "netbsd",
386387
target_os = "openbsd",
387388
target_os = "solaris",
388-
target_os = "nacl"))]
389+
target_os = "nacl",
390+
target_os = "emscripten"))]
389391
pub fn args() -> Args {
390392
use sys_common;
391393
let bytes = sys_common::args::clone().unwrap_or(Vec::new());

src/libstd/sys/unix/process.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ impl fmt::Debug for Command {
131131
pub struct ExitStatus(c_int);
132132

133133
#[cfg(any(target_os = "linux", target_os = "android",
134-
target_os = "nacl", target_os = "solaris"))]
134+
target_os = "nacl", target_os = "solaris",
135+
target_os = "emscripten"))]
135136
mod status_imp {
136137
pub fn WIFEXITED(status: i32) -> bool { (status & 0xff) == 0 }
137138
pub fn WEXITSTATUS(status: i32) -> i32 { (status >> 8) & 0xff }

0 commit comments

Comments
 (0)