Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test support for emscripten targets #610

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3c6a4f2
Bump ctest to 0.1.3
malbarbo Jun 8, 2017
6324ed9
Add support for emscripten tests
malbarbo Jun 8, 2017
772efe9
Fix c_char and wchar_t for emscripten
malbarbo Jun 8, 2017
0547ddf
Fix rusage and sched_param for emscripten
malbarbo Jun 8, 2017
2ca0849
Fix pthread related definitions for emscripten
malbarbo Jun 8, 2017
084e473
Fix loff_t, ino_t, off_t, blkcnt_t, blksize_t, fsblkcnt_t, fsfilcnt_t…
malbarbo Jun 8, 2017
66c7d05
Fix dev_t, ino64_t, off64_t, blkcnt64_t definitions for emscripten
malbarbo Jun 8, 2017
d87405d
Fix POSIX_MADV_DONTNEED definition for emscripten
malbarbo Jun 8, 2017
cd00492
Enavle travis tests for emscripten
malbarbo Jun 8, 2017
6cd1dd3
Fix style
malbarbo Jun 9, 2017
8f88b6d
Hide output of emsdk installation
malbarbo Jun 9, 2017
4228e72
Change compiler to beta for emscripten (stable is failing)
malbarbo Jun 9, 2017
ef7e8e9
Merge branch 'master' of https://github.com/rust-lang/libc into emscr…
malbarbo Jun 9, 2017
5363161
Fix __SIZEOF_PTHREAD_MUTEX_T for mips
malbarbo Jun 9, 2017
b49cecf
Change compiler to stable for emscripten and skip some functions
malbarbo Jun 9, 2017
bf60a14
Disable wasm-unknown-emscripten tests on travis
malbarbo Jun 9, 2017
80fda85
Remove some functions from emscripten whitelist
malbarbo Jun 13, 2017
a7d5b09
Merge branch 'master' of https://github.com/rust-lang/libc into emscr…
malbarbo Jun 13, 2017
97502e8
Add recent added functions to wasm32 whitelist
malbarbo Jun 13, 2017
f22bfe3
Update emscripten to sdk-1.37.14-64bit
malbarbo Jun 20, 2017
7df3af3
Merge branch 'master' of https://github.com/rust-lang/libc into emscr…
malbarbo Jun 20, 2017
52f1b31
Enable travis tests for wasm32
malbarbo Jun 20, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ matrix:
- os: linux
env: TARGET=mips-unknown-linux-gnu
rust: beta
- os: linux
env: TARGET=asmjs-unknown-emscripten
rust: stable
- os: linux
env: TARGET=wasm32-unknown-emscripten
rust: stable

# beta
- os: linux
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions ci/docker/asmjs-unknown-emscripten/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:16.04

RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
curl \
gcc \
git \
libc6-dev \
python \
xz-utils

COPY emscripten.sh /
RUN bash /emscripten.sh

ENV PATH=$PATH:/rust/bin

COPY emscripten-entry.sh /
ENTRYPOINT ["/emscripten-entry.sh"]

20 changes: 20 additions & 0 deletions ci/docker/wasm32-unknown-emscripten/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:16.04

RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
curl \
gcc \
git \
libc6-dev \
python \
xz-utils

COPY emscripten.sh /
RUN bash /emscripten.sh

ENV PATH=$PATH:/rust/bin

COPY emscripten-entry.sh /
ENTRYPOINT ["/emscripten-entry.sh"]

19 changes: 19 additions & 0 deletions ci/emscripten-entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Copyright 2017 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.

set -ex

source /emsdk-portable/emsdk_env.sh &> /dev/null

# emsdk-portable provides a node binary, but we need version 8 to run wasm
export PATH="/node-v8.0.0-linux-x64/bin:$PATH"

exec "$@"
53 changes: 53 additions & 0 deletions ci/emscripten.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2017 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.

set -ex

hide_output() {
set +x
on_err="
echo ERROR: An error was encountered with the build.
cat /tmp/build.log
exit 1
"
trap "$on_err" ERR
bash -c "while true; do sleep 30; echo \$(date) - building ...; done" &
PING_LOOP_PID=$!
$@ &> /tmp/build.log
trap - ERR
kill $PING_LOOP_PID
rm -f /tmp/build.log
set -x
}

cd /
curl -L https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz | \
tar -xz

cd /emsdk-portable
./emsdk update
hide_output ./emsdk install sdk-1.37.14-64bit
./emsdk activate sdk-1.37.14-64bit

# Compile and cache libc
source ./emsdk_env.sh
echo "main(){}" > a.c
HOME=/emsdk-portable/ emcc a.c
HOME=/emsdk-portable/ emcc -s BINARYEN=1 a.c
rm -f a.*

# Make emsdk usable by any user
cp /root/.emscripten /emsdk-portable
chmod a+rxw -R /emsdk-portable

# node 8 is required to run wasm
cd /
curl -L https://nodejs.org/dist/v8.0.0/node-v8.0.0-linux-x64.tar.xz | \
tar -xJ
4 changes: 4 additions & 0 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ case "$TARGET" in
qemu-aarch64 -L /usr/aarch64-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/libc-test
;;

*-emscripten)
cd $CARGO_TARGET_DIR/$TARGET/debug/deps/ && node ../libc-test.js
;;

*-rumprun-netbsd)
rumprun-bake hw_virtio /tmp/libc-test.img $CARGO_TARGET_DIR/$TARGET/debug/libc-test
qemu-system-x86_64 -nographic -vga none -m 64 \
Expand Down
2 changes: 1 addition & 1 deletion libc-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ build = "build.rs"
libc = { path = ".." }

[build-dependencies]
ctest = "0.1"
ctest = "0.1.3"
40 changes: 35 additions & 5 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ fn main() {
let linux = target.contains("unknown-linux");
let android = target.contains("android");
let apple = target.contains("apple");
let musl = target.contains("musl");
let emscripten = target.contains("asm");
let musl = target.contains("musl") || emscripten;
let uclibc = target.contains("uclibc");
let freebsd = target.contains("freebsd");
let dragonfly = target.contains("dragonfly");
Expand All @@ -25,7 +26,7 @@ fn main() {
let mut cfg = ctest::TestGenerator::new();

// Pull in extra goodies
if linux || android {
if linux || android || emscripten {
cfg.define("_GNU_SOURCE", None);
} else if netbsd {
cfg.define("_NETBSD_SOURCE", Some("1"));
Expand Down Expand Up @@ -165,7 +166,7 @@ fn main() {
}
}

if linux {
if linux || emscripten {
cfg.header("mqueue.h");
cfg.header("ucontext.h");
cfg.header("sys/signalfd.h");
Expand All @@ -186,7 +187,7 @@ fn main() {
}
}

if linux || android {
if linux || android || emscripten {
cfg.header("malloc.h");
cfg.header("net/ethernet.h");
cfg.header("netpacket/packet.h");
Expand Down Expand Up @@ -242,7 +243,7 @@ fn main() {
cfg.header("sys/ioctl_compat.h");
}

if linux || freebsd || dragonfly || netbsd || apple {
if linux || emscripten || freebsd || dragonfly || netbsd || apple {
if !uclibc {
cfg.header("aio.h");
}
Expand Down Expand Up @@ -361,6 +362,9 @@ fn main() {
"FILE_ATTRIBUTE_INTEGRITY_STREAM" |
"ERROR_NOTHING_TO_TERMINATE" if mingw => true,

// not defined
"IUTF8" | "ENOATTR" | "EXTA" | "EXTB" if emscripten => true,

"SIG_IGN" => true, // sighandler_t weirdness

// types on musl are defined a little differently
Expand Down Expand Up @@ -433,6 +437,32 @@ fn main() {
"prlimit" | "prlimit64" | // non-int in 2nd arg
"strerror_r" if linux => true, // actually xpg-something-or-other

// not defined or fails to link
"aio_cancel" | "aio_error" | "aio_fsync" | "aio_read" | "aio_return"| "aio_suspend" |
"aio_write" | "clock_nanosleep" | "clone" | "daemon" | "endspent" | "epoll_create" |
"epoll_create1" | "epoll_ctl" | "epoll_pwait" | "epoll_wait" | "eventfd" |
"faccessat" | "fallocate" | "fgetxattr" | "flistxattr" | "forkpty" | "fremovexattr" |
"fsetxattr" | "ftok" | "futimes" | "getdtablesize" | "getgrgid" | "getgrnam" |
"getpwnam_r" | "getpwuid_r" | "getspent" | "getspnam" | "getxattr" | "initgroups" |
"lgetxattr" | "listxattr" | "llistxattr" | "lremovexattr" | "lsetxattr" | "lutimes" |
"mount" | "mq_close" | "mq_getattr" | "mq_open" | "mq_receive" | "mq_send" |
"mq_setattr" | "mq_unlink" | "msgctl" | "msgget" | "msgrcv" | "msgsnd" | "pclose" |
"popen" | "ppoll" | "prctl" | "prlimit" | "prlimit64" | "process_vm_readv" |
"process_vm_writev" | "pthread_atfork" | "pthread_attr_getguardsize" |
"pthread_kill" | "pthread_mutexattr_getpshared" | "pthread_mutex_timedlock" |
"pthread_getschedparam" | "pthread_setschedparam" | "pthread_setschedprio" |
"pthread_sigmask" | "ptrace" | "quotactl" | "readahead" | "reboot" | "removexattr" |
"sched_getaffinity" | "sched_getparam" | "sched_get_priority_max" |
"sched_get_priority_min" | "sched_getscheduler" | "sched_rr_get_interval" |
"sched_setaffinity" | "sched_setparam" | "sched_setscheduler" | "sem_close" |
"semctl" | "semget" | "semop" | "sem_open" | "sem_timedwait" | "sem_unlink" |
"sendfile" | "setfsgid" | "setfsuid" | "sethostname" | "setns" | "setspent" |
"settimeofday" | "setxattr" | "shmat" | "shmctl" | "shmdt" | "shmget" |
"sigaltstack" | "signalfd" | "sigsuspend" | "sigtimedwait" | "sigwait" |
"sigwaitinfo" | "splice" | "sync_file_range" | "sysinfo" | "tee" | "umount" |
"umount2" | "unshare" | "vmsplice" | "swapoff" | "vhangup" | "swapon" |
"personality" | "syscall" if emscripten => true,

// int vs uint. Sorry musl, your prototype declarations are "correct" in the sense that
// they match the interface defined by Linux verbatim, but they conflict with other
// send*/recv* syscalls
Expand Down
2 changes: 1 addition & 1 deletion src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ s! {
pub ru_nvcsw: c_long,
pub ru_nivcsw: c_long,

#[cfg(any(target_env = "musl"))]
#[cfg(any(target_env = "musl", target_os = "emscripten"))]
__reserved: [c_long; 16],
}

Expand Down
2 changes: 2 additions & 0 deletions src/unix/notbsd/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub type clock_t = ::c_long;
pub type time_t = ::c_long;
pub type suseconds_t = ::c_long;
pub type off_t = ::c_long;
pub type loff_t = ::c_longlong;
pub type blkcnt_t = ::c_ulong;
pub type blksize_t = ::c_ulong;
pub type nlink_t = u32;
Expand Down Expand Up @@ -148,6 +149,7 @@ s! {
}

pub const O_TRUNC: ::c_int = 512;
pub const O_TMPFILE: ::c_int = 0o20000000 | ::O_DIRECTORY;

pub const O_CLOEXEC: ::c_int = 0x80000;

Expand Down
6 changes: 6 additions & 0 deletions src/unix/notbsd/linux/mips/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
pub type loff_t = ::c_longlong;
pub type dev_t = u64;
pub type ino64_t = u64;
pub type off64_t = i64;
pub type blkcnt64_t = i64;
pub type fsblkcnt_t = ::c_ulong;
pub type fsfilcnt_t = ::c_ulong;
pub type rlim_t = c_ulong;
Expand Down Expand Up @@ -72,6 +77,7 @@ pub const O_ACCMODE: ::c_int = 3;
pub const O_DIRECT: ::c_int = 0x8000;
pub const O_DIRECTORY: ::c_int = 0x10000;
pub const O_NOFOLLOW: ::c_int = 0x20000;
pub const O_TMPFILE: ::c_int = 0o20000000 | O_DIRECTORY;
pub const ST_RELATIME: ::c_ulong = 4096;
pub const NI_MAXHOST: ::socklen_t = 1025;

Expand Down
Loading