| ... | @@ -21,35 +21,7 @@ pub fn buildWasiLibcSysroot(comp: *Compilation) !void { | ... | @@ -21,35 +21,7 @@ pub fn buildWasiLibcSysroot(comp: *Compilation) !void { |
| 21 | // Compile crt sources. | 21 | // Compile crt sources. |
| 22 | var args = std.ArrayList([]const u8).init(arena); | 22 | var args = std.ArrayList([]const u8).init(arena); |
| 23 | try addCCArgs(comp, arena, &args, false); | 23 | try addCCArgs(comp, arena, &args, false); |
| 24 | try args.appendSlice(&[_][]const u8{ | 24 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 25 | "-I", | | |
| 26 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | | |
| 27 | "libc", | | |
| 28 | "wasi", | | |
| 29 | "libc-bottom-half", | | |
| 30 | "headers", | | |
| 31 | "private", | | |
| 32 | }), | | |
| 33 | | | |
| 34 | "-I", | | |
| 35 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | | |
| 36 | "libc", | | |
| 37 | "wasi", | | |
| 38 | "libc-bottom-half", | | |
| 39 | "cloudlibc", | | |
| 40 | "src", | | |
| 41 | "include", | | |
| 42 | }), | | |
| 43 | | | |
| 44 | "-I", | | |
| 45 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | | |
| 46 | "libc", | | |
| 47 | "wasi", | | |
| 48 | "libc-bottom-half", | | |
| 49 | "cloudlibc", | | |
| 50 | "src", | | |
| 51 | }), | | |
| 52 | }); | | |
| 53 | | 25 | |
| 54 | var comp_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | 26 | var comp_sources = std.ArrayList(Compilation.CSourceFile).init(arena); |
| 55 | for (crt_src_files) |file_path| { | 27 | for (crt_src_files) |file_path| { |
| ... | @@ -95,37 +67,43 @@ pub fn buildWasiLibcSysroot(comp: *Compilation) !void { | ... | @@ -95,37 +67,43 @@ pub fn buildWasiLibcSysroot(comp: *Compilation) !void { |
| 95 | // Compile libc-bottom-half. | 67 | // Compile libc-bottom-half. |
| 96 | var args = std.ArrayList([]const u8).init(arena); | 68 | var args = std.ArrayList([]const u8).init(arena); |
| 97 | try addCCArgs(comp, arena, &args, true); | 69 | try addCCArgs(comp, arena, &args, true); |
| 98 | try args.appendSlice(&[_][]const u8{ | 70 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 99 | "-I", | | |
| 100 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | | |
| 101 | "libc", | | |
| 102 | "wasi", | | |
| 103 | "libc-bottom-half", | | |
| 104 | "headers", | | |
| 105 | "private", | | |
| 106 | }), | | |
| 107 | | 71 | |
| 108 | "-I", | 72 | for (libc_bottom_half_src_files) |file_path| { |
| 109 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 73 | try comp_sources.append(.{ |
| 110 | "libc", | 74 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 111 | "wasi", | 75 | "libc", try sanitize(arena, file_path), |
| 112 | "libc-bottom-half", | 76 | }), |
| 113 | "cloudlibc", | 77 | .extra_flags = args.items, |
| 114 | "src", | 78 | }); |
| 115 | }), | 79 | } |
| | 80 | } |
| 116 | | 81 | |
| 117 | "-I", | 82 | { |
| 118 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 83 | // Compile emulated sources depending only on libc-bottom-half. |
| 119 | "libc", | 84 | var args = std.ArrayList([]const u8).init(arena); |
| 120 | "wasi", | 85 | try addCCArgs(comp, arena, &args, true); |
| 121 | "libc-bottom-half", | 86 | try addLibcBottomHalfIncludes(comp, arena, &args); |
| 122 | "cloudlibc", | | |
| 123 | "src", | | |
| 124 | "include", | | |
| 125 | }), | | |
| 126 | }); | | |
| 127 | | 87 | |
| 128 | for (libc_bottom_half_src_files) |file_path| { | 88 | for (emulated_process_clocks_src_files) |file_path| { |
| | 89 | try comp_sources.append(.{ |
| | 90 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| | 91 | "libc", try sanitize(arena, file_path), |
| | 92 | }), |
| | 93 | .extra_flags = args.items, |
| | 94 | }); |
| | 95 | } |
| | 96 | |
| | 97 | for (emulated_getpid_src_files) |file_path| { |
| | 98 | try comp_sources.append(.{ |
| | 99 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| | 100 | "libc", try sanitize(arena, file_path), |
| | 101 | }), |
| | 102 | .extra_flags = args.items, |
| | 103 | }); |
| | 104 | } |
| | 105 | |
| | 106 | for (emulated_mman_src_files) |file_path| { |
| 129 | try comp_sources.append(.{ | 107 | try comp_sources.append(.{ |
| 130 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 108 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 131 | "libc", try sanitize(arena, file_path), | 109 | "libc", try sanitize(arena, file_path), |
| ... | @@ -136,59 +114,42 @@ pub fn buildWasiLibcSysroot(comp: *Compilation) !void { | ... | @@ -136,59 +114,42 @@ pub fn buildWasiLibcSysroot(comp: *Compilation) !void { |
| 136 | } | 114 | } |
| 137 | | 115 | |
| 138 | { | 116 | { |
| 139 | // Compile libc-top-half. | 117 | // Compile emulated signals (bottom-half). |
| 140 | var args = std.ArrayList([]const u8).init(arena); | 118 | var args = std.ArrayList([]const u8).init(arena); |
| 141 | try addCCArgs(comp, arena, &args, true); | 119 | try addCCArgs(comp, arena, &args, true); |
| 142 | try args.appendSlice(&[_][]const u8{ | | |
| 143 | "-I", | | |
| 144 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | | |
| 145 | "libc", | | |
| 146 | "wasi", | | |
| 147 | "libc-top-half", | | |
| 148 | "musl", | | |
| 149 | "src", | | |
| 150 | "include", | | |
| 151 | }), | | |
| 152 | | 120 | |
| 153 | "-I", | 121 | for (emulated_signal_bottom_half_src_files) |file_path| { |
| 154 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 122 | try comp_sources.append(.{ |
| 155 | "libc", | 123 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 156 | "wasi", | 124 | "libc", try sanitize(arena, file_path), |
| 157 | "libc-top-half", | 125 | }), |
| 158 | "musl", | 126 | .extra_flags = args.items, |
| 159 | "src", | 127 | }); |
| 160 | "internal", | 128 | } |
| 161 | }), | 129 | } |
| 162 | | 130 | |
| 163 | "-I", | 131 | { |
| 164 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 132 | // Compile emulated signals (top-half). |
| 165 | "libc", | 133 | var args = std.ArrayList([]const u8).init(arena); |
| 166 | "wasi", | 134 | try addCCArgs(comp, arena, &args, true); |
| 167 | "libc-top-half", | 135 | try addLibcTopHalfIncludes(comp, arena, &args); |
| 168 | "musl", | 136 | try args.append("-D_WASI_EMULATED_SIGNAL"); |
| 169 | "arch", | | |
| 170 | "wasm32", | | |
| 171 | }), | | |
| 172 | | 137 | |
| 173 | "-I", | 138 | for (emulated_signal_top_half_src_files) |file_path| { |
| 174 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 139 | try comp_sources.append(.{ |
| 175 | "libc", | 140 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 176 | "wasi", | 141 | "libc", try sanitize(arena, file_path), |
| 177 | "libc-top-half", | 142 | }), |
| 178 | "musl", | 143 | .extra_flags = args.items, |
| 179 | "arch", | 144 | }); |
| 180 | "generic", | 145 | } |
| 181 | }), | 146 | } |
| 182 | | 147 | |
| 183 | "-I", | 148 | { |
| 184 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | 149 | // Compile libc-top-half. |
| 185 | "libc", | 150 | var args = std.ArrayList([]const u8).init(arena); |
| 186 | "wasi", | 151 | try addCCArgs(comp, arena, &args, true); |
| 187 | "libc-top-half", | 152 | try addLibcTopHalfIncludes(comp, arena, &args); |
| 188 | "headers", | | |
| 189 | "private", | | |
| 190 | }), | | |
| 191 | }); | | |
| 192 | | 153 | |
| 193 | for (libc_top_half_src_files) |file_path| { | 154 | for (libc_top_half_src_files) |file_path| { |
| 194 | try comp_sources.append(.{ | 155 | try comp_sources.append(.{ |
| ... | @@ -251,6 +212,99 @@ fn addCCArgs( | ... | @@ -251,6 +212,99 @@ fn addCCArgs( |
| 251 | }); | 212 | }); |
| 252 | } | 213 | } |
| 253 | | 214 | |
| | 215 | fn addLibcBottomHalfIncludes( |
| | 216 | comp: *Compilation, |
| | 217 | arena: *Allocator, |
| | 218 | args: *std.ArrayList([]const u8), |
| | 219 | ) error{OutOfMemory}!void { |
| | 220 | try args.appendSlice(&[_][]const u8{ |
| | 221 | "-I", |
| | 222 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| | 223 | "libc", |
| | 224 | "wasi", |
| | 225 | "libc-bottom-half", |
| | 226 | "headers", |
| | 227 | "private", |
| | 228 | }), |
| | 229 | |
| | 230 | "-I", |
| | 231 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| | 232 | "libc", |
| | 233 | "wasi", |
| | 234 | "libc-bottom-half", |
| | 235 | "cloudlibc", |
| | 236 | "src", |
| | 237 | "include", |
| | 238 | }), |
| | 239 | |
| | 240 | "-I", |
| | 241 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| | 242 | "libc", |
| | 243 | "wasi", |
| | 244 | "libc-bottom-half", |
| | 245 | "cloudlibc", |
| | 246 | "src", |
| | 247 | }), |
| | 248 | }); |
| | 249 | } |
| | 250 | |
| | 251 | fn addLibcTopHalfIncludes( |
| | 252 | comp: *Compilation, |
| | 253 | arena: *Allocator, |
| | 254 | args: *std.ArrayList([]const u8), |
| | 255 | ) error{OutOfMemory}!void { |
| | 256 | try args.appendSlice(&[_][]const u8{ |
| | 257 | "-I", |
| | 258 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| | 259 | "libc", |
| | 260 | "wasi", |
| | 261 | "libc-top-half", |
| | 262 | "musl", |
| | 263 | "src", |
| | 264 | "include", |
| | 265 | }), |
| | 266 | |
| | 267 | "-I", |
| | 268 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| | 269 | "libc", |
| | 270 | "wasi", |
| | 271 | "libc-top-half", |
| | 272 | "musl", |
| | 273 | "src", |
| | 274 | "internal", |
| | 275 | }), |
| | 276 | |
| | 277 | "-I", |
| | 278 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| | 279 | "libc", |
| | 280 | "wasi", |
| | 281 | "libc-top-half", |
| | 282 | "musl", |
| | 283 | "arch", |
| | 284 | "wasm32", |
| | 285 | }), |
| | 286 | |
| | 287 | "-I", |
| | 288 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| | 289 | "libc", |
| | 290 | "wasi", |
| | 291 | "libc-top-half", |
| | 292 | "musl", |
| | 293 | "arch", |
| | 294 | "generic", |
| | 295 | }), |
| | 296 | |
| | 297 | "-I", |
| | 298 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| | 299 | "libc", |
| | 300 | "wasi", |
| | 301 | "libc-top-half", |
| | 302 | "headers", |
| | 303 | "private", |
| | 304 | }), |
| | 305 | }); |
| | 306 | } |
| | 307 | |
| 254 | const dlmalloc_src_files = [_][]const u8{ | 308 | const dlmalloc_src_files = [_][]const u8{ |
| 255 | "wasi/dlmalloc/src/dlmalloc.c", | 309 | "wasi/dlmalloc/src/dlmalloc.c", |
| 256 | }; | 310 | }; |
| ... | @@ -1025,6 +1079,11 @@ const emulated_mman_src_files = &[_][]const u8{ | ... | @@ -1025,6 +1079,11 @@ const emulated_mman_src_files = &[_][]const u8{ |
| 1025 | "wasi/libc-bottom-half/mman/mman.c", | 1079 | "wasi/libc-bottom-half/mman/mman.c", |
| 1026 | }; | 1080 | }; |
| 1027 | | 1081 | |
| 1028 | const emulated_signal_src_files = &[_][]const u8{ | 1082 | const emulated_signal_bottom_half_src_files = &[_][]const u8{ |
| 1029 | "wasi/libc-bottom-half/signal/signal.c", | 1083 | "wasi/libc-bottom-half/signal/signal.c", |
| 1030 | }; | 1084 | }; |
| | 1085 | |
| | 1086 | const emulated_signal_top_half_src_files = &[_][]const u8{ |
| | 1087 | "wasi/libc-top-half/musl/src/signal/psignal.c", |
| | 1088 | "wasi/libc-top-half/musl/src/string/strsignal.c", |
| | 1089 | }; |