| ... | @@ -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,65 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre | ... | @@ -157,87 +122,65 @@ 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 | | 141 | |
| 181 | .libwasi_emulated_process_clocks_a => { | 142 | { |
| 182 | var args = std.ArrayList([]const u8).init(arena); | 143 | // Compile libwasi-emulated-process-clocks. |
| 183 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | 144 | var args = std.ArrayList([]const u8).init(arena); |
| 184 | try addLibcBottomHalfIncludes(comp, arena, &args); | 145 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| | 146 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 185 | | 147 | |
| 186 | var emu_clocks_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | 148 | for (emulated_process_clocks_src_files) |file_path| { |
| 187 | for (emulated_process_clocks_src_files) |file_path| { | 149 | try libc_sources.append(.{ |
| 188 | try emu_clocks_sources.append(.{ | 150 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ |
| 189 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | 151 | "libc", try sanitize(arena, file_path), |
| 190 | "libc", try sanitize(arena, file_path), | 152 | }), |
| 191 | }), | 153 | .extra_flags = args.items, |
| 192 | .extra_flags = args.items, | 154 | .owner = undefined, |
| 193 | .owner = undefined, | 155 | }); |
| 194 | }); | 156 | } |
| 195 | } | 157 | } |
| 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 | | 158 | |
| 203 | var emu_getpid_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | 159 | { |
| 204 | for (emulated_getpid_src_files) |file_path| { | 160 | // Compile libwasi-emulated-getpid. |
| 205 | try emu_getpid_sources.append(.{ | 161 | var args = std.ArrayList([]const u8).init(arena); |
| 206 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | 162 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| 207 | "libc", try sanitize(arena, file_path), | 163 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 208 | }), | | |
| 209 | .extra_flags = args.items, | | |
| 210 | .owner = undefined, | | |
| 211 | }); | | |
| 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 | | 164 | |
| 220 | var emu_mman_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | 165 | for (emulated_getpid_src_files) |file_path| { |
| 221 | for (emulated_mman_src_files) |file_path| { | 166 | try libc_sources.append(.{ |
| 222 | try emu_mman_sources.append(.{ | 167 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ |
| 223 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | 168 | "libc", try sanitize(arena, file_path), |
| 224 | "libc", try sanitize(arena, file_path), | 169 | }), |
| 225 | }), | 170 | .extra_flags = args.items, |
| 226 | .extra_flags = args.items, | 171 | .owner = undefined, |
| 227 | .owner = undefined, | 172 | }); |
| 228 | }); | 173 | } |
| 229 | } | 174 | } |
| 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 | | 175 | |
| 235 | { | 176 | { |
| | 177 | // Compile libwasi-emulated-mman. |
| 236 | var args = std.ArrayList([]const u8).init(arena); | 178 | var args = std.ArrayList([]const u8).init(arena); |
| 237 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | 179 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); |
| | 180 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 238 | | 181 | |
| 239 | for (emulated_signal_bottom_half_src_files) |file_path| { | 182 | for (emulated_mman_src_files) |file_path| { |
| 240 | try emu_signal_sources.append(.{ | 183 | try libc_sources.append(.{ |
| 241 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | 184 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ |
| 242 | "libc", try sanitize(arena, file_path), | 185 | "libc", try sanitize(arena, file_path), |
| 243 | }), | 186 | }), |
| ... | @@ -248,23 +191,37 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre | ... | @@ -248,23 +191,37 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre |
| 248 | } | 191 | } |
| 249 | | 192 | |
| 250 | { | 193 | { |
| 251 | var args = std.ArrayList([]const u8).init(arena); | 194 | // Compile libwasi-emulated-signal. |
| 252 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | 195 | var bottom_args = std.ArrayList([]const u8).init(arena); |
| 253 | try addLibcTopHalfIncludes(comp, arena, &args); | 196 | try addCCArgs(comp, arena, &bottom_args, .{ .want_O3 = true }); |
| 254 | try args.append("-D_WASI_EMULATED_SIGNAL"); | 197 | |
| | 198 | for (emulated_signal_bottom_half_src_files) |file_path| { |
| | 199 | try libc_sources.append(.{ |
| | 200 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ |
| | 201 | "libc", try sanitize(arena, file_path), |
| | 202 | }), |
| | 203 | .extra_flags = bottom_args.items, |
| | 204 | .owner = undefined, |
| | 205 | }); |
| | 206 | } |
| | 207 | |
| | 208 | var top_args = std.ArrayList([]const u8).init(arena); |
| | 209 | try addCCArgs(comp, arena, &top_args, .{ .want_O3 = true }); |
| | 210 | try addLibcTopHalfIncludes(comp, arena, &top_args); |
| | 211 | try top_args.append("-D_WASI_EMULATED_SIGNAL"); |
| 255 | | 212 | |
| 256 | for (emulated_signal_top_half_src_files) |file_path| { | 213 | for (emulated_signal_top_half_src_files) |file_path| { |
| 257 | try emu_signal_sources.append(.{ | 214 | try libc_sources.append(.{ |
| 258 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | 215 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ |
| 259 | "libc", try sanitize(arena, file_path), | 216 | "libc", try sanitize(arena, file_path), |
| 260 | }), | 217 | }), |
| 261 | .extra_flags = args.items, | 218 | .extra_flags = top_args.items, |
| 262 | .owner = undefined, | 219 | .owner = undefined, |
| 263 | }); | 220 | }); |
| 264 | } | 221 | } |
| 265 | } | 222 | } |
| 266 | | 223 | |
| 267 | try comp.build_crt_file("wasi-emulated-signal", .Lib, .@"libwasi-emulated-signal.a", prog_node, emu_signal_sources.items, .{}); | 224 | try comp.build_crt_file("c", .Lib, .@"wasi libc.a", prog_node, libc_sources.items, .{}); |
| 268 | }, | 225 | }, |
| 269 | } | 226 | } |
| 270 | } | 227 | } |