aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-05-18 16:00:06 +0200
committerJakub Konka <kubkon@jakubkonka.com>2021-05-20 16:54:00 +0200
commit7b74de7d717e2167337ba8a23e73baf99239529f (patch)
tree2eb631f92e8df09ab388b3d3ea226f07f224d69e /src
parent782cfedaf6452b00df948132284da65fa3ac8fdd (diff)
downloadzig-7b74de7d717e2167337ba8a23e73baf99239529f.tar.gz
zig-7b74de7d717e2167337ba8a23e73baf99239529f.zip
wasi,cc: fix naming and add stubs for building
Rename include dir to match the convention: from `wasm32-wasi` to `wasm-wasi-musl` Add building stubs which will be used to build and cache WASI libc sysroot.
Diffstat (limited to 'src')
-rw-r--r--src/Compilation.zig21
-rw-r--r--src/target.zig1
-rw-r--r--src/wasi_libc.zig12
3 files changed, 34 insertions, 0 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index ff36df198a..5c856b6217 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -21,6 +21,7 @@ const musl = @import("musl.zig");
const mingw = @import("mingw.zig");
const libunwind = @import("libunwind.zig");
const libcxx = @import("libcxx.zig");
+const wasi_libc = @import("wasi_libc.zig");
const fatal = @import("main.zig").fatal;
const Module = @import("Module.zig");
const Cache = @import("Cache.zig");
@@ -202,6 +203,8 @@ const Job = union(enum) {
/// needed when not linking libc and using LLVM for code generation because it generates
/// calls to, for example, memcpy and memset.
zig_libc: void,
+ /// WASI libc sysroot
+ wasi_libc_sysroot: void,
/// Use stage1 C++ code to compile zig code into an object file.
stage1_module: void,
@@ -276,6 +279,7 @@ pub const MiscTask = enum {
libcxx,
libcxxabi,
libtsan,
+ wasi_libc_sysroot,
compiler_rt,
libssp,
zig_libc,
@@ -1414,6 +1418,9 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
},
});
}
+ if (comp.wantBuildWASILibcSysrootFromSource()) {
+ try comp.work_queue.write(&[_]Job{.{ .wasi_libc_sysroot = {} }});
+ }
if (comp.wantBuildMinGWFromSource()) {
const static_lib_jobs = [_]Job{
.{ .mingw_crt_file = .mingw32_lib },
@@ -2139,6 +2146,16 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
);
};
},
+ .wasi_libc_sysroot => {
+ wasi_libc.buildWASILibcSysroot(self) catch |err| {
+ // TODO Surface more error details.
+ try self.setMiscFailure(
+ .wasi_libc_sysroot,
+ "unable to build WASI libc sysroot: {s}",
+ .{@errorName(err)},
+ );
+ };
+ },
.compiler_rt_lib => {
self.buildOutputFromZig(
"compiler_rt.zig",
@@ -3285,6 +3302,10 @@ fn wantBuildMuslFromSource(comp: Compilation) bool {
!comp.getTarget().isWasm();
}
+fn wantBuildWASILibcSysrootFromSource(comp: Compilation) bool {
+ return comp.wantBuildLibCFromSource() and comp.getTarget().isWasm();
+}
+
fn wantBuildMinGWFromSource(comp: Compilation) bool {
return comp.wantBuildLibCFromSource() and comp.getTarget().isMinGW();
}
diff --git a/src/target.zig b/src/target.zig
index 28b4771d0a..cb6aecf645 100644
--- a/src/target.zig
+++ b/src/target.zig
@@ -57,6 +57,7 @@ pub const available_libcs = [_]ArchOsAbi{
.{ .arch = .sparc, .os = .linux, .abi = .gnu },
.{ .arch = .sparcv9, .os = .linux, .abi = .gnu },
.{ .arch = .wasm32, .os = .freestanding, .abi = .musl },
+ .{ .arch = .wasm32, .os = .wasi, .abi = .musl },
.{ .arch = .x86_64, .os = .linux, .abi = .gnu },
.{ .arch = .x86_64, .os = .linux, .abi = .gnux32 },
.{ .arch = .x86_64, .os = .linux, .abi = .musl },
diff --git a/src/wasi_libc.zig b/src/wasi_libc.zig
new file mode 100644
index 0000000000..2928c8e4cb
--- /dev/null
+++ b/src/wasi_libc.zig
@@ -0,0 +1,12 @@
+const std = @import("std");
+
+const Compilation = @import("Compilation.zig");
+const build_options = @import("build_options");
+
+pub fn buildWASILibcSysroot(comp: *Compilation) !void {
+ if (!build_options.have_llvm) {
+ return error.ZigCompilerNotBuiltWithLLVMExtensions;
+ }
+
+ return error.TODOBuildWASILibcSysroot;
+}