╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ dev.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
67 pub inline fn supports(comptime dev_env: Env, comptime feature: Feature) bool { 68 return switch (dev_env) { 69 .full => true, 70 .bootstrap => switch (feature) { 71 .build_exe_command, 72 .build_obj_command, 73 .ast_gen, 74 .sema, 75 .c_backend, 76 .c_linker, 77 => true, 78 else => false, 79 }, 80 .core => switch (feature) { 81 .build_exe_command, 82 .build_lib_command, 83 .build_obj_command, 84 .test_command, 85 .run_command, 86 .ar_command, 87 .clang_command, 88 .stdio_listen, 89 .build_import_lib, 90 .make_executable, 91 .make_writable, 92 .incremental, 93 .ast_gen, 94 .sema, 95 .legalize, 96 .c_compiler, 97 .llvm_backend, 98 .c_backend, 99 .wasm_backend, 100 .arm_backend, 101 .x86_64_backend, 102 .aarch64_backend, 103 .x86_backend, 104 .powerpc_backend, 105 .riscv64_backend, 106 .sparc64_backend, 107 .spirv_backend, 108 .loongarch_backend, 109 .spork8_backend, 110 .lld_linker, 111 .coff_linker, 112 .coff2_linker, 113 .elf_linker, 114 .elf2_linker, 115 .macho_linker, 116 .c_linker, 117 .wasm_linker, 118 .spirv_linker, 119 .plan9_linker, 120 .spork8_linker, 121 .jit_command, 122 => true, 123 .cc_command, 124 .translate_c_command, 125 .fmt_command, 126 .init_command, 127 .targets_command, 128 .version_command, 129 .env_command, 130 .zen_command, 131 .help_command, 132 .ast_check_command, 133 .detect_cpu_command, 134 .changelist_command, 135 .dump_zir_command, 136 .llvm_ints_command, 137 .docs_emit, 138 // Avoid dragging networking into zig2.c because it adds dependencies on some 139 // linker symbols that are annoying to satisfy while bootstrapping. 140 .network_listen, 141 .win32_resource, 142 => false, 143 }, 144 .c_source => switch (feature) { 145 .clang_command, 146 .cc_command, 147 .translate_c_command, 148 .c_compiler, 149 => true, 150 else => false, 151 }, 152 .ast_gen => switch (feature) { 153 .ast_check_command, 154 .changelist_command, 155 .dump_zir_command, 156 .make_executable, 157 .make_writable, 158 .incremental, 159 .ast_gen, 160 => true, 161 else => false, 162 }, 163 .sema => switch (feature) { 164 .build_exe_command, 165 .build_lib_command, 166 .build_obj_command, 167 .test_command, 168 .run_command, 169 .sema, 170 => true, 171 else => Env.ast_gen.supports(feature), 172 }, 173 .@"aarch64-linux" => switch (feature) { 174 .stdio_listen, 175 .incremental, 176 .aarch64_backend, 177 .elf_linker, 178 .elf2_linker, 179 => true, 180 else => Env.sema.supports(feature), 181 }, 182 .cbe => switch (feature) { 183 .legalize, 184 .c_backend, 185 .c_linker, 186 => true, 187 else => Env.sema.supports(feature), 188 }, 189 .@"powerpc-linux" => switch (feature) { 190 .stdio_listen, 191 .incremental, 192 .x86_64_backend, 193 .elf_linker, 194 => true, 195 else => Env.sema.supports(feature), 196 }, 197 .@"riscv64-linux" => switch (feature) { 198 .riscv64_backend, 199 .elf_linker, 200 => true, 201 else => Env.sema.supports(feature), 202 }, 203 .spirv => switch (feature) { 204 .spirv_backend, 205 .spirv_linker, 206 .legalize, 207 => true, 208 else => Env.sema.supports(feature), 209 }, 210 .wasm => switch (feature) { 211 .incremental, 212 .legalize, 213 .stdio_listen, 214 .wasm_backend, 215 .wasm_linker, 216 => true, 217 else => Env.sema.supports(feature), 218 }, 219 .@"x86_64-linux" => switch (feature) { 220 .stdio_listen, 221 .incremental, 222 .legalize, 223 .x86_64_backend, 224 .elf_linker, 225 .elf2_linker, 226 => true, 227 else => Env.sema.supports(feature), 228 }, 229 .@"x86_64-windows" => switch (feature) { 230 .stdio_listen, 231 .incremental, 232 .legalize, 233 .x86_64_backend, 234 .coff2_linker, 235 => true, 236 else => Env.sema.supports(feature), 237 }, 238 .@"loongarch-linux" => switch (feature) { 239 .stdio_listen, 240 .incremental, 241 .legalize, 242 .loongarch_backend, 243 .elf2_linker, 244 => true, 245 else => Env.sema.supports(feature), 246 }, 247 .spork8 => switch (feature) { 248 .stdio_listen, 249 .incremental, 250 .legalize, 251 .spork8_backend, 252 .spork8_linker, 253 => true, 254 else => Env.sema.supports(feature), 255 }, 256 }; 257 } 258 259 pub inline fn supportsAny(comptime dev_env: Env, comptime features: []const Feature) bool { 260 inline for (features) |feature| if (dev_env.supports(feature)) return true; 261 return false; 262 } 263 264 pub inline fn supportsAll(comptime dev_env: Env, comptime features: []const Feature) bool { 265 inline for (features) |feature| if (!dev_env.supports(feature)) return false; 266 return true; 267 } 268 }; 269 270 pub const Feature = enum { 271 build_exe_command, 272 build_lib_command, 273 build_obj_command, 274 test_command, 275 run_command, 276 ar_command, 277 clang_command, 278 cc_command, 279 translate_c_command, 280 fmt_command, 281 jit_command, 282 init_command, 283 targets_command, 284 version_command, 285 env_command, 286 zen_command, 287 help_command, 288 ast_check_command, 289 detect_cpu_command, 290 changelist_command, 291 dump_zir_command, 292 llvm_ints_command, 293 294 docs_emit, 295 stdio_listen, 296 network_listen, 297 build_import_lib, 298 win32_resource, 299 make_executable, 300 make_writable, 301 incremental, 302 ast_gen, 303 sema, 304 legalize, 305 306 c_compiler, 307 308 llvm_backend, 309 c_backend, 310 wasm_backend, 311 arm_backend, 312 x86_64_backend, 313 aarch64_backend, 314 x86_backend, 315 powerpc_backend, 316 riscv64_backend, 317 sparc64_backend, 318 spirv_backend, 319 loongarch_backend, 320 spork8_backend, 321 322 lld_linker, 323 coff_linker, 324 coff2_linker, 325 elf_linker, 326 elf2_linker, 327 macho_linker, 328 c_linker, 329 wasm_linker, 330 spirv_linker, 331 plan9_linker, 332 spork8_linker, 333 }; 334 335 /// Makes the code following the call to this function unreachable if `feature` is disabled. 336 pub fn check(comptime feature: Feature) if (env.supports(feature)) void else noreturn { 337 if (env.supports(feature)) return; 338 @panic("development environment " ++ @tagName(env) ++ " does not support feature " ++ @tagName(feature)); 339 } 340 341 /// Makes the code following the call to this function unreachable if all of `features` are disabled. 342 pub fn checkAny(comptime features: []const Feature) if (env.supportsAny(features)) void else noreturn { 343 if (env.supportsAny(features)) return; 344 comptime var feature_tags: []const u8 = ""; 345 inline for (features[0 .. features.len - 1]) |feature| feature_tags = feature_tags ++ @tagName(feature) ++ ", "; 346 feature_tags = feature_tags ++ "or " ++ @tagName(features[features.len - 1]); 347 @panic("development environment " ++ @tagName(env) ++ " does not support feature " ++ feature_tags); 348 } 349 350 /// Makes the code following the call to this function unreachable if any of `features` are disabled. 351 pub fn checkAll(comptime features: []const Feature) if (env.supportsAll(features)) void else noreturn { 352 if (env.supportsAll(features)) return; 353 inline for (features) |feature| if (!env.supports(feature)) 354 @panic("development environment " ++ @tagName(env) ++ " does not support feature " ++ @tagName(feature)); 355 } 356 357 const build_options = @import("build_options"); 358 359 pub const env: Env = if (@hasDecl(build_options, "dev")) 360 @field(Env, @tagName(build_options.dev)) 361 else if (@hasDecl(build_options, "only_c") and build_options.only_c) 362 .bootstrap 363 else if (@hasDecl(build_options, "only_core_functionality") and build_options.only_core_functionality) 364 .core 365 else 366 .full; 367