Skip to content

Commit 35bc1bd

Browse files
Merge pull request WebAssembly#1 from waynr/cpython-compatibility-fixes
CPython compatibility updates
2 parents 577ac36 + 2362aca commit 35bc1bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+5705
-68
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.ccls*
12
sysroot
23
sysroot32
34
sysroot64

Makefile

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,29 @@ LIBC_TOP_HALF_MUSL_SOURCES = \
9999
misc/nftw.c \
100100
misc/syslog.c \
101101
errno/strerror.c \
102+
\
103+
network/services.c \
104+
network/getaddrinfo.c \
105+
network/getnameinfo.c \
106+
network/gethostbyname.c \
107+
network/gethostbyname2.c \
108+
network/gethostbyname2_r.c \
109+
network/getservbyname.c \
110+
network/getservbyname_r.c \
111+
network/gethostbyaddr.c \
112+
network/gethostbyaddr_r.c \
113+
network/lookup_ipliteral.c \
114+
network/lookup_name.c \
115+
network/lookup_serv.c \
116+
network/freeaddrinfo.c \
117+
network/resolvconf.c \
118+
\
119+
network/gethostbyaddr.c \
120+
network/gethostbyname.c \
121+
network/getservbyname.c \
122+
network/getservbyport.c \
123+
network/h_errno.c \
124+
network/hstrerror.c \
102125
network/htonl.c \
103126
network/htons.c \
104127
network/ntohl.c \
@@ -108,6 +131,7 @@ LIBC_TOP_HALF_MUSL_SOURCES = \
108131
network/inet_aton.c \
109132
network/in6addr_any.c \
110133
network/in6addr_loopback.c \
134+
network/proto.c \
111135
fenv/fenv.c \
112136
fenv/fesetround.c \
113137
fenv/feupdateenv.c \
@@ -169,6 +193,7 @@ LIBC_TOP_HALF_MUSL_SOURCES = \
169193
linux/wait3.c \
170194
linux/wait4.c \
171195
linux/eventfd.c \
196+
linux/setgroups.c \
172197
stat/futimesat.c \
173198
legacy/getpagesize.c \
174199
thread/thrd_sleep.c \
@@ -445,7 +470,7 @@ MUSL_OMIT_HEADERS += \
445470
"sys/acct.h" \
446471
"sys/cachectl.h" \
447472
"sys/epoll.h" "sys/reboot.h" "sys/swap.h" \
448-
"sys/sendfile.h" "sys/inotify.h" \
473+
"sys/inotify.h" \
449474
"sys/quota.h" \
450475
"sys/klog.h" \
451476
"sys/fsuid.h" \
@@ -468,7 +493,6 @@ MUSL_OMIT_HEADERS += \
468493
"sys/membarrier.h" \
469494
"sys/signalfd.h" \
470495
"sys/termios.h" \
471-
"net/if.h" \
472496
"net/if_arp.h" \
473497
"net/ethernet.h" \
474498
"net/route.h" \
@@ -483,7 +507,16 @@ ifeq ($(THREAD_MODEL), single)
483507
MUSL_OMIT_HEADERS += "pthread.h"
484508
endif
485509

486-
default: finish
510+
default: finish post-finish
511+
512+
wasix-headers:
513+
git submodule init
514+
git submodule update
515+
cargo run --manifest-path tools/wasix-headers/Cargo.toml generate-libc
516+
517+
post-finish: finish
518+
rm -f sysroot/lib/wasm32-wasi/libc-printscan-log-double.a
519+
rsync -rtvu --delete ./sysroot/ ./sysroot32/
487520

488521
$(SYSROOT_LIB)/libc.a: $(LIBC_OBJS)
489522

examples/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
CC=clang
1+
CC ?= "clang"
2+
SYSROOT ?= "../sysroot32"
23
LLD_PATH=/prog/rust/build/x86_64-unknown-linux-gnu/lld/bin
34

45
CFLAGS = --target=wasm32-wasmer-wasi \
56
-O2 \
6-
--sysroot ../../wasix-libc/sysroot32 \
7+
--sysroot ${SYSROOT} \
78
-matomics \
89
-mbulk-memory \
910
-mmutable-globals \
@@ -54,7 +55,7 @@ SRC=$(wildcard *.c)
5455

5556
export PATH := $(LLD_PATH):$(PATH)
5657

57-
all: longjmp file-copy signal fork vfork fork-longjmp execve spawn pipe epoll
58+
all: longjmp file-copy signal fork vfork fork-longjmp execve spawn pipe epoll getrandom readdir_tree
5859
cp -f ../dist/wasix/longjmp.wasm ../../wasmer/tests/integration/cli/tests/wasm/example-longjmp.wasm
5960
cp -f ../dist/wasix/fork.wasm ../../wasmer/tests/integration/cli/tests/wasm/example-fork.wasm
6061
cp -f ../dist/wasix/fork.wasm ../../packages/fork-test/test.wasm
@@ -69,9 +70,9 @@ all: longjmp file-copy signal fork vfork fork-longjmp execve spawn pipe epoll
6970

7071
%: %.c
7172
mkdir -p ../dist/host
72-
clang $@.c -o ../dist/host/$@
73+
${CC} $(CFLAGS) $@.c -o ../dist/host/$@
7374
mkdir -p ../dist/wasix
74-
clang $(CFLAGS) $(CLFLAGS) \
75+
${CC} $(CFLAGS) $(CLFLAGS) \
7576
7677
-o ../dist/wasix/[email protected]
7778
wasm-opt -O2 --asyncify ../dist/wasix/[email protected] -o ../dist/wasix/[email protected]

examples/getrandom.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdio.h>
2+
#include <sys/random.h>
3+
#include <unistd.h>
4+
5+
int print_random_int_array() {
6+
ssize_t retval;
7+
int buf[100];
8+
retval = getrandom(buf, sizeof(int) * 100, 0);
9+
if (retval == -1) {
10+
return retval;
11+
}
12+
for (int i = 0; i < 100; ++i) {
13+
printf("%d ", buf[i]);
14+
}
15+
printf("\n");
16+
return 0;
17+
}
18+
19+
int main() {
20+
int i = 0, retval = 0;
21+
while (i < 5) {
22+
printf("trial %d:\n ", i);
23+
retval = print_random_int_array();
24+
printf("\n");
25+
if (retval == -1) {
26+
printf("failed!\n");
27+
return retval;
28+
}
29+
i++;
30+
}
31+
return 0;
32+
}

examples/readdir_tree.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <stdarg.h>
2+
#include <stdio.h>
3+
#include <sys/random.h>
4+
#include <unistd.h>
5+
#include <string.h>
6+
7+
#include <dirent.h>
8+
9+
void print(int lvl, const char *format, ...) {
10+
for (int i = 0; i < lvl; i++) {
11+
printf(" ");
12+
}
13+
va_list args;
14+
va_start(args, format);
15+
vprintf(format, args);
16+
va_end(args);
17+
fflush(stdout);
18+
}
19+
20+
int handle_dir(int lvl, DIR *d) {
21+
DIR *new;
22+
int ret = 0;
23+
for (;;) {
24+
struct dirent *ent = readdir(d);
25+
if (ent == NULL) {
26+
return 0;
27+
}
28+
29+
if (strcmp(ent->d_name, "..") == 0 || strcmp(ent->d_name, ".") == 0) {
30+
continue;
31+
}
32+
33+
switch (ent->d_type) {
34+
case DT_DIR:
35+
print(lvl, "%s:\n", ent->d_name);
36+
new = opendir(ent->d_name);
37+
ret = handle_dir(lvl + 1, new);
38+
if (ret < 0) {
39+
return ret;
40+
}
41+
continue;
42+
default:
43+
print(lvl, "%s\n", ent->d_name);
44+
}
45+
}
46+
47+
return ret;
48+
}
49+
50+
int main(int argc, char *argv[]) {
51+
if (argc < 1) {
52+
fprintf(stderr, "not enough args!");
53+
}
54+
for (int i = 1; i < argc; i++) {
55+
print(0, "%s\n", argv[i]);
56+
57+
DIR *d = opendir(argv[i]);
58+
int ret = handle_dir(1, d);
59+
if (ret < 0) {
60+
return ret;
61+
}
62+
}
63+
return 0;
64+
}

expected/wasm32-wasi/defined-symbols.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ __fwritex
103103
__fwriting
104104
__get_handler_set
105105
__get_locale
106+
__get_resolv_conf
106107
__getdelim
107108
__getentropy
108109
__getgr_a
@@ -113,6 +114,7 @@ __getpwent_a
113114
__gettext_lockptr
114115
__gettextdomain
115116
__gmtime_r
117+
__h_errno_location
116118
__hwcap
117119
__inet_aton
118120
__inhibit_ptc
@@ -184,6 +186,10 @@ __log2_data
184186
__log2f_data
185187
__log_data
186188
__logf_data
189+
__lookup_ipliteral
190+
__lookup_name
191+
__lookup_serv
192+
__lookup_serv_wasi
187193
__lseek
188194
__main_void
189195
__malloc_atfork
@@ -560,6 +566,7 @@ acosh
560566
acoshf
561567
acoshl
562568
acosl
569+
add_entry
563570
alarm
564571
aligned_alloc
565572
alphasort
@@ -742,6 +749,7 @@ duplocale
742749
ecvt
743750
encrypt
744751
endgrent
752+
endprotoent
745753
endpwent
746754
endspent
747755
environ
@@ -869,6 +877,7 @@ fputws_unlocked
869877
fread
870878
fread_unlocked
871879
free
880+
freeaddrinfo
872881
freeif_addrs
873882
freelocale
874883
freopen
@@ -901,9 +910,11 @@ fwrite_unlocked
901910
fwscanf
902911
gcvt
903912
get_avphys_pages
913+
get_entry
904914
get_nprocs
905915
get_nprocs_conf
906916
get_phys_pages
917+
getaddrinfo
907918
getc
908919
getc_unlocked
909920
getchar
@@ -925,11 +936,17 @@ getgrgid_r
925936
getgrnam
926937
getgrnam_r
927938
getgrouplist
939+
gethostbyaddr
940+
gethostbyaddr_r
941+
gethostbyname
942+
gethostbyname2
943+
gethostbyname2_r
928944
gethostid
929945
gethostname
930946
getif_addrs
931947
getitimer
932948
getline
949+
getnameinfo
933950
getopt
934951
getopt_long
935952
getopt_long_only
@@ -939,6 +956,9 @@ getpgid
939956
getpgrp
940957
getpid
941958
getppid
959+
getprotobyname
960+
getprotobynumber
961+
getprotoent
942962
getpwent
943963
getpwnam
944964
getpwnam_r
@@ -948,6 +968,9 @@ getrandom
948968
getrlimit
949969
getrlimit64
950970
getrusage
971+
getservbyname
972+
getservbyname_r
973+
getservbyport
951974
getsid
952975
getsockname
953976
getsockopt
@@ -969,12 +992,14 @@ globfree
969992
globfree64
970993
gmtime
971994
gmtime_r
995+
h_errno
972996
hcreate
973997
hcreate_r
974998
hdestroy
975999
hdestroy_r
9761000
hsearch
9771001
hsearch_r
1002+
hstrerror
9781003
htonl
9791004
htons
9801005
hypot
@@ -994,6 +1019,7 @@ index
9941019
inet_aton
9951020
inet_ntop
9961021
inet_pton
1022+
init_services
9971023
initstate
9981024
insque
9991025
ioctl
@@ -1428,13 +1454,15 @@ send
14281454
sendfile
14291455
sendmsg
14301456
sendto
1457+
services
14311458
setbuf
14321459
setbuffer
14331460
setegid
14341461
setenv
14351462
seteuid
14361463
setgid
14371464
setgrent
1465+
setgroups
14381466
setitimer
14391467
setjmp
14401468
setkey
@@ -1443,6 +1471,7 @@ setlocale
14431471
setlogmask
14441472
setpgid
14451473
setpgrp
1474+
setprotoent
14461475
setpwent
14471476
setrlimit
14481477
setrlimit64

expected/wasm32-wasi/include-all.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
#include <memory.h>
117117
#include <monetary.h>
118118
#include <mqueue.h>
119+
#include <net/if.h>
119120
#include <netdb.h>
120121
#include <netinet/icmp6.h>
121122
#include <netinet/igmp.h>
@@ -161,6 +162,7 @@
161162
#include <sys/random.h>
162163
#include <sys/reg.h>
163164
#include <sys/select.h>
165+
#include <sys/sendfile.h>
164166
#include <sys/socket.h>
165167
#include <sys/stat.h>
166168
#include <sys/stropts.h>

0 commit comments

Comments
 (0)