diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-06-07 11:02:11 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-06-09 01:25:38 +0200 |
| commit | 4e4722a65e3bc3d6bb4518df3082ffea7c2a7c5d (patch) | |
| tree | 02bf3ff87229ec8df06bd8296050e318e1cb90cc /src/Compilation.zig | |
| parent | 93a4403271ef62d8ae2cd10f58cc23d4b7bbdf4d (diff) | |
| download | zig-4e4722a65e3bc3d6bb4518df3082ffea7c2a7c5d.tar.gz zig-4e4722a65e3bc3d6bb4518df3082ffea7c2a7c5d.zip | |
cc,wasi: build referenced-only emulated components
Move parsing of system libs into `main.zig` next to where we decide
if we should link libC, and, if targeting WASI, if the specified
libname equals one of the emulated components, save it on the side
and remove it from the system libs. Then, build *only* those parts
of WASI libc that were preserved in the previous step.
This also fixes building of different crt1 bits needed to support
reactors and commands.
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 4c015cb58f..444e69c557 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -203,8 +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, + /// one of WASI libc static objects + wasi_libc_crt_file: wasi_libc.CRTFile, /// Use stage1 C++ code to compile zig code into an object file. stage1_module: void, @@ -279,7 +279,7 @@ pub const MiscTask = enum { libcxx, libcxxabi, libtsan, - wasi_libc_sysroot, + wasi_libc_crt_file, compiler_rt, libssp, zig_libc, @@ -646,6 +646,12 @@ pub const InitOptions = struct { framework_dirs: []const []const u8 = &[0][]const u8{}, frameworks: []const []const u8 = &[0][]const u8{}, system_libs: []const []const u8 = &[0][]const u8{}, + /// These correspond to the WASI libc emulated subcomponents including: + /// * process clocks + /// * getpid + /// * mman + /// * signal + wasi_emulated_libs: []const []const u8 = &[0][]const u8{}, link_libc: bool = false, link_libcpp: bool = false, link_libunwind: bool = false, @@ -1286,6 +1292,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { .framework_dirs = options.framework_dirs, .system_libs = system_libs, .syslibroot = darwin_options.syslibroot, + .wasi_emulated_libs = options.wasi_emulated_libs, .lib_dirs = options.lib_dirs, .rpath_list = options.rpath_list, .strip = strip, @@ -1426,8 +1433,19 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { }, }); } - if (comp.wantBuildWasiLibcSysrootFromSource()) { - try comp.work_queue.write(&[_]Job{.{ .wasi_libc_sysroot = {} }}); + if (comp.wantBuildWasiLibcFromSource()) { + try comp.work_queue.ensureUnusedCapacity(6); // worst-case we need all components + const wasi_emulated_libs = comp.bin_file.options.wasi_emulated_libs; + for (wasi_emulated_libs) |lib_name| { + comp.work_queue.writeItemAssumeCapacity(.{ + .wasi_libc_crt_file = wasi_libc.getEmulatedLibCRTFile(lib_name).?, + }); + } + // TODO add logic deciding which crt1 we want here. + comp.work_queue.writeAssumeCapacity(&[_]Job{ + .{ .wasi_libc_crt_file = .crt1_o }, + .{ .wasi_libc_crt_file = .libc_a }, + }); } if (comp.wantBuildMinGWFromSource()) { const static_lib_jobs = [_]Job{ @@ -2169,12 +2187,12 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor ); }; }, - .wasi_libc_sysroot => { - wasi_libc.buildWasiLibcSysroot(self) catch |err| { + .wasi_libc_crt_file => |crt_file| { + wasi_libc.buildCRTFile(self, crt_file) catch |err| { // TODO Surface more error details. try self.setMiscFailure( - .wasi_libc_sysroot, - "unable to build WASI libc sysroot: {s}", + .wasi_libc_crt_file, + "unable to build WASI libc CRT file: {s}", .{@errorName(err)}, ); }; @@ -3303,7 +3321,7 @@ pub fn get_libc_crt_file(comp: *Compilation, arena: *Allocator, basename: []cons if (comp.wantBuildGLibCFromSource() or comp.wantBuildMuslFromSource() or comp.wantBuildMinGWFromSource() or - comp.wantBuildWasiLibcSysrootFromSource()) + comp.wantBuildWasiLibcFromSource()) { return comp.crt_files.get(basename).?.full_object_path; } @@ -3343,8 +3361,9 @@ fn wantBuildMuslFromSource(comp: Compilation) bool { !comp.getTarget().isWasm(); } -fn wantBuildWasiLibcSysrootFromSource(comp: Compilation) bool { - return comp.wantBuildLibCFromSource() and comp.getTarget().isWasm(); +fn wantBuildWasiLibcFromSource(comp: Compilation) bool { + return comp.wantBuildLibCFromSource() and comp.getTarget().isWasm() and + comp.getTarget().os.tag == .wasi; } fn wantBuildMinGWFromSource(comp: Compilation) bool { |
