| ... | @@ -10,43 +10,8 @@ pub const CrtFile = enum { | ... | @@ -10,43 +10,8 @@ pub const CrtFile = enum { |
| 10 | crt1_reactor_o, | 10 | crt1_reactor_o, |
| 11 | crt1_command_o, | 11 | crt1_command_o, |
| 12 | libc_a, | 12 | libc_a, |
| 13 | libdl_a, | | |
| 14 | libwasi_emulated_process_clocks_a, | | |
| 15 | libwasi_emulated_getpid_a, | | |
| 16 | libwasi_emulated_mman_a, | | |
| 17 | libwasi_emulated_signal_a, | | |
| 18 | }; | 13 | }; |
| 19 | | 14 | |
| 20 | pub fn getEmulatedLibCrtFile(lib_name: []const u8) ?CrtFile { | | |
| 21 | if (mem.eql(u8, lib_name, "dl")) { | | |
| 22 | return .libdl_a; | | |
| 23 | } | | |
| 24 | if (mem.eql(u8, lib_name, "wasi-emulated-process-clocks")) { | | |
| 25 | return .libwasi_emulated_process_clocks_a; | | |
| 26 | } | | |
| 27 | if (mem.eql(u8, lib_name, "wasi-emulated-getpid")) { | | |
| 28 | return .libwasi_emulated_getpid_a; | | |
| 29 | } | | |
| 30 | if (mem.eql(u8, lib_name, "wasi-emulated-mman")) { | | |
| 31 | return .libwasi_emulated_mman_a; | | |
| 32 | } | | |
| 33 | if (mem.eql(u8, lib_name, "wasi-emulated-signal")) { | | |
| 34 | return .libwasi_emulated_signal_a; | | |
| 35 | } | | |
| 36 | return null; | | |
| 37 | } | | |
| 38 | | | |
| 39 | pub fn emulatedLibCRFileLibName(crt_file: CrtFile) []const u8 { | | |
| 40 | return switch (crt_file) { | | |
| 41 | .libdl_a => "libdl.a", | | |
| 42 | .libwasi_emulated_process_clocks_a => "libwasi-emulated-process-clocks.a", | | |
| 43 | .libwasi_emulated_getpid_a => "libwasi-emulated-getpid.a", | | |
| 44 | .libwasi_emulated_mman_a => "libwasi-emulated-mman.a", | | |
| 45 | .libwasi_emulated_signal_a => "libwasi-emulated-signal.a", | | |
| 46 | else => unreachable, | | |
| 47 | }; | | |
| 48 | } | | |
| 49 | | | |
| 50 | pub fn execModelCrtFile(wasi_exec_model: std.builtin.WasiExecModel) CrtFile { | 15 | pub fn execModelCrtFile(wasi_exec_model: std.builtin.WasiExecModel) CrtFile { |
| 51 | return switch (wasi_exec_model) { | 16 | return switch (wasi_exec_model) { |
| 52 | .reactor => CrtFile.crt1_reactor_o, | 17 | .reactor => CrtFile.crt1_reactor_o, |
| ... | @@ -157,87 +122,57 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre | ... | @@ -157,87 +122,57 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 157 | } | 122 | } |
| 158 | } | 123 | } |
| 159 | | 124 | |
| 160 | try comp.build_crt_file("c", .Lib, .@"wasi libc.a", prog_node, libc_sources.items, .{}); | 125 | { |
| 161 | }, | 126 | // Compile libdl. |
| 162 | | 127 | var args = std.ArrayList([]const u8).init(arena); |
| 163 | .libdl_a => { | 128 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| 164 | var args = std.ArrayList([]const u8).init(arena); | 129 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 165 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | | |
| 166 | try addLibcBottomHalfIncludes(comp, arena, &args); | | |
| 167 | | 130 | |
| 168 | var emu_dl_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | 131 | for (emulated_dl_src_files) |file_path| { |
| 169 | for (emulated_dl_src_files) |file_path| { | 132 | try libc_sources.append(.{ |
| 170 | try emu_dl_sources.append(.{ | 133 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ |
| 171 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | 134 | "libc", try sanitize(arena, file_path), |
| 172 | "libc", try sanitize(arena, file_path), | 135 | }), |
| 173 | }), | 136 | .extra_flags = args.items, |
| 174 | .extra_flags = args.items, | 137 | .owner = undefined, |
| 175 | .owner = undefined, | 138 | }); |
| 176 | }); | 139 | } |
| 177 | } | 140 | } |
| 178 | try comp.build_crt_file("dl", .Lib, .@"wasi libdl.a", prog_node, emu_dl_sources.items, .{}); | | |
| 179 | }, | | |
| 180 | | | |
| 181 | .libwasi_emulated_process_clocks_a => { | | |
| 182 | var args = std.ArrayList([]const u8).init(arena); | | |
| 183 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | | |
| 184 | try addLibcBottomHalfIncludes(comp, arena, &args); | | |
| 185 | | 141 | |
| 186 | var emu_clocks_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | 142 | { |
| 187 | for (emulated_process_clocks_src_files) |file_path| { | 143 | // Compile libwasi-emulated-process-clocks. |
| 188 | try emu_clocks_sources.append(.{ | 144 | var args = std.ArrayList([]const u8).init(arena); |
| 189 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | 145 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| 190 | "libc", try sanitize(arena, file_path), | 146 | try args.appendSlice(&.{ |
| | 147 | "-I", |
| | 148 | try comp.dirs.zig_lib.join(arena, &.{ |
| | 149 | "libc", |
| | 150 | "wasi", |
| | 151 | "libc-bottom-half", |
| | 152 | "cloudlibc", |
| | 153 | "src", |
| 191 | }), | 154 | }), |
| 192 | .extra_flags = args.items, | | |
| 193 | .owner = undefined, | | |
| 194 | }); | 155 | }); |
| 195 | } | | |
| 196 | try comp.build_crt_file("wasi-emulated-process-clocks", .Lib, .@"libwasi-emulated-process-clocks.a", prog_node, emu_clocks_sources.items, .{}); | | |
| 197 | }, | | |
| 198 | .libwasi_emulated_getpid_a => { | | |
| 199 | var args = std.ArrayList([]const u8).init(arena); | | |
| 200 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | | |
| 201 | try addLibcBottomHalfIncludes(comp, arena, &args); | | |
| 202 | | 156 | |
| 203 | var emu_getpid_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | 157 | for (emulated_process_clocks_src_files) |file_path| { |
| 204 | for (emulated_getpid_src_files) |file_path| { | 158 | try libc_sources.append(.{ |
| 205 | try emu_getpid_sources.append(.{ | 159 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ |
| 206 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | 160 | "libc", try sanitize(arena, file_path), |
| 207 | "libc", try sanitize(arena, file_path), | 161 | }), |
| 208 | }), | 162 | .extra_flags = args.items, |
| 209 | .extra_flags = args.items, | 163 | .owner = undefined, |
| 210 | .owner = undefined, | 164 | }); |
| 211 | }); | 165 | } |
| 212 | } | | |
| 213 | try comp.build_crt_file("wasi-emulated-getpid", .Lib, .@"libwasi-emulated-getpid.a", prog_node, emu_getpid_sources.items, .{}); | | |
| 214 | }, | | |
| 215 | .libwasi_emulated_mman_a => { | | |
| 216 | var args = std.ArrayList([]const u8).init(arena); | | |
| 217 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | | |
| 218 | try addLibcBottomHalfIncludes(comp, arena, &args); | | |
| 219 | | | |
| 220 | var emu_mman_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | | |
| 221 | for (emulated_mman_src_files) |file_path| { | | |
| 222 | try emu_mman_sources.append(.{ | | |
| 223 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | | |
| 224 | "libc", try sanitize(arena, file_path), | | |
| 225 | }), | | |
| 226 | .extra_flags = args.items, | | |
| 227 | .owner = undefined, | | |
| 228 | }); | | |
| 229 | } | 166 | } |
| 230 | try comp.build_crt_file("wasi-emulated-mman", .Lib, .@"libwasi-emulated-mman.a", prog_node, emu_mman_sources.items, .{}); | | |
| 231 | }, | | |
| 232 | .libwasi_emulated_signal_a => { | | |
| 233 | var emu_signal_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | | |
| 234 | | 167 | |
| 235 | { | 168 | { |
| | 169 | // Compile libwasi-emulated-getpid. |
| 236 | var args = std.ArrayList([]const u8).init(arena); | 170 | var args = std.ArrayList([]const u8).init(arena); |
| 237 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | 171 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| | 172 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 238 | | 173 | |
| 239 | for (emulated_signal_bottom_half_src_files) |file_path| { | 174 | for (emulated_getpid_src_files) |file_path| { |
| 240 | try emu_signal_sources.append(.{ | 175 | try libc_sources.append(.{ |
| 241 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | 176 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ |
| 242 | "libc", try sanitize(arena, file_path), | 177 | "libc", try sanitize(arena, file_path), |
| 243 | }), | 178 | }), |
| ... | @@ -248,13 +183,13 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre | ... | @@ -248,13 +183,13 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 248 | } | 183 | } |
| 249 | | 184 | |
| 250 | { | 185 | { |
| | 186 | // Compile libwasi-emulated-mman. |
| 251 | var args = std.ArrayList([]const u8).init(arena); | 187 | var args = std.ArrayList([]const u8).init(arena); |
| 252 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | 188 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| 253 | try addLibcTopHalfIncludes(comp, arena, &args); | 189 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 254 | try args.append("-D_WASI_EMULATED_SIGNAL"); | | |
| 255 | | 190 | |
| 256 | for (emulated_signal_top_half_src_files) |file_path| { | 191 | for (emulated_mman_src_files) |file_path| { |
| 257 | try emu_signal_sources.append(.{ | 192 | try libc_sources.append(.{ |
| 258 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | 193 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ |
| 259 | "libc", try sanitize(arena, file_path), | 194 | "libc", try sanitize(arena, file_path), |
| 260 | }), | 195 | }), |
| ... | @@ -264,7 +199,38 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre | ... | @@ -264,7 +199,38 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 264 | } | 199 | } |
| 265 | } | 200 | } |
| 266 | | 201 | |
| 267 | try comp.build_crt_file("wasi-emulated-signal", .Lib, .@"libwasi-emulated-signal.a", prog_node, emu_signal_sources.items, .{}); | 202 | { |
| | 203 | // Compile libwasi-emulated-signal. |
| | 204 | var bottom_args = std.ArrayList([]const u8).init(arena); |
| | 205 | try addCCArgs(comp, arena, &bottom_args, .{ .want_O3 = true }); |
| | 206 | |
| | 207 | for (emulated_signal_bottom_half_src_files) |file_path| { |
| | 208 | try libc_sources.append(.{ |
| | 209 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ |
| | 210 | "libc", try sanitize(arena, file_path), |
| | 211 | }), |
| | 212 | .extra_flags = bottom_args.items, |
| | 213 | .owner = undefined, |
| | 214 | }); |
| | 215 | } |
| | 216 | |
| | 217 | var top_args = std.ArrayList([]const u8).init(arena); |
| | 218 | try addCCArgs(comp, arena, &top_args, .{ .want_O3 = true }); |
| | 219 | try addLibcTopHalfIncludes(comp, arena, &top_args); |
| | 220 | try top_args.append("-D_WASI_EMULATED_SIGNAL"); |
| | 221 | |
| | 222 | for (emulated_signal_top_half_src_files) |file_path| { |
| | 223 | try libc_sources.append(.{ |
| | 224 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ |
| | 225 | "libc", try sanitize(arena, file_path), |
| | 226 | }), |
| | 227 | .extra_flags = top_args.items, |
| | 228 | .owner = undefined, |
| | 229 | }); |
| | 230 | } |
| | 231 | } |
| | 232 | |
| | 233 | try comp.build_crt_file("c", .Lib, .@"wasi libc.a", prog_node, libc_sources.items, .{}); |
| 268 | }, | 234 | }, |
| 269 | } | 235 | } |
| 270 | } | 236 | } |