Skip to content

Commit 6324ed9

Browse files
committed
Add support for emscripten tests
1 parent 3c6a4f2 commit 6324ed9

File tree

6 files changed

+136
-5
lines changed

6 files changed

+136
-5
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM ubuntu:16.04
2+
3+
RUN apt-get update && \
4+
apt-get install -y --no-install-recommends \
5+
ca-certificates \
6+
curl \
7+
gcc \
8+
git \
9+
libc6-dev \
10+
python \
11+
xz-utils
12+
13+
COPY emscripten.sh /
14+
RUN bash /emscripten.sh
15+
16+
ENV PATH=$PATH:/rust/bin
17+
18+
COPY emscripten-entry.sh /
19+
ENTRYPOINT ["/emscripten-entry.sh"]
20+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM ubuntu:16.04
2+
3+
RUN apt-get update && \
4+
apt-get install -y --no-install-recommends \
5+
ca-certificates \
6+
curl \
7+
gcc \
8+
git \
9+
libc6-dev \
10+
python \
11+
xz-utils
12+
13+
COPY emscripten.sh /
14+
RUN bash /emscripten.sh
15+
16+
ENV PATH=$PATH:/rust/bin
17+
18+
COPY emscripten-entry.sh /
19+
ENTRYPOINT ["/emscripten-entry.sh"]
20+

ci/emscripten-entry.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# Copyright 2017 The Rust Project Developers. See the COPYRIGHT
3+
# file at the top-level directory of this distribution and at
4+
# http://rust-lang.org/COPYRIGHT.
5+
#
6+
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7+
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8+
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9+
# option. This file may not be copied, modified, or distributed
10+
# except according to those terms.
11+
12+
set -ex
13+
14+
source /emsdk-portable/emsdk_env.sh &> /dev/null
15+
16+
# emsdk-portable provides a node binary, but we need version 8 to run wasm
17+
export PATH="/node-v8.0.0-linux-x64/bin:$PATH"
18+
19+
exec "$@"

ci/emscripten.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2017 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+
set -ex
12+
13+
cd /
14+
curl -L https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz | \
15+
tar -xz
16+
17+
cd /emsdk-portable
18+
./emsdk update
19+
./emsdk install sdk-1.37.13-64bit
20+
./emsdk activate sdk-1.37.13-64bit
21+
22+
# Compile and cache libc
23+
source ./emsdk_env.sh
24+
echo "main(){}" > a.c
25+
HOME=/emsdk-portable/ emcc a.c
26+
HOME=/emsdk-portable/ emcc -s BINARYEN=1 a.c
27+
rm -f a.*
28+
29+
# Make emsdk usable by any user
30+
cp /root/.emscripten /emsdk-portable
31+
chmod a+rxw -R /emsdk-portable
32+
33+
# node 8 is required to run wasm
34+
cd /
35+
curl -L https://nodejs.org/dist/v8.0.0/node-v8.0.0-linux-x64.tar.xz | \
36+
tar -xJ

ci/run.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ case "$TARGET" in
168168
qemu-aarch64 -L /usr/aarch64-linux-gnu/ $CARGO_TARGET_DIR/$TARGET/debug/libc-test
169169
;;
170170

171+
*-emscripten)
172+
cd $CARGO_TARGET_DIR/$TARGET/debug/deps/ && node ../libc-test.js
173+
;;
174+
171175
*-rumprun-netbsd)
172176
rumprun-bake hw_virtio /tmp/libc-test.img $CARGO_TARGET_DIR/$TARGET/debug/libc-test
173177
qemu-system-x86_64 -nographic -vga none -m 64 \

libc-test/build.rs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ fn main() {
1313
let linux = target.contains("unknown-linux");
1414
let android = target.contains("android");
1515
let apple = target.contains("apple");
16-
let musl = target.contains("musl");
16+
let emscripten = target.contains("asm");
17+
let musl = target.contains("musl") || emscripten;
1718
let uclibc = target.contains("uclibc");
1819
let freebsd = target.contains("freebsd");
1920
let dragonfly = target.contains("dragonfly");
@@ -25,7 +26,7 @@ fn main() {
2526
let mut cfg = ctest::TestGenerator::new();
2627

2728
// Pull in extra goodies
28-
if linux || android {
29+
if linux || android || emscripten {
2930
cfg.define("_GNU_SOURCE", None);
3031
} else if netbsd {
3132
cfg.define("_NETBSD_SOURCE", Some("1"));
@@ -165,7 +166,7 @@ fn main() {
165166
}
166167
}
167168

168-
if linux {
169+
if linux || emscripten {
169170
cfg.header("mqueue.h");
170171
cfg.header("ucontext.h");
171172
cfg.header("sys/signalfd.h");
@@ -183,7 +184,7 @@ fn main() {
183184
cfg.header("shadow.h");
184185
}
185186

186-
if linux || android {
187+
if linux || android || emscripten {
187188
cfg.header("malloc.h");
188189
cfg.header("net/ethernet.h");
189190
cfg.header("netpacket/packet.h");
@@ -237,7 +238,7 @@ fn main() {
237238
cfg.header("sys/ioctl_compat.h");
238239
}
239240

240-
if linux || freebsd || dragonfly || netbsd || apple {
241+
if linux || emscripten || freebsd || dragonfly || netbsd || apple {
241242
if !uclibc {
242243
cfg.header("aio.h");
243244
}
@@ -356,6 +357,9 @@ fn main() {
356357
"FILE_ATTRIBUTE_INTEGRITY_STREAM" |
357358
"ERROR_NOTHING_TO_TERMINATE" if mingw => true,
358359

360+
// not defined
361+
"IUTF8" | "ENOATTR" | "EXTA" | "EXTB" if emscripten => true,
362+
359363
"SIG_IGN" => true, // sighandler_t weirdness
360364

361365
// types on musl are defined a little differently
@@ -428,6 +432,34 @@ fn main() {
428432
"prlimit" | "prlimit64" | // non-int in 2nd arg
429433
"strerror_r" if linux => true, // actually xpg-something-or-other
430434

435+
// not defined or fails to link
436+
"aio_cancel" | "aio_error" | "aio_fsync" | "aio_read" | "aio_read_write" | "aio_return"|
437+
"aio_suspend" | "aio_write" | "clock_nanosleep" | "clone" | "daemon" | "endspent" |
438+
"epoll_create" | "epoll_create1" | "epoll_ctl" | "epoll_pwait" | "epoll_wait" |
439+
"eventfd" | "faccessat" | "fallocate" | "fgetxattr" | "flistxattr" | "fork" |
440+
"forkpty" | "fremovexattr" | "fsetxattr" | "ftok" | "futimes" | "getdtablesize" |
441+
"getgrgid" | "getgrnam" | "getgroups" | "getpgid" | "getpgrp" | "getpwnam_r" |
442+
"getpwuid_r" | "getspent" | "getspnam" | "getxattr" | "initgroups" | "lgetxattr" |
443+
"listxattr" | "llistxattr" | "lremovexattr" | "lsetxattr" | "lutimes" | "mount" |
444+
"mq_close" | "mq_getattr" | "mq_open" | "mq_receive" | "mq_send" | "mq_setattr" |
445+
"mq_unlink" | "msgctl" | "msgget" | "msgrcv" | "msgsnd" | "pclose" | "popen" |
446+
"ppoll" | "prctl" | "prlimit" | "prlimit64" | "process_vm_readv" |
447+
"process_vm_writev" | "pthread_atfork" | "pthread_attr_getguardsize" |
448+
"pthread_kill" | "pthread_mutexattr_getpshared" | "pthread_mutex_timedlock" |
449+
"pthread_sigmask" | "ptrace" | "quotactl" | "readahead" | "reboot" | "removexattr" |
450+
"sched_getaffinity" | "sched_getparam" | "sched_get_priority_max" |
451+
"sched_get_priority_min" | "sched_getscheduler" | "sched_rr_get_interval" |
452+
"sched_setaffinity" | "sched_setparam" | "sched_setscheduler" | "sem_close" |
453+
"semctl" | "semget" | "semop" | "sem_open" | "sem_timedwait" | "sem_unlink" |
454+
"sendfile" | "setfsgid" | "setfsuid" | "setgroups" | "sethostname" | "setns" |
455+
"setpgid" | "setpgrp" | "setspent" | "settimeofday" | "setxattr" | "shmat" |
456+
"shmctl" | "shmdt" | "shmget" | "sigaltstack" | "signalfd" | "sigsuspend" |
457+
"sigtimedwait" | "sigwait" | "sigwaitinfo" | "splice" | "sync_file_range" |
458+
"syscall" | "sysinfo" | "tee" | "umount" | "umount2" | "unshare" | "vmsplice"
459+
if emscripten => true,
460+
461+
// n if n.starts_with("epoll") && emscripten => true,
462+
431463
// int vs uint. Sorry musl, your prototype declarations are "correct" in the sense that
432464
// they match the interface defined by Linux verbatim, but they conflict with other
433465
// send*/recv* syscalls

0 commit comments

Comments
 (0)