aboutsummaryrefslogtreecommitdiff
path: root/src/libs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/wasi_libc.zig209
1 files changed, 162 insertions, 47 deletions
diff --git a/src/libs/wasi_libc.zig b/src/libs/wasi_libc.zig
index d71740e5e6..4af86f28f2 100644
--- a/src/libs/wasi_libc.zig
+++ b/src/libs/wasi_libc.zig
@@ -44,6 +44,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
var args = std.array_list.Managed([]const u8).init(arena);
try addCCArgs(comp, arena, &args, .{});
try addLibcBottomHalfIncludes(comp, arena, &args);
+
var files = [_]Compilation.CSourceFile{
.{
.src_path = try comp.dirs.zig_lib.join(arena, &.{
@@ -53,12 +54,14 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
.owner = undefined,
},
};
+
return comp.build_crt_file("crt1-reactor", .Obj, .@"wasi crt1-reactor.o", prog_node, &files, .{});
},
.crt1_command_o => {
var args = std.array_list.Managed([]const u8).init(arena);
try addCCArgs(comp, arena, &args, .{});
try addLibcBottomHalfIncludes(comp, arena, &args);
+
var files = [_]Compilation.CSourceFile{
.{
.src_path = try comp.dirs.zig_lib.join(arena, &.{
@@ -68,6 +71,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
.owner = undefined,
},
};
+
return comp.build_crt_file("crt1-command", .Obj, .@"wasi crt1-command.o", prog_node, &files, .{});
},
.libc_a => {
@@ -77,6 +81,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
// Compile emmalloc.
var args = std.array_list.Managed([]const u8).init(arena);
try addCCArgs(comp, arena, &args, .{ .want_O3 = true, .no_strict_aliasing = true });
+
for (emmalloc_src_files) |file_path| {
try libc_sources.append(.{
.src_path = try comp.dirs.zig_lib.join(arena, &.{
@@ -123,10 +128,51 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
}
{
+ // Compile musl-fts.
+ var args = std.array_list.Managed([]const u8).init(arena);
+ try addCCArgs(comp, arena, &args, .{ .want_O3 = true });
+ try args.appendSlice(&[_][]const u8{
+ "-I",
+ try comp.dirs.zig_lib.join(arena, &.{
+ "libc",
+ "wasi",
+ "fts",
+ }),
+ });
+
+ for (fts_src_files) |file_path| {
+ try libc_sources.append(.{
+ .src_path = try comp.dirs.zig_lib.join(arena, &.{
+ "libc", try sanitize(arena, file_path),
+ }),
+ .extra_flags = args.items,
+ .owner = undefined,
+ });
+ }
+ }
+
+ if (comp.getTarget().cpu.has(.wasm, .exception_handling)) {
+ // Compile libsetjmp.
+ var args = std.array_list.Managed([]const u8).init(arena);
+ try addCCArgs(comp, arena, &args, .{ .want_O3 = true });
+ try addLibcTopHalfIncludes(comp, arena, &args);
+
+ for (setjmp_src_files) |file_path| {
+ try libc_sources.append(.{
+ .src_path = try comp.dirs.zig_lib.join(arena, &.{
+ "libc", try sanitize(arena, file_path),
+ }),
+ .extra_flags = args.items,
+ .owner = undefined,
+ });
+ }
+ }
+
+ {
// Compile libdl.
var args = std.array_list.Managed([]const u8).init(arena);
try addCCArgs(comp, arena, &args, .{ .want_O3 = true });
- try addLibcBottomHalfIncludes(comp, arena, &args);
+ try addLibcTopHalfIncludes(comp, arena, &args);
for (emulated_dl_src_files) |file_path| {
try libc_sources.append(.{
@@ -143,16 +189,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
// Compile libwasi-emulated-process-clocks.
var args = std.array_list.Managed([]const u8).init(arena);
try addCCArgs(comp, arena, &args, .{ .want_O3 = true });
- try args.appendSlice(&.{
- "-I",
- try comp.dirs.zig_lib.join(arena, &.{
- "libc",
- "wasi",
- "libc-bottom-half",
- "cloudlibc",
- "src",
- }),
- });
for (emulated_process_clocks_src_files) |file_path| {
try libc_sources.append(.{
@@ -169,7 +205,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
// Compile libwasi-emulated-getpid.
var args = std.array_list.Managed([]const u8).init(arena);
try addCCArgs(comp, arena, &args, .{ .want_O3 = true });
- try addLibcBottomHalfIncludes(comp, arena, &args);
for (emulated_getpid_src_files) |file_path| {
try libc_sources.append(.{
@@ -186,7 +221,6 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
// Compile libwasi-emulated-mman.
var args = std.array_list.Managed([]const u8).init(arena);
try addCCArgs(comp, arena, &args, .{ .want_O3 = true });
- try addLibcBottomHalfIncludes(comp, arena, &args);
for (emulated_mman_src_files) |file_path| {
try libc_sources.append(.{
@@ -278,13 +312,18 @@ fn addCCArgs(
"-mthread-model",
"single",
- "-isysroot",
- "/",
+ "-I",
+ try comp.dirs.zig_lib.join(arena, &.{
+ "libc",
+ "wasi",
+ "libc-bottom-half",
+ "cloudlibc",
+ "src",
+ }),
- "-iwithsysroot",
+ "-isystem",
try comp.dirs.zig_lib.join(arena, &.{ "libc", "include", triple }),
-
- "-iwithsysroot",
+ "-isystem",
try comp.dirs.zig_lib.join(arena, &.{ "libc", "include", "generic-musl" }),
"-DBULK_MEMORY_THRESHOLD=32",
@@ -338,7 +377,6 @@ fn addLibcBottomHalfIncludes(
"src",
"include",
}),
-
"-I",
try comp.dirs.zig_lib.join(arena, &.{
"libc",
@@ -346,8 +384,8 @@ fn addLibcBottomHalfIncludes(
"src",
"include",
}),
-
"-I",
+
try comp.dirs.zig_lib.join(arena, &.{
"libc",
"wasi",
@@ -356,7 +394,6 @@ fn addLibcBottomHalfIncludes(
"src",
"internal",
}),
-
"-I",
try comp.dirs.zig_lib.join(arena, &.{
"libc",
@@ -382,7 +419,6 @@ fn addLibcTopHalfIncludes(
"src",
"include",
}),
-
"-I",
try comp.dirs.zig_lib.join(arena, &.{
"libc",
@@ -400,7 +436,6 @@ fn addLibcTopHalfIncludes(
"src",
"internal",
}),
-
"-I",
try comp.dirs.zig_lib.join(arena, &.{
"libc",
@@ -418,7 +453,6 @@ fn addLibcTopHalfIncludes(
"arch",
"wasm32",
}),
-
"-I",
try comp.dirs.zig_lib.join(arena, &.{
"libc",
@@ -469,8 +503,8 @@ const libc_bottom_half_src_files = [_][]const u8{
"wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c",
- "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c",
+ "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c",
@@ -479,11 +513,11 @@ const libc_bottom_half_src_files = [_][]const u8{
"wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/pwritev.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c",
- "wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c",
- "wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c",
+ "wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c",
+ "wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/time/time.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c",
@@ -501,25 +535,18 @@ const libc_bottom_half_src_files = [_][]const u8{
"wasi/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c",
"wasi/libc-bottom-half/cloudlibc/src/libc/unistd/write.c",
- "wasi/libc-bottom-half/sources/__errno_location.c",
- "wasi/libc-bottom-half/sources/__main_void.c",
- "wasi/libc-bottom-half/sources/__wasilibc_dt.c",
- "wasi/libc-bottom-half/sources/__wasilibc_environ.c",
- "wasi/libc-bottom-half/sources/__wasilibc_fd_renumber.c",
- "wasi/libc-bottom-half/sources/__wasilibc_initialize_environ.c",
- "wasi/libc-bottom-half/sources/__wasilibc_real.c",
- "wasi/libc-bottom-half/sources/__wasilibc_rmdirat.c",
- "wasi/libc-bottom-half/sources/__wasilibc_tell.c",
- "wasi/libc-bottom-half/sources/__wasilibc_unlinkat.c",
"wasi/libc-bottom-half/sources/abort.c",
"wasi/libc-bottom-half/sources/accept-wasip1.c",
"wasi/libc-bottom-half/sources/at_fdcwd.c",
+ "wasi/libc-bottom-half/sources/chdir.c",
"wasi/libc-bottom-half/sources/complex-builtins.c",
"wasi/libc-bottom-half/sources/environ.c",
"wasi/libc-bottom-half/sources/errno.c",
+ "wasi/libc-bottom-half/sources/__errno_location.c",
"wasi/libc-bottom-half/sources/getcwd.c",
"wasi/libc-bottom-half/sources/getentropy.c",
"wasi/libc-bottom-half/sources/isatty.c",
+ "wasi/libc-bottom-half/sources/__main_void.c",
"wasi/libc-bottom-half/sources/math/fmin-fmax.c",
"wasi/libc-bottom-half/sources/math/math-builtins.c",
"wasi/libc-bottom-half/sources/posix.c",
@@ -527,7 +554,15 @@ const libc_bottom_half_src_files = [_][]const u8{
"wasi/libc-bottom-half/sources/reallocarray.c",
"wasi/libc-bottom-half/sources/sbrk.c",
"wasi/libc-bottom-half/sources/truncate.c",
- "wasi/libc-bottom-half/sources/chdir.c",
+ "wasi/libc-bottom-half/sources/__wasilibc_dt.c",
+ "wasi/libc-bottom-half/sources/__wasilibc_environ.c",
+ "wasi/libc-bottom-half/sources/__wasilibc_fd_renumber.c",
+ "wasi/libc-bottom-half/sources/__wasilibc_initialize_environ.c",
+ "wasi/libc-bottom-half/sources/__wasilibc_random.c",
+ "wasi/libc-bottom-half/sources/__wasilibc_real.c",
+ "wasi/libc-bottom-half/sources/__wasilibc_rmdirat.c",
+ "wasi/libc-bottom-half/sources/__wasilibc_tell.c",
+ "wasi/libc-bottom-half/sources/__wasilibc_unlinkat.c",
};
const libc_top_half_src_files = [_][]const u8{
@@ -593,6 +628,7 @@ const libc_top_half_src_files = [_][]const u8{
"musl/src/complex/ctanhf.c",
"musl/src/complex/ctanhl.c",
"musl/src/complex/ctanl.c",
+ "musl/src/conf/confstr.c",
"musl/src/conf/legacy.c",
"musl/src/conf/pathconf.c",
"musl/src/crypt/crypt_blowfish.c",
@@ -971,8 +1007,10 @@ const libc_top_half_src_files = [_][]const u8{
"musl/src/stdio/__toread.c",
"musl/src/stdio/__towrite.c",
"musl/src/stdio/__uflow.c",
+ "musl/src/stdio/ungetc.c",
"musl/src/stdio/ungetwc.c",
"musl/src/stdio/vasprintf.c",
+ "musl/src/stdio/vfwscanf.c",
"musl/src/stdio/vprintf.c",
"musl/src/stdio/vscanf.c",
"musl/src/stdio/vsprintf.c",
@@ -994,23 +1032,20 @@ const libc_top_half_src_files = [_][]const u8{
"musl/src/stdlib/lldiv.c",
"musl/src/stdlib/qsort.c",
"musl/src/stdlib/qsort_nr.c",
+ "musl/src/stdlib/strtol.c",
"musl/src/string/bcmp.c",
"musl/src/string/bcopy.c",
"musl/src/string/explicit_bzero.c",
"musl/src/string/index.c",
"musl/src/string/memccpy.c",
- "musl/src/string/memchr.c",
- "musl/src/string/memcmp.c",
"musl/src/string/memmem.c",
"musl/src/string/mempcpy.c",
- "musl/src/string/memrchr.c",
"musl/src/string/rindex.c",
"musl/src/string/stpcpy.c",
"musl/src/string/stpncpy.c",
"musl/src/string/strcasestr.c",
"musl/src/string/strcat.c",
"musl/src/string/strchr.c",
- "musl/src/string/strchrnul.c",
"musl/src/string/strcpy.c",
"musl/src/string/strcspn.c",
"musl/src/string/strdup.c",
@@ -1058,6 +1093,37 @@ const libc_top_half_src_files = [_][]const u8{
"musl/src/string/wmemcpy.c",
"musl/src/string/wmemmove.c",
"musl/src/string/wmemset.c",
+ "musl/src/thread/default_attr.c",
+ "musl/src/thread/pthread_attr_destroy.c",
+ "musl/src/thread/pthread_attr_init.c",
+ "musl/src/thread/pthread_attr_setdetachstate.c",
+ "musl/src/thread/pthread_attr_setstack.c",
+ "musl/src/thread/pthread_attr_setstacksize.c",
+ "musl/src/thread/pthread_barrierattr_destroy.c",
+ "musl/src/thread/pthread_barrierattr_init.c",
+ "musl/src/thread/pthread_barrierattr_setpshared.c",
+ "musl/src/thread/pthread_cleanup_push.c",
+ "musl/src/thread/pthread_condattr_destroy.c",
+ "musl/src/thread/pthread_condattr_init.c",
+ "musl/src/thread/pthread_condattr_setpshared.c",
+ "musl/src/thread/pthread_equal.c",
+ "musl/src/thread/pthread_getspecific.c",
+ "musl/src/thread/pthread_mutexattr_destroy.c",
+ "musl/src/thread/pthread_mutexattr_init.c",
+ "musl/src/thread/pthread_mutexattr_setpshared.c",
+ "musl/src/thread/pthread_mutexattr_settype.c",
+ "musl/src/thread/pthread_mutex_init.c",
+ "musl/src/thread/pthread_rwlockattr_destroy.c",
+ "musl/src/thread/pthread_rwlockattr_init.c",
+ "musl/src/thread/pthread_rwlockattr_setpshared.c",
+ "musl/src/thread/pthread_rwlock_destroy.c",
+ "musl/src/thread/pthread_rwlock_init.c",
+ "musl/src/thread/pthread_setcancelstate.c",
+ "musl/src/thread/pthread_setcanceltype.c",
+ "musl/src/thread/pthread_setspecific.c",
+ "musl/src/thread/pthread_spin_destroy.c",
+ "musl/src/thread/pthread_spin_init.c",
+ "musl/src/thread/pthread_testcancel.c",
"musl/src/thread/thrd_sleep.c",
"musl/src/time/asctime.c",
"musl/src/time/asctime_r.c",
@@ -1071,7 +1137,6 @@ const libc_top_half_src_files = [_][]const u8{
"musl/src/time/__year_to_secs.c",
"musl/src/unistd/posix_close.c",
- "wasi/libc-top-half/musl/src/conf/confstr.c",
"wasi/libc-top-half/musl/src/conf/fpathconf.c",
"wasi/libc-top-half/musl/src/conf/sysconf.c",
"wasi/libc-top-half/musl/src/dirent/alphasort.c",
@@ -1112,9 +1177,9 @@ const libc_top_half_src_files = [_][]const u8{
"wasi/libc-top-half/musl/src/misc/nftw.c",
"wasi/libc-top-half/musl/src/misc/uname.c",
"wasi/libc-top-half/musl/src/prng/random.c",
+ "wasi/libc-top-half/musl/src/regex/glob.c",
"wasi/libc-top-half/musl/src/regex/regcomp.c",
"wasi/libc-top-half/musl/src/regex/regexec.c",
- "wasi/libc-top-half/musl/src/regex/glob.c",
"wasi/libc-top-half/musl/src/regex/tre-mem.c",
"wasi/libc-top-half/musl/src/stat/futimesat.c",
"wasi/libc-top-half/musl/src/stdio/__fdopen.c",
@@ -1144,21 +1209,32 @@ const libc_top_half_src_files = [_][]const u8{
"wasi/libc-top-half/musl/src/stdio/__stdio_write.c",
"wasi/libc-top-half/musl/src/stdio/stdout.c",
"wasi/libc-top-half/musl/src/stdio/__stdout_write.c",
- "wasi/libc-top-half/musl/src/stdio/ungetc.c",
"wasi/libc-top-half/musl/src/stdio/vdprintf.c",
"wasi/libc-top-half/musl/src/stdio/vfprintf.c",
"wasi/libc-top-half/musl/src/stdio/vfscanf.c",
"wasi/libc-top-half/musl/src/stdio/vfwprintf.c",
- "wasi/libc-top-half/musl/src/stdio/vfwscanf.c",
"wasi/libc-top-half/musl/src/stdio/vsnprintf.c",
"wasi/libc-top-half/musl/src/stdio/vsscanf.c",
"wasi/libc-top-half/musl/src/stdio/vswprintf.c",
"wasi/libc-top-half/musl/src/stdio/vswscanf.c",
"wasi/libc-top-half/musl/src/stdlib/strtod.c",
- "wasi/libc-top-half/musl/src/stdlib/strtol.c",
"wasi/libc-top-half/musl/src/stdlib/wcstod.c",
"wasi/libc-top-half/musl/src/stdlib/wcstol.c",
+ "wasi/libc-top-half/musl/src/string/memchr.c",
+ "wasi/libc-top-half/musl/src/string/memcmp.c",
+ "wasi/libc-top-half/musl/src/string/memrchr.c",
"wasi/libc-top-half/musl/src/string/memset.c",
+ "wasi/libc-top-half/musl/src/string/strchrnul.c",
+ "wasi/libc-top-half/musl/src/thread/pthread_attr_get.c",
+ "wasi/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c",
+ "wasi/libc-top-half/musl/src/thread/pthread_attr_setschedparam.c",
+ "wasi/libc-top-half/musl/src/thread/pthread_cancel.c",
+ "wasi/libc-top-half/musl/src/thread/pthread_condattr_setclock.c",
+ "wasi/libc-top-half/musl/src/thread/pthread_key_create.c",
+ "wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c",
+ "wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c",
+ "wasi/libc-top-half/musl/src/thread/pthread_mutex_destroy.c",
+ "wasi/libc-top-half/musl/src/thread/pthread_self.c",
"wasi/libc-top-half/musl/src/time/getdate.c",
"wasi/libc-top-half/musl/src/time/gmtime.c",
"wasi/libc-top-half/musl/src/time/gmtime_r.c",
@@ -1173,11 +1249,50 @@ const libc_top_half_src_files = [_][]const u8{
"wasi/libc-top-half/musl/src/time/wcsftime.c",
"wasi/libc-top-half/sources/arc4random.c",
+
+ "wasi/thread-stub/pthread_barrier_destroy.c",
+ "wasi/thread-stub/pthread_barrier_init.c",
+ "wasi/thread-stub/pthread_barrier_wait.c",
+ "wasi/thread-stub/pthread_cond_broadcast.c",
+ "wasi/thread-stub/pthread_cond_destroy.c",
+ "wasi/thread-stub/pthread_cond_init.c",
+ "wasi/thread-stub/pthread_cond_signal.c",
+ "wasi/thread-stub/pthread_cond_timedwait.c",
+ "wasi/thread-stub/pthread_cond_wait.c",
+ "wasi/thread-stub/pthread_create.c",
+ "wasi/thread-stub/pthread_detach.c",
+ "wasi/thread-stub/pthread_getattr_np.c",
+ "wasi/thread-stub/pthread_join.c",
+ "wasi/thread-stub/pthread_mutex_consistent.c",
+ "wasi/thread-stub/pthread_mutex_getprioceiling.c",
+ "wasi/thread-stub/pthread_mutex_lock.c",
+ "wasi/thread-stub/pthread_mutex_timedlock.c",
+ "wasi/thread-stub/pthread_mutex_trylock.c",
+ "wasi/thread-stub/pthread_mutex_unlock.c",
+ "wasi/thread-stub/pthread_once.c",
+ "wasi/thread-stub/pthread_rwlock_rdlock.c",
+ "wasi/thread-stub/pthread_rwlock_timedrdlock.c",
+ "wasi/thread-stub/pthread_rwlock_timedwrlock.c",
+ "wasi/thread-stub/pthread_rwlock_tryrdlock.c",
+ "wasi/thread-stub/pthread_rwlock_trywrlock.c",
+ "wasi/thread-stub/pthread_rwlock_unlock.c",
+ "wasi/thread-stub/pthread_rwlock_wrlock.c",
+ "wasi/thread-stub/pthread_spin_lock.c",
+ "wasi/thread-stub/pthread_spin_trylock.c",
+ "wasi/thread-stub/pthread_spin_unlock.c",
};
const crt1_command_src_file = "wasi/libc-bottom-half/crt/crt1-command.c";
const crt1_reactor_src_file = "wasi/libc-bottom-half/crt/crt1-reactor.c";
+const fts_src_files = &[_][]const u8{
+ "wasi/fts/musl-fts/fts.c",
+};
+
+const setjmp_src_files = &[_][]const u8{
+ "wasi/libc-top-half/musl/src/setjmp/wasm32/rt.c",
+};
+
const emulated_dl_src_files = &[_][]const u8{
"wasi/libc-top-half/musl/src/misc/dl.c",
};