authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-07-19 01:04:59-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-19 22:35:33-07:00
log4f742c4cfc3c3134a0d6ebfdfc354286ae97b2c1
treec20b44dbe98cb8cb7484b19aca727ad2957e42a2
parentb7e48c6bcd99457f84f0043a3f4590a6ac1f4933

dev: introduce dev environments that enable compiler feature sets


16 files changed, 518 insertions(+), 235 deletions(-)

CMakeLists.txt+1
......@@ -578,6 +578,7 @@ set(ZIG_STAGE2_SOURCES
578578 src/codegen/spirv/Section.zig
579579 src/codegen/spirv/spec.zig
580580 src/crash_report.zig
581 src/dev.zig
581582 src/glibc.zig
582583 src/introspect.zig
583584 src/libcxx.zig
bootstrap.c+1-2
......@@ -140,8 +140,7 @@ int main(int argc, char **argv) {
140140 "pub const value_tracing = false;\n"
141141 "pub const skip_non_native = false;\n"
142142 "pub const force_gpa = false;\n"
143 "pub const only_c = false;\n"
144 "pub const only_core_functionality = true;\n"
143 "pub const dev = .core;\n"
145144 , zig_version);
146145 if (written < 100)
147146 panic("unable to write to config.zig file");
build.zig+4-6
......@@ -8,6 +8,7 @@ const io = std.io;
88const fs = std.fs;
99const InstallDirectoryOptions = std.Build.InstallDirectoryOptions;
1010const assert = std.debug.assert;
11const DevEnv = @import("src/dev.zig").Env;
1112
1213const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 14, .patch = 0 };
1314const stack_size = 32 * 1024 * 1024;
......@@ -232,8 +233,7 @@ pub fn build(b: *std.Build) !void {
232233 exe_options.addOption(bool, "llvm_has_arc", llvm_has_arc);
233234 exe_options.addOption(bool, "llvm_has_xtensa", llvm_has_xtensa);
234235 exe_options.addOption(bool, "force_gpa", force_gpa);
235 exe_options.addOption(bool, "only_c", only_c);
236 exe_options.addOption(bool, "only_core_functionality", only_c);
236 exe_options.addOption(DevEnv, "dev", b.option(DevEnv, "dev", "Build a compiler with a reduced feature set for development of specific features") orelse if (only_c) .bootstrap else .full);
237237
238238 if (link_libc) {
239239 exe.linkLibC();
......@@ -393,8 +393,6 @@ pub fn build(b: *std.Build) !void {
393393 test_cases_options.addOption(bool, "llvm_has_arc", llvm_has_arc);
394394 test_cases_options.addOption(bool, "llvm_has_xtensa", llvm_has_xtensa);
395395 test_cases_options.addOption(bool, "force_gpa", force_gpa);
396 test_cases_options.addOption(bool, "only_c", only_c);
397 test_cases_options.addOption(bool, "only_core_functionality", true);
398396 test_cases_options.addOption(bool, "enable_qemu", b.enable_qemu);
399397 test_cases_options.addOption(bool, "enable_wine", b.enable_wine);
400398 test_cases_options.addOption(bool, "enable_wasmtime", b.enable_wasmtime);
......@@ -406,6 +404,7 @@ pub fn build(b: *std.Build) !void {
406404 test_cases_options.addOption([:0]const u8, "version", version);
407405 test_cases_options.addOption(std.SemanticVersion, "semver", semver);
408406 test_cases_options.addOption([]const []const u8, "test_filters", test_filters);
407 test_cases_options.addOption(DevEnv, "dev", if (only_c) .bootstrap else .core);
409408
410409 var chosen_opt_modes_buf: [4]builtin.OptimizeMode = undefined;
411410 var chosen_mode_index: usize = 0;
......@@ -575,7 +574,6 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
575574 exe_options.addOption(u32, "mem_leak_frames", 0);
576575 exe_options.addOption(bool, "have_llvm", false);
577576 exe_options.addOption(bool, "force_gpa", false);
578 exe_options.addOption(bool, "only_c", true);
579577 exe_options.addOption([:0]const u8, "version", version);
580578 exe_options.addOption(std.SemanticVersion, "semver", semver);
581579 exe_options.addOption(bool, "enable_debug_extensions", false);
......@@ -585,7 +583,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
585583 exe_options.addOption(bool, "enable_tracy_callstack", false);
586584 exe_options.addOption(bool, "enable_tracy_allocation", false);
587585 exe_options.addOption(bool, "value_tracing", false);
588 exe_options.addOption(bool, "only_core_functionality", true);
586 exe_options.addOption(DevEnv, "dev", .bootstrap);
589587
590588 const run_opt = b.addSystemCommand(&.{
591589 "wasm-opt",
src/Compilation.zig+73-69
......@@ -38,6 +38,7 @@ const Zir = std.zig.Zir;
3838const Air = @import("Air.zig");
3939const Builtin = @import("Builtin.zig");
4040const LlvmObject = @import("codegen/llvm.zig").Object;
41const dev = @import("dev.zig");
4142
4243pub const Config = @import("Compilation/Config.zig");
4344
......@@ -94,8 +95,15 @@ native_system_include_paths: []const []const u8,
9495force_undefined_symbols: std.StringArrayHashMapUnmanaged(void),
9596
9697c_object_table: std.AutoArrayHashMapUnmanaged(*CObject, void) = .{},
97win32_resource_table: if (build_options.only_core_functionality) void else std.AutoArrayHashMapUnmanaged(*Win32Resource, void) =
98 if (build_options.only_core_functionality) {} else .{},
98win32_resource_table: if (dev.env.supports(.win32_resource)) std.AutoArrayHashMapUnmanaged(*Win32Resource, void) else struct {
99 pub fn keys(_: @This()) [0]void {
100 return .{};
101 }
102 pub fn count(_: @This()) u0 {
103 return 0;
104 }
105 pub fn deinit(_: @This(), _: Allocator) void {}
106} = .{},
99107
100108link_error_flags: link.File.ErrorFlags = .{},
101109link_errors: std.ArrayListUnmanaged(link.File.ErrorMsg) = .{},
......@@ -125,7 +133,13 @@ c_object_work_queue: std.fifo.LinearFifo(*CObject, .Dynamic),
125133
126134/// These jobs are to invoke the RC compiler to create a compiled resource file (.res), which
127135/// gets linked with the Compilation.
128win32_resource_work_queue: if (build_options.only_core_functionality) void else std.fifo.LinearFifo(*Win32Resource, .Dynamic),
136win32_resource_work_queue: if (dev.env.supports(.win32_resource)) std.fifo.LinearFifo(*Win32Resource, .Dynamic) else struct {
137 pub fn ensureUnusedCapacity(_: @This(), _: u0) error{}!void {}
138 pub fn readItem(_: @This()) ?noreturn {
139 return null;
140 }
141 pub fn deinit(_: @This()) void {}
142},
129143
130144/// These jobs are to tokenize, parse, and astgen files, which may be outdated
131145/// since the last compilation, as well as scan for `@import` and queue up
......@@ -142,8 +156,12 @@ failed_c_objects: std.AutoArrayHashMapUnmanaged(*CObject, *CObject.Diag.Bundle)
142156
143157/// The ErrorBundle memory is owned by the `Win32Resource`, using Compilation's general purpose allocator.
144158/// This data is accessed by multiple threads and is protected by `mutex`.
145failed_win32_resources: if (build_options.only_core_functionality) void else std.AutoArrayHashMapUnmanaged(*Win32Resource, ErrorBundle) =
146 if (build_options.only_core_functionality) {} else .{},
159failed_win32_resources: if (dev.env.supports(.win32_resource)) std.AutoArrayHashMapUnmanaged(*Win32Resource, ErrorBundle) else struct {
160 pub fn values(_: @This()) [0]void {
161 return .{};
162 }
163 pub fn deinit(_: @This(), _: Allocator) void {}
164} = .{},
147165
148166/// Miscellaneous things that can fail.
149167misc_failures: std.AutoArrayHashMapUnmanaged(MiscTask, MiscError) = .{},
......@@ -1484,7 +1502,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
14841502 .done = false,
14851503 },
14861504 .c_object_work_queue = std.fifo.LinearFifo(*CObject, .Dynamic).init(gpa),
1487 .win32_resource_work_queue = if (build_options.only_core_functionality) {} else std.fifo.LinearFifo(*Win32Resource, .Dynamic).init(gpa),
1505 .win32_resource_work_queue = if (dev.env.supports(.win32_resource)) std.fifo.LinearFifo(*Win32Resource, .Dynamic).init(gpa) else .{},
14881506 .astgen_work_queue = std.fifo.LinearFifo(Zcu.File.Index, .Dynamic).init(gpa),
14891507 .embed_file_work_queue = std.fifo.LinearFifo(*Zcu.EmbedFile, .Dynamic).init(gpa),
14901508 .c_source_files = options.c_source_files,
......@@ -1711,7 +1729,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
17111729 comp.emit_llvm_ir != null or
17121730 comp.emit_llvm_bc != null))
17131731 {
1714 if (build_options.only_c) unreachable;
1732 dev.check(.llvm_backend);
17151733 if (opt_zcu) |zcu| zcu.llvm_object = try LlvmObject.create(arena, comp);
17161734 }
17171735
......@@ -1738,8 +1756,11 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
17381756 }
17391757
17401758 // Add a `Win32Resource` for each `rc_source_files` and one for `manifest_file`.
1741 if (!build_options.only_core_functionality) {
1742 try comp.win32_resource_table.ensureTotalCapacity(gpa, options.rc_source_files.len + @intFromBool(options.manifest_file != null));
1759 const win32_resource_count =
1760 options.rc_source_files.len + @intFromBool(options.manifest_file != null);
1761 if (win32_resource_count > 0) {
1762 dev.check(.win32_resource);
1763 try comp.win32_resource_table.ensureTotalCapacity(gpa, win32_resource_count);
17431764 for (options.rc_source_files) |rc_source_file| {
17441765 const win32_resource = try gpa.create(Win32Resource);
17451766 errdefer gpa.destroy(win32_resource);
......@@ -1905,9 +1926,7 @@ pub fn destroy(comp: *Compilation) void {
19051926 for (comp.work_queues) |work_queue| work_queue.deinit();
19061927 if (!InternPool.single_threaded) comp.codegen_work.queue.deinit();
19071928 comp.c_object_work_queue.deinit();
1908 if (!build_options.only_core_functionality) {
1909 comp.win32_resource_work_queue.deinit();
1910 }
1929 comp.win32_resource_work_queue.deinit();
19111930 comp.astgen_work_queue.deinit();
19121931 comp.embed_file_work_queue.deinit();
19131932
......@@ -1956,17 +1975,15 @@ pub fn destroy(comp: *Compilation) void {
19561975 }
19571976 comp.failed_c_objects.deinit(gpa);
19581977
1959 if (!build_options.only_core_functionality) {
1960 for (comp.win32_resource_table.keys()) |key| {
1961 key.destroy(gpa);
1962 }
1963 comp.win32_resource_table.deinit(gpa);
1978 for (comp.win32_resource_table.keys()) |key| {
1979 key.destroy(gpa);
1980 }
1981 comp.win32_resource_table.deinit(gpa);
19641982
1965 for (comp.failed_win32_resources.values()) |*value| {
1966 value.deinit(gpa);
1967 }
1968 comp.failed_win32_resources.deinit(gpa);
1983 for (comp.failed_win32_resources.values()) |*value| {
1984 value.deinit(gpa);
19691985 }
1986 comp.failed_win32_resources.deinit(gpa);
19701987
19711988 for (comp.link_errors.items) |*item| item.deinit(gpa);
19721989 comp.link_errors.deinit(gpa);
......@@ -2153,17 +2170,15 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
21532170
21542171 // For compiling Win32 resources, we rely on the cache hash system to avoid duplicating work.
21552172 // Add a Job for each Win32 resource file.
2156 if (!build_options.only_core_functionality) {
2157 try comp.win32_resource_work_queue.ensureUnusedCapacity(comp.win32_resource_table.count());
2158 for (comp.win32_resource_table.keys()) |key| {
2159 comp.win32_resource_work_queue.writeItemAssumeCapacity(key);
2160 }
2161 if (comp.file_system_inputs) |fsi| {
2162 for (comp.win32_resource_table.keys()) |win32_resource| switch (win32_resource.src) {
2163 .rc => |f| try comp.appendFileSystemInput(fsi, Cache.Path.cwd(), f.src_path),
2164 .manifest => continue,
2165 };
2166 }
2173 try comp.win32_resource_work_queue.ensureUnusedCapacity(comp.win32_resource_table.count());
2174 for (comp.win32_resource_table.keys()) |key| {
2175 comp.win32_resource_work_queue.writeItemAssumeCapacity(key);
2176 }
2177 if (comp.file_system_inputs) |fsi| {
2178 for (comp.win32_resource_table.keys()) |win32_resource| switch (win32_resource.src) {
2179 .rc => |f| try comp.appendFileSystemInput(fsi, Cache.Path.cwd(), f.src_path),
2180 .manifest => continue,
2181 };
21672182 }
21682183
21692184 if (comp.module) |zcu| {
......@@ -2397,7 +2412,6 @@ fn flush(comp: *Compilation, arena: Allocator, tid: Zcu.PerThread.Id, prog_node:
23972412 try link.File.C.flushEmitH(zcu);
23982413
23992414 if (zcu.llvm_object) |llvm_object| {
2400 if (build_options.only_c) unreachable;
24012415 const default_emit = switch (comp.cache_use) {
24022416 .whole => |whole| .{
24032417 .directory = whole.tmp_artifact_directory.?,
......@@ -2541,17 +2555,15 @@ fn addNonIncrementalStuffToCacheManifest(
25412555 man.hash.addListOfBytes(key.src.extra_flags);
25422556 }
25432557
2544 if (!build_options.only_core_functionality) {
2545 for (comp.win32_resource_table.keys()) |key| {
2546 switch (key.src) {
2547 .rc => |rc_src| {
2548 _ = try man.addFile(rc_src.src_path, null);
2549 man.hash.addListOfBytes(rc_src.extra_flags);
2550 },
2551 .manifest => |manifest_path| {
2552 _ = try man.addFile(manifest_path, null);
2553 },
2554 }
2558 for (comp.win32_resource_table.keys()) |key| {
2559 switch (key.src) {
2560 .rc => |rc_src| {
2561 _ = try man.addFile(rc_src.src_path, null);
2562 man.hash.addListOfBytes(rc_src.extra_flags);
2563 },
2564 .manifest => |manifest_path| {
2565 _ = try man.addFile(manifest_path, null);
2566 },
25552567 }
25562568 }
25572569
......@@ -2695,8 +2707,6 @@ pub fn emitLlvmObject(
26952707 llvm_object: *LlvmObject,
26962708 prog_node: std.Progress.Node,
26972709) !void {
2698 if (build_options.only_c) @compileError("unreachable");
2699
27002710 const sub_prog_node = prog_node.start("LLVM Emit Object", 0);
27012711 defer sub_prog_node.end();
27022712
......@@ -2860,6 +2870,7 @@ fn reportMultiModuleErrors(pt: Zcu.PerThread) !void {
28602870/// or whatever is needed so that it can be executed.
28612871/// After this, one must call` makeFileWritable` before calling `update`.
28622872pub fn makeBinFileExecutable(comp: *Compilation) !void {
2873 if (!dev.env.supports(.make_executable)) return;
28632874 const lf = comp.bin_file orelse return;
28642875 return lf.makeExecutable();
28652876}
......@@ -2897,6 +2908,8 @@ const Header = extern struct {
28972908/// saved, such as the target and most CLI flags. A cache hit will only occur
28982909/// when subsequent compiler invocations use the same set of flags.
28992910pub fn saveState(comp: *Compilation) !void {
2911 dev.check(.incremental);
2912
29002913 const lf = comp.bin_file orelse return;
29012914
29022915 const gpa = comp.gpa;
......@@ -3001,10 +3014,8 @@ pub fn totalErrorCount(comp: *Compilation) u32 {
30013014 total += bundle.diags.len;
30023015 }
30033016
3004 if (!build_options.only_core_functionality) {
3005 for (comp.failed_win32_resources.values()) |errs| {
3006 total += errs.errorMessageCount();
3007 }
3017 for (comp.failed_win32_resources.values()) |errs| {
3018 total += errs.errorMessageCount();
30083019 }
30093020
30103021 if (comp.module) |zcu| {
......@@ -3082,10 +3093,8 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
30823093 try diag_bundle.addToErrorBundle(&bundle);
30833094 }
30843095
3085 if (!build_options.only_core_functionality) {
3086 for (comp.failed_win32_resources.values()) |error_bundle| {
3087 try bundle.addBundleAsRoots(error_bundle);
3088 }
3096 for (comp.failed_win32_resources.values()) |error_bundle| {
3097 try bundle.addBundleAsRoots(error_bundle);
30893098 }
30903099
30913100 for (comp.lld_errors.items) |lld_error| {
......@@ -3509,11 +3518,10 @@ fn performAllTheWorkInner(
35093518 comp.work_queue_wait_group.reset();
35103519 defer comp.work_queue_wait_group.wait();
35113520
3512 if (!build_options.only_c and !build_options.only_core_functionality) {
3513 if (comp.docs_emit != null) {
3514 comp.thread_pool.spawnWg(&comp.work_queue_wait_group, workerDocsCopy, .{comp});
3515 comp.work_queue_wait_group.spawnManager(workerDocsWasm, .{ comp, main_progress_node });
3516 }
3521 if (comp.docs_emit != null) {
3522 dev.check(.docs_emit);
3523 comp.thread_pool.spawnWg(&comp.work_queue_wait_group, workerDocsCopy, .{comp});
3524 comp.work_queue_wait_group.spawnManager(workerDocsWasm, .{ comp, main_progress_node });
35173525 }
35183526
35193527 {
......@@ -3585,12 +3593,10 @@ fn performAllTheWorkInner(
35853593 });
35863594 }
35873595
3588 if (!build_options.only_core_functionality) {
3589 while (comp.win32_resource_work_queue.readItem()) |win32_resource| {
3590 comp.thread_pool.spawnWg(&comp.work_queue_wait_group, workerUpdateWin32Resource, .{
3591 comp, win32_resource, main_progress_node,
3592 });
3593 }
3596 while (comp.win32_resource_work_queue.readItem()) |win32_resource| {
3597 comp.thread_pool.spawnWg(&comp.work_queue_wait_group, workerUpdateWin32Resource, .{
3598 comp, win32_resource, main_progress_node,
3599 });
35943600 }
35953601 }
35963602
......@@ -3867,9 +3873,6 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
38673873 };
38683874 },
38693875 .windows_import_lib => |index| {
3870 if (build_options.only_c)
3871 @panic("building import libs not included in core functionality");
3872
38733876 const named_frame = tracy.namedFrame("windows_import_lib");
38743877 defer named_frame.end();
38753878
......@@ -4466,7 +4469,8 @@ pub const CImportResult = struct {
44664469/// This API is currently coupled pretty tightly to stage1's needs; it will need to be reworked
44674470/// a bit when we want to start using it from self-hosted.
44684471pub fn cImport(comp: *Compilation, c_src: []const u8, owner_mod: *Package.Module) !CImportResult {
4469 if (build_options.only_core_functionality) @panic("@cImport is not available in a zig2.c build");
4472 dev.check(.translate_c_command);
4473
44704474 const tracy_trace = trace(@src());
44714475 defer tracy_trace.end();
44724476
src/Zcu.zig+4-6
......@@ -38,6 +38,7 @@ const Alignment = InternPool.Alignment;
3838const AnalUnit = InternPool.AnalUnit;
3939const BuiltinFn = std.zig.BuiltinFn;
4040const LlvmObject = @import("codegen/llvm.zig").Object;
41const dev = @import("dev.zig");
4142
4243comptime {
4344 @setEvalBranchQuota(4000);
......@@ -57,7 +58,7 @@ comp: *Compilation,
5758/// Usually, the LlvmObject is managed by linker code, however, in the case
5859/// that -fno-emit-bin is specified, the linker code never executes, so we
5960/// store the LlvmObject here.
60llvm_object: ?*LlvmObject,
61llvm_object: if (dev.env.supports(.llvm_backend)) ?*LlvmObject else ?noreturn,
6162
6263/// Pointer to externally managed resource.
6364root_mod: *Package.Module,
......@@ -2403,10 +2404,7 @@ pub fn deinit(zcu: *Zcu) void {
24032404 const pt: Zcu.PerThread = .{ .tid = .main, .zcu = zcu };
24042405 const gpa = zcu.gpa;
24052406
2406 if (zcu.llvm_object) |llvm_object| {
2407 if (build_options.only_c) unreachable;
2408 llvm_object.deinit();
2409 }
2407 if (zcu.llvm_object) |llvm_object| llvm_object.deinit();
24102408
24112409 for (zcu.import_table.keys()) |key| {
24122410 gpa.free(key);
......@@ -3041,7 +3039,7 @@ pub fn deleteUnitExports(zcu: *Zcu, anal_unit: AnalUnit) void {
30413039 // `updateExports` on flush).
30423040 // This case is needed because in some rare edge cases, `Sema` wants to add and delete exports
30433041 // within a single update.
3044 if (!build_options.only_c) {
3042 if (dev.env.supports(.incremental)) {
30453043 for (exports, exports_base..) |exp, export_idx| {
30463044 if (zcu.comp.bin_file) |lf| {
30473045 lf.deleteExport(exp.exported, exp.opts.name);
src/Zcu/PerThread.zig+9-5
......@@ -64,6 +64,7 @@ pub fn astGenFile(
6464 path_digest: Cache.BinDigest,
6565 opt_root_decl: Zcu.Decl.OptionalIndex,
6666) !void {
67 dev.check(.ast_gen);
6768 assert(!file.mod.isBuiltin());
6869
6970 const tracy = trace(@src());
......@@ -504,6 +505,8 @@ pub fn ensureFileAnalyzed(pt: Zcu.PerThread, file_index: Zcu.File.Index) Zcu.Sem
504505/// For example an inferred error set is not resolved until after `analyzeFnBody`.
505506/// is called.
506507pub fn ensureDeclAnalyzed(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) Zcu.SemaError!void {
508 dev.check(.sema);
509
507510 const tracy = trace(@src());
508511 defer tracy.end();
509512
......@@ -552,9 +555,9 @@ pub fn ensureDeclAnalyzed(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) Zcu.Sem
552555 }
553556
554557 if (was_outdated) {
558 dev.check(.incremental);
555559 // The exports this Decl performs will be re-discovered, so we remove them here
556560 // prior to re-analysis.
557 if (build_options.only_c) unreachable;
558561 mod.deleteUnitExports(decl_as_depender);
559562 mod.deleteUnitReferences(decl_as_depender);
560563 }
......@@ -623,6 +626,8 @@ pub fn ensureDeclAnalyzed(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) Zcu.Sem
623626}
624627
625628pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: InternPool.Index) Zcu.SemaError!void {
629 dev.check(.sema);
630
626631 const tracy = trace(@src());
627632 defer tracy.end();
628633
......@@ -684,7 +689,7 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
684689 zcu.potentially_outdated.swapRemove(func_as_depender);
685690
686691 if (was_outdated) {
687 if (build_options.only_c) unreachable;
692 dev.check(.incremental);
688693 _ = zcu.outdated_ready.swapRemove(func_as_depender);
689694 zcu.deleteUnitExports(func_as_depender);
690695 zcu.deleteUnitReferences(func_as_depender);
......@@ -836,7 +841,6 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
836841 },
837842 };
838843 } else if (zcu.llvm_object) |llvm_object| {
839 if (build_options.only_c) unreachable;
840844 llvm_object.updateFunc(pt, func_index, air, liveness) catch |err| switch (err) {
841845 error.OutOfMemory => return error.OutOfMemory,
842846 };
......@@ -845,6 +849,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
845849
846850/// https://github.com/ziglang/zig/issues/14307
847851pub fn semaPkg(pt: Zcu.PerThread, pkg: *Module) !void {
852 dev.check(.sema);
848853 const import_file_result = try pt.importPkg(pkg);
849854 const root_decl_index = pt.zcu.fileRootDecl(import_file_result.file_index);
850855 if (root_decl_index == .none) {
......@@ -2481,7 +2486,6 @@ fn processExportsInner(
24812486 if (zcu.comp.bin_file) |lf| {
24822487 try zcu.handleUpdateExports(export_indices, lf.updateExports(pt, exported, export_indices));
24832488 } else if (zcu.llvm_object) |llvm_object| {
2484 if (build_options.only_c) unreachable;
24852489 try zcu.handleUpdateExports(export_indices, llvm_object.updateExports(pt, exported, export_indices));
24862490 }
24872491}
......@@ -2654,7 +2658,6 @@ pub fn linkerUpdateDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !void {
26542658 },
26552659 };
26562660 } else if (zcu.llvm_object) |llvm_object| {
2657 if (build_options.only_c) unreachable;
26582661 llvm_object.updateDecl(pt, decl_index) catch |err| switch (err) {
26592662 error.OutOfMemory => return error.OutOfMemory,
26602663 };
......@@ -3271,6 +3274,7 @@ const BigIntMutable = std.math.big.int.Mutable;
32713274const build_options = @import("build_options");
32723275const builtin = @import("builtin");
32733276const Cache = std.Build.Cache;
3277const dev = @import("../dev.zig");
32743278const InternPool = @import("../InternPool.zig");
32753279const isUpDir = @import("../introspect.zig").isUpDir;
32763280const Liveness = @import("../Liveness.zig");
src/codegen.zig+34-16
......@@ -22,6 +22,7 @@ const Type = @import("Type.zig");
2222const Value = @import("Value.zig");
2323const Zir = std.zig.Zir;
2424const Alignment = InternPool.Alignment;
25const dev = @import("dev.zig");
2526
2627pub const Result = union(enum) {
2728 /// The `code` parameter passed to `generateSymbol` has the value ok.
......@@ -43,6 +44,23 @@ pub const DebugInfoOutput = union(enum) {
4344 none,
4445};
4546
47fn devFeatureForBackend(comptime backend: std.builtin.CompilerBackend) dev.Feature {
48 comptime assert(mem.startsWith(u8, @tagName(backend), "stage2_"));
49 return @field(dev.Feature, @tagName(backend)["stage2_".len..] ++ "_backend");
50}
51
52fn importBackend(comptime backend: std.builtin.CompilerBackend) type {
53 return switch (backend) {
54 .stage2_aarch64 => @import("arch/aarch64/CodeGen.zig"),
55 .stage2_arm => @import("arch/arm/CodeGen.zig"),
56 .stage2_riscv64 => @import("arch/riscv64/CodeGen.zig"),
57 .stage2_sparc64 => @import("arch/sparc64/CodeGen.zig"),
58 .stage2_wasm => @import("arch/wasm/CodeGen.zig"),
59 .stage2_x86_64 => @import("arch/x86_64/CodeGen.zig"),
60 else => unreachable,
61 };
62}
63
4664pub fn generateFunction(
4765 lf: *link.File,
4866 pt: Zcu.PerThread,
......@@ -58,21 +76,18 @@ pub fn generateFunction(
5876 const decl = zcu.declPtr(func.owner_decl);
5977 const namespace = zcu.namespacePtr(decl.src_namespace);
6078 const target = namespace.fileScope(zcu).mod.resolved_target.result;
61 switch (target.cpu.arch) {
62 .arm,
63 .armeb,
64 => return @import("arch/arm/CodeGen.zig").generate(lf, pt, src_loc, func_index, air, liveness, code, debug_output),
65 .aarch64,
66 .aarch64_be,
67 .aarch64_32,
68 => return @import("arch/aarch64/CodeGen.zig").generate(lf, pt, src_loc, func_index, air, liveness, code, debug_output),
69 .riscv64 => return @import("arch/riscv64/CodeGen.zig").generate(lf, pt, src_loc, func_index, air, liveness, code, debug_output),
70 .sparc64 => return @import("arch/sparc64/CodeGen.zig").generate(lf, pt, src_loc, func_index, air, liveness, code, debug_output),
71 .x86_64 => return @import("arch/x86_64/CodeGen.zig").generate(lf, pt, src_loc, func_index, air, liveness, code, debug_output),
72 .wasm32,
73 .wasm64,
74 => return @import("arch/wasm/CodeGen.zig").generate(lf, pt, src_loc, func_index, air, liveness, code, debug_output),
79 switch (target_util.zigBackend(target, false)) {
7580 else => unreachable,
81 inline .stage2_aarch64,
82 .stage2_arm,
83 .stage2_riscv64,
84 .stage2_sparc64,
85 .stage2_wasm,
86 .stage2_x86_64,
87 => |backend| {
88 dev.check(devFeatureForBackend(backend));
89 return importBackend(backend).generate(lf, pt, src_loc, func_index, air, liveness, code, debug_output);
90 },
7691 }
7792}
7893
......@@ -89,9 +104,12 @@ pub fn generateLazyFunction(
89104 const decl = zcu.declPtr(decl_index);
90105 const namespace = zcu.namespacePtr(decl.src_namespace);
91106 const target = namespace.fileScope(zcu).mod.resolved_target.result;
92 switch (target.cpu.arch) {
93 .x86_64 => return @import("arch/x86_64/CodeGen.zig").generateLazy(lf, pt, src_loc, lazy_sym, code, debug_output),
107 switch (target_util.zigBackend(target, false)) {
94108 else => unreachable,
109 inline .stage2_x86_64 => |backend| {
110 dev.check(devFeatureForBackend(backend));
111 return importBackend(backend).generateLazy(lf, pt, src_loc, lazy_sym, code, debug_output);
112 },
95113 }
96114}
97115
src/codegen/llvm.zig-1
......@@ -868,7 +868,6 @@ pub const Object = struct {
868868 pub const TypeMap = std.AutoHashMapUnmanaged(InternPool.Index, Builder.Type);
869869
870870 pub fn create(arena: Allocator, comp: *Compilation) !*Object {
871 if (build_options.only_c) unreachable;
872871 const gpa = comp.gpa;
873872 const target = comp.root_mod.resolved_target.result;
874873 const llvm_target_triple = try targetTriple(arena, target);
src/dev.zig created+238
......@@ -0,0 +1,238 @@
1pub const Env = enum {
2 /// zig1 features
3 bootstrap,
4
5 /// zig2 features
6 core,
7
8 /// stage3 features
9 full,
10
11 /// - `zig cc`
12 /// - `zig c++`
13 /// - `zig translate-c`
14 c_source,
15
16 /// - `zig ast-check`
17 /// - `zig changelist`
18 /// - `zig dump-zir`
19 ast_gen,
20
21 /// - ast_gen
22 /// - `zig build-* -fno-emit-bin`
23 sema,
24
25 /// - sema
26 /// - jit command on x86_64-linux host
27 /// - `zig build-* -fno-llvm -fno-lld -target x86_64-linux`
28 @"x86_64-linux",
29
30 pub inline fn supports(comptime dev_env: Env, comptime feature: Feature) bool {
31 return switch (dev_env) {
32 .full => true,
33 .bootstrap => switch (feature) {
34 .build_exe_command,
35 .build_obj_command,
36 .ast_gen,
37 .sema,
38 .c_backend,
39 .c_linker,
40 => true,
41 else => false,
42 },
43 .core => switch (feature) {
44 .build_exe_command,
45 .build_lib_command,
46 .build_obj_command,
47 .test_command,
48 .run_command,
49 .ar_command,
50 .build_command,
51 .clang_command,
52 .stdio_listen,
53 .build_import_lib,
54 .make_executable,
55 .make_writable,
56 .incremental,
57 .ast_gen,
58 .sema,
59 .llvm_backend,
60 .c_backend,
61 .wasm_backend,
62 .arm_backend,
63 .x86_64_backend,
64 .aarch64_backend,
65 .x86_backend,
66 .riscv64_backend,
67 .sparc64_backend,
68 .spirv64_backend,
69 .lld_linker,
70 .coff_linker,
71 .elf_linker,
72 .macho_linker,
73 .c_linker,
74 .wasm_linker,
75 .spirv_linker,
76 .plan9_linker,
77 .nvptx_linker,
78 => true,
79 .cc_command,
80 .translate_c_command,
81 .jit_command,
82 .fetch_command,
83 .init_command,
84 .targets_command,
85 .version_command,
86 .env_command,
87 .zen_command,
88 .help_command,
89 .ast_check_command,
90 .detect_cpu_command,
91 .changelist_command,
92 .dump_zir_command,
93 .llvm_ints_command,
94 .docs_emit,
95 // Avoid dragging networking into zig2.c because it adds dependencies on some
96 // linker symbols that are annoying to satisfy while bootstrapping.
97 .network_listen,
98 .win32_resource,
99 => false,
100 },
101 .c_source => switch (feature) {
102 .clang_command,
103 .cc_command,
104 .translate_c_command,
105 => true,
106 else => false,
107 },
108 .ast_gen => switch (feature) {
109 .ast_check_command,
110 .changelist_command,
111 .dump_zir_command,
112 .make_executable,
113 .make_writable,
114 .incremental,
115 .ast_gen,
116 => true,
117 else => false,
118 },
119 .sema => switch (feature) {
120 .build_exe_command,
121 .build_lib_command,
122 .build_obj_command,
123 .test_command,
124 .run_command,
125 .sema,
126 => true,
127 else => Env.ast_gen.supports(feature),
128 },
129 .@"x86_64-linux" => switch (feature) {
130 .x86_64_backend,
131 .elf_linker,
132 => true,
133 else => Env.sema.supports(feature),
134 },
135 };
136 }
137
138 pub inline fn supportsAny(comptime dev_env: Env, comptime features: []const Feature) bool {
139 inline for (features) |feature| if (dev_env.supports(feature)) return true;
140 return false;
141 }
142
143 pub inline fn supportsAll(comptime dev_env: Env, comptime features: []const Feature) bool {
144 inline for (features) |feature| if (!dev_env.supports(feature)) return false;
145 return true;
146 }
147};
148
149pub const Feature = enum {
150 build_exe_command,
151 build_lib_command,
152 build_obj_command,
153 test_command,
154 run_command,
155 ar_command,
156 build_command,
157 clang_command,
158 cc_command,
159 translate_c_command,
160 jit_command,
161 fetch_command,
162 init_command,
163 targets_command,
164 version_command,
165 env_command,
166 zen_command,
167 help_command,
168 ast_check_command,
169 detect_cpu_command,
170 changelist_command,
171 dump_zir_command,
172 llvm_ints_command,
173
174 docs_emit,
175 stdio_listen,
176 network_listen,
177 build_import_lib,
178 win32_resource,
179 make_executable,
180 make_writable,
181 incremental,
182 ast_gen,
183 sema,
184
185 llvm_backend,
186 c_backend,
187 wasm_backend,
188 arm_backend,
189 x86_64_backend,
190 aarch64_backend,
191 x86_backend,
192 riscv64_backend,
193 sparc64_backend,
194 spirv64_backend,
195
196 lld_linker,
197 coff_linker,
198 elf_linker,
199 macho_linker,
200 c_linker,
201 wasm_linker,
202 spirv_linker,
203 plan9_linker,
204 nvptx_linker,
205};
206
207/// Makes the code following the call to this function unreachable if `feature` is disabled.
208pub fn check(comptime feature: Feature) if (env.supports(feature)) void else noreturn {
209 if (env.supports(feature)) return;
210 @panic("development environment " ++ @tagName(env) ++ " does not support feature " ++ @tagName(feature));
211}
212
213/// Makes the code following the call to this function unreachable if all of `features` are disabled.
214pub fn checkAny(comptime features: []const Feature) if (env.supportsAny(features)) void else noreturn {
215 if (env.supportsAny(features)) return;
216 comptime var feature_tags: []const u8 = "";
217 inline for (features[0 .. features.len - 1]) |feature| feature_tags = feature_tags ++ @tagName(feature) ++ ", ";
218 feature_tags = feature_tags ++ "or " ++ @tagName(features[features.len - 1]);
219 @panic("development environment " ++ @tagName(env) ++ " does not support feature " ++ feature_tags);
220}
221
222/// Makes the code following the call to this function unreachable if any of `features` are disabled.
223pub fn checkAll(comptime features: []const Feature) if (env.supportsAll(features)) void else noreturn {
224 if (env.supportsAll(features)) return;
225 inline for (features) |feature| if (!env.supports(feature))
226 @panic("development environment " ++ @tagName(env) ++ " does not support feature " ++ @tagName(feature));
227}
228
229const build_options = @import("build_options");
230
231pub const env: Env = if (@hasDecl(build_options, "dev"))
232 @field(Env, @tagName(build_options.dev))
233else if (@hasDecl(build_options, "only_c") and build_options.only_c)
234 .bootstrap
235else if (@hasDecl(build_options, "only_core_functionality") and build_options.only_core_functionality)
236 .core
237else
238 .full;
src/link.zig+40-37
......@@ -21,6 +21,7 @@ const Value = @import("Value.zig");
2121const LlvmObject = @import("codegen/llvm.zig").Object;
2222const lldMain = @import("main.zig").lldMain;
2323const Package = @import("Package.zig");
24const dev = @import("dev.zig");
2425
2526/// When adding a new field, remember to update `hashAddSystemLibs`.
2627/// These are *always* dynamically linked. Static libraries will be
......@@ -192,7 +193,7 @@ pub const File = struct {
192193 ) !*File {
193194 switch (Tag.fromObjectFormat(comp.root_mod.resolved_target.result.ofmt)) {
194195 inline else => |tag| {
195 if (tag != .c and build_options.only_c) unreachable;
196 dev.check(tag.devFeature());
196197 const ptr = try tag.Type().open(arena, comp, emit, options);
197198 return &ptr.base;
198199 },
......@@ -207,7 +208,7 @@ pub const File = struct {
207208 ) !*File {
208209 switch (Tag.fromObjectFormat(comp.root_mod.resolved_target.result.ofmt)) {
209210 inline else => |tag| {
210 if (tag != .c and build_options.only_c) unreachable;
211 dev.check(tag.devFeature());
211212 const ptr = try tag.Type().createEmpty(arena, comp, emit, options);
212213 return &ptr.base;
213214 },
......@@ -219,12 +220,13 @@ pub const File = struct {
219220 }
220221
221222 pub fn makeWritable(base: *File) !void {
223 dev.check(.make_writable);
222224 const comp = base.comp;
223225 const gpa = comp.gpa;
224226 switch (base.tag) {
225227 .coff, .elf, .macho, .plan9, .wasm => {
226 if (build_options.only_c) unreachable;
227228 if (base.file != null) return;
229 dev.checkAny(&.{ .coff_linker, .elf_linker, .macho_linker, .plan9_linker, .wasm_linker });
228230 const emit = base.emit;
229231 if (base.child_pid) |pid| {
230232 if (builtin.os.tag == .windows) {
......@@ -263,11 +265,12 @@ pub const File = struct {
263265 .mode = determineMode(use_lld, output_mode, link_mode),
264266 });
265267 },
266 .c, .spirv, .nvptx => {},
268 .c, .spirv, .nvptx => dev.checkAny(&.{ .c_linker, .spirv_linker, .nvptx_linker }),
267269 }
268270 }
269271
270272 pub fn makeExecutable(base: *File) !void {
273 dev.check(.make_executable);
271274 const comp = base.comp;
272275 const output_mode = comp.config.output_mode;
273276 const link_mode = comp.config.link_mode;
......@@ -283,7 +286,7 @@ pub const File = struct {
283286 }
284287 switch (base.tag) {
285288 .elf => if (base.file) |f| {
286 if (build_options.only_c) unreachable;
289 dev.check(.elf_linker);
287290 if (base.zcu_object_sub_path != null and use_lld) {
288291 // The file we have open is not the final file that we want to
289292 // make executable, so we don't have to close it.
......@@ -302,7 +305,7 @@ pub const File = struct {
302305 }
303306 },
304307 .coff, .macho, .plan9, .wasm => if (base.file) |f| {
305 if (build_options.only_c) unreachable;
308 dev.checkAny(&.{ .coff_linker, .macho_linker, .plan9_linker, .wasm_linker });
306309 if (base.zcu_object_sub_path != null) {
307310 // The file we have open is not the final file that we want to
308311 // make executable, so we don't have to close it.
......@@ -321,7 +324,7 @@ pub const File = struct {
321324 }
322325 }
323326 },
324 .c, .spirv, .nvptx => {},
327 .c, .spirv, .nvptx => dev.checkAny(&.{ .c_linker, .spirv_linker, .nvptx_linker }),
325328 }
326329 }
327330
......@@ -366,13 +369,13 @@ pub const File = struct {
366369 /// constant. Returns the symbol index of the lowered constant in the read-only section
367370 /// of the final binary.
368371 pub fn lowerUnnamedConst(base: *File, pt: Zcu.PerThread, val: Value, decl_index: InternPool.DeclIndex) UpdateDeclError!u32 {
369 if (build_options.only_c) @compileError("unreachable");
370372 switch (base.tag) {
371373 .spirv => unreachable,
372374 .c => unreachable,
373375 .nvptx => unreachable,
374 inline else => |t| {
375 return @as(*t.Type(), @fieldParentPtr("base", base)).lowerUnnamedConst(pt, val, decl_index);
376 inline else => |tag| {
377 dev.check(tag.devFeature());
378 return @as(*tag.Type(), @fieldParentPtr("base", base)).lowerUnnamedConst(pt, val, decl_index);
376379 },
377380 }
378381 }
......@@ -383,15 +386,15 @@ pub const File = struct {
383386 /// Optionally, it is possible to specify where to expect the symbol defined if it
384387 /// is an import.
385388 pub fn getGlobalSymbol(base: *File, name: []const u8, lib_name: ?[]const u8) UpdateDeclError!u32 {
386 if (build_options.only_c) @compileError("unreachable");
387389 log.debug("getGlobalSymbol '{s}' (expected in '{?s}')", .{ name, lib_name });
388390 switch (base.tag) {
389391 .plan9 => unreachable,
390392 .spirv => unreachable,
391393 .c => unreachable,
392394 .nvptx => unreachable,
393 inline else => |t| {
394 return @as(*t.Type(), @fieldParentPtr("base", base)).getGlobalSymbol(name, lib_name);
395 inline else => |tag| {
396 dev.check(tag.devFeature());
397 return @as(*tag.Type(), @fieldParentPtr("base", base)).getGlobalSymbol(name, lib_name);
395398 },
396399 }
397400 }
......@@ -402,7 +405,7 @@ pub const File = struct {
402405 assert(decl.has_tv);
403406 switch (base.tag) {
404407 inline else => |tag| {
405 if (tag != .c and build_options.only_c) unreachable;
408 dev.check(tag.devFeature());
406409 return @as(*tag.Type(), @fieldParentPtr("base", base)).updateDecl(pt, decl_index);
407410 },
408411 }
......@@ -418,7 +421,7 @@ pub const File = struct {
418421 ) UpdateDeclError!void {
419422 switch (base.tag) {
420423 inline else => |tag| {
421 if (tag != .c and build_options.only_c) unreachable;
424 dev.check(tag.devFeature());
422425 return @as(*tag.Type(), @fieldParentPtr("base", base)).updateFunc(pt, func_index, air, liveness);
423426 },
424427 }
......@@ -430,7 +433,7 @@ pub const File = struct {
430433 switch (base.tag) {
431434 .spirv, .nvptx => {},
432435 inline else => |tag| {
433 if (tag != .c and build_options.only_c) unreachable;
436 dev.check(tag.devFeature());
434437 return @as(*tag.Type(), @fieldParentPtr("base", base)).updateDeclLineNumber(pt, decl_index);
435438 },
436439 }
......@@ -454,7 +457,7 @@ pub const File = struct {
454457 if (base.file) |f| f.close();
455458 switch (base.tag) {
456459 inline else => |tag| {
457 if (tag != .c and build_options.only_c) unreachable;
460 dev.check(tag.devFeature());
458461 @as(*tag.Type(), @fieldParentPtr("base", base)).deinit();
459462 },
460463 }
......@@ -536,12 +539,9 @@ pub const File = struct {
536539 /// and `use_lld`, not only `effectiveOutputMode`.
537540 /// `arena` has the lifetime of the call to `Compilation.update`.
538541 pub fn flush(base: *File, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) FlushError!void {
539 if (build_options.only_c) {
540 assert(base.tag == .c);
541 return @as(*C, @fieldParentPtr("base", base)).flush(arena, tid, prog_node);
542 }
543542 const comp = base.comp;
544543 if (comp.clang_preprocessor_mode == .yes or comp.clang_preprocessor_mode == .pch) {
544 dev.check(.clang_command);
545545 const gpa = comp.gpa;
546546 const emit = base.emit;
547547 // TODO: avoid extra link step when it's just 1 object file (the `zig cc -c` case)
......@@ -565,6 +565,7 @@ pub const File = struct {
565565 }
566566 switch (base.tag) {
567567 inline else => |tag| {
568 dev.check(tag.devFeature());
568569 return @as(*tag.Type(), @fieldParentPtr("base", base)).flush(arena, tid, prog_node);
569570 },
570571 }
......@@ -575,7 +576,7 @@ pub const File = struct {
575576 pub fn flushModule(base: *File, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) FlushError!void {
576577 switch (base.tag) {
577578 inline else => |tag| {
578 if (tag != .c and build_options.only_c) unreachable;
579 dev.check(tag.devFeature());
579580 return @as(*tag.Type(), @fieldParentPtr("base", base)).flushModule(arena, tid, prog_node);
580581 },
581582 }
......@@ -585,7 +586,7 @@ pub const File = struct {
585586 pub fn freeDecl(base: *File, decl_index: InternPool.DeclIndex) void {
586587 switch (base.tag) {
587588 inline else => |tag| {
588 if (tag != .c and build_options.only_c) unreachable;
589 dev.check(tag.devFeature());
589590 @as(*tag.Type(), @fieldParentPtr("base", base)).freeDecl(decl_index);
590591 },
591592 }
......@@ -608,7 +609,7 @@ pub const File = struct {
608609 ) UpdateExportsError!void {
609610 switch (base.tag) {
610611 inline else => |tag| {
611 if (tag != .c and build_options.only_c) unreachable;
612 dev.check(tag.devFeature());
612613 return @as(*tag.Type(), @fieldParentPtr("base", base)).updateExports(pt, exported, export_indices);
613614 },
614615 }
......@@ -627,12 +628,12 @@ pub const File = struct {
627628 /// May be called before or after updateFunc/updateDecl therefore it is up to the linker to allocate
628629 /// the block/atom.
629630 pub fn getDeclVAddr(base: *File, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex, reloc_info: RelocInfo) !u64 {
630 if (build_options.only_c) @compileError("unreachable");
631631 switch (base.tag) {
632632 .c => unreachable,
633633 .spirv => unreachable,
634634 .nvptx => unreachable,
635635 inline else => |tag| {
636 dev.check(tag.devFeature());
636637 return @as(*tag.Type(), @fieldParentPtr("base", base)).getDeclVAddr(pt, decl_index, reloc_info);
637638 },
638639 }
......@@ -647,24 +648,24 @@ pub const File = struct {
647648 decl_align: InternPool.Alignment,
648649 src_loc: Zcu.LazySrcLoc,
649650 ) !LowerResult {
650 if (build_options.only_c) @compileError("unreachable");
651651 switch (base.tag) {
652652 .c => unreachable,
653653 .spirv => unreachable,
654654 .nvptx => unreachable,
655655 inline else => |tag| {
656 dev.check(tag.devFeature());
656657 return @as(*tag.Type(), @fieldParentPtr("base", base)).lowerAnonDecl(pt, decl_val, decl_align, src_loc);
657658 },
658659 }
659660 }
660661
661662 pub fn getAnonDeclVAddr(base: *File, decl_val: InternPool.Index, reloc_info: RelocInfo) !u64 {
662 if (build_options.only_c) @compileError("unreachable");
663663 switch (base.tag) {
664664 .c => unreachable,
665665 .spirv => unreachable,
666666 .nvptx => unreachable,
667667 inline else => |tag| {
668 dev.check(tag.devFeature());
668669 return @as(*tag.Type(), @fieldParentPtr("base", base)).getAnonDeclVAddr(decl_val, reloc_info);
669670 },
670671 }
......@@ -675,7 +676,6 @@ pub const File = struct {
675676 exported: Zcu.Exported,
676677 name: InternPool.NullTerminatedString,
677678 ) void {
678 if (build_options.only_c) @compileError("unreachable");
679679 switch (base.tag) {
680680 .plan9,
681681 .spirv,
......@@ -683,12 +683,15 @@ pub const File = struct {
683683 => {},
684684
685685 inline else => |tag| {
686 dev.check(tag.devFeature());
686687 return @as(*tag.Type(), @fieldParentPtr("base", base)).deleteExport(exported, name);
687688 },
688689 }
689690 }
690691
691692 pub fn linkAsArchive(base: *File, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) FlushError!void {
693 dev.check(.lld_linker);
694
692695 const tracy = trace(@src());
693696 defer tracy.end();
694697
......@@ -743,10 +746,8 @@ pub const File = struct {
743746 for (comp.c_object_table.keys()) |key| {
744747 _ = try man.addFile(key.status.success.object_path, null);
745748 }
746 if (!build_options.only_core_functionality) {
747 for (comp.win32_resource_table.keys()) |key| {
748 _ = try man.addFile(key.status.success.res_path, null);
749 }
749 for (comp.win32_resource_table.keys()) |key| {
750 _ = try man.addFile(key.status.success.res_path, null);
750751 }
751752 try man.addOptionalFile(zcu_obj_path);
752753 try man.addOptionalFile(compiler_rt_path);
......@@ -777,7 +778,7 @@ pub const File = struct {
777778 };
778779 }
779780
780 const win32_resource_table_len = if (build_options.only_core_functionality) 0 else comp.win32_resource_table.count();
781 const win32_resource_table_len = comp.win32_resource_table.count();
781782 const num_object_files = objects.len + comp.c_object_table.count() + win32_resource_table_len + 2;
782783 var object_files = try std.ArrayList([*:0]const u8).initCapacity(gpa, num_object_files);
783784 defer object_files.deinit();
......@@ -788,10 +789,8 @@ pub const File = struct {
788789 for (comp.c_object_table.keys()) |key| {
789790 object_files.appendAssumeCapacity(try arena.dupeZ(u8, key.status.success.object_path));
790791 }
791 if (!build_options.only_core_functionality) {
792 for (comp.win32_resource_table.keys()) |key| {
793 object_files.appendAssumeCapacity(try arena.dupeZ(u8, key.status.success.res_path));
794 }
792 for (comp.win32_resource_table.keys()) |key| {
793 object_files.appendAssumeCapacity(try arena.dupeZ(u8, key.status.success.res_path));
795794 }
796795 if (zcu_obj_path) |p| {
797796 object_files.appendAssumeCapacity(try arena.dupeZ(u8, p));
......@@ -869,6 +868,10 @@ pub const File = struct {
869868 .dxcontainer => @panic("TODO implement dxcontainer object format"),
870869 };
871870 }
871
872 pub fn devFeature(tag: Tag) dev.Feature {
873 return @field(dev.Feature, @tagName(tag) ++ "_linker");
874 }
872875 };
873876
874877 pub const ErrorFlags = struct {
src/link/Coff/lld.zig+7-8
......@@ -2,6 +2,7 @@ const std = @import("std");
22const build_options = @import("build_options");
33const allocPrint = std.fmt.allocPrint;
44const assert = std.debug.assert;
5const dev = @import("../../dev.zig");
56const fs = std.fs;
67const log = std.log.scoped(.link);
78const mem = std.mem;
......@@ -18,6 +19,8 @@ const Compilation = @import("../../Compilation.zig");
1819const Zcu = @import("../../Zcu.zig");
1920
2021pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) !void {
22 dev.check(.lld_linker);
23
2124 const tracy = trace(@src());
2225 defer tracy.end();
2326
......@@ -77,10 +80,8 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
7780 for (comp.c_object_table.keys()) |key| {
7881 _ = try man.addFile(key.status.success.object_path, null);
7982 }
80 if (!build_options.only_core_functionality) {
81 for (comp.win32_resource_table.keys()) |key| {
82 _ = try man.addFile(key.status.success.res_path, null);
83 }
83 for (comp.win32_resource_table.keys()) |key| {
84 _ = try man.addFile(key.status.success.res_path, null);
8485 }
8586 try man.addOptionalFile(module_obj_path);
8687 man.hash.addOptionalBytes(entry_name);
......@@ -274,10 +275,8 @@ pub fn linkWithLLD(self: *Coff, arena: Allocator, tid: Zcu.PerThread.Id, prog_no
274275 try argv.append(key.status.success.object_path);
275276 }
276277
277 if (!build_options.only_core_functionality) {
278 for (comp.win32_resource_table.keys()) |key| {
279 try argv.append(key.status.success.res_path);
280 }
278 for (comp.win32_resource_table.keys()) |key| {
279 try argv.append(key.status.success.res_path);
281280 }
282281
283282 if (module_obj_path) |p| {
src/link/Elf.zig+3
......@@ -2148,6 +2148,8 @@ fn scanRelocs(self: *Elf) !void {
21482148}
21492149
21502150fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) !void {
2151 dev.check(.lld_linker);
2152
21512153 const tracy = trace(@src());
21522154 defer tracy.end();
21532155
......@@ -6430,6 +6432,7 @@ const math = std.math;
64306432const mem = std.mem;
64316433
64326434const codegen = @import("../codegen.zig");
6435const dev = @import("../dev.zig");
64336436const eh_frame = @import("Elf/eh_frame.zig");
64346437const gc = @import("Elf/gc.zig");
64356438const glibc = @import("../glibc.zig");
src/link/Wasm.zig+3
......@@ -6,6 +6,7 @@ const assert = std.debug.assert;
66const build_options = @import("build_options");
77const builtin = @import("builtin");
88const codegen = @import("../codegen.zig");
9const dev = @import("../dev.zig");
910const fs = std.fs;
1011const leb = std.leb;
1112const link = @import("../link.zig");
......@@ -3325,6 +3326,8 @@ fn emitImport(wasm: *Wasm, writer: anytype, import: types.Import) !void {
33253326}
33263327
33273328fn linkWithLLD(wasm: *Wasm, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) !void {
3329 dev.check(.lld_linker);
3330
33283331 const tracy = trace(@src());
33293332 defer tracy.end();
33303333
src/main.zig+97-82
......@@ -30,6 +30,7 @@ const Zcu = @import("Zcu.zig");
3030const AstGen = std.zig.AstGen;
3131const mingw = @import("mingw.zig");
3232const Server = std.zig.Server;
33const dev = @import("dev.zig");
3334
3435pub const std_options = .{
3536 .wasiCwd = wasi_cwd,
......@@ -195,17 +196,6 @@ pub fn main() anyerror!void {
195196 wasi_preopens = try fs.wasi.preopensAlloc(arena);
196197 }
197198
198 // Short circuit some of the other logic for bootstrapping.
199 if (build_options.only_c) {
200 if (mem.eql(u8, args[1], "build-exe")) {
201 return buildOutputType(gpa, arena, args, .{ .build = .Exe });
202 } else if (mem.eql(u8, args[1], "build-obj")) {
203 return buildOutputType(gpa, arena, args, .{ .build = .Obj });
204 } else {
205 @panic("only build-exe or build-obj is supported in a -Donly-c build");
206 }
207 }
208
209199 return mainArgs(gpa, arena, args);
210200}
211201
......@@ -227,6 +217,7 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
227217 }
228218
229219 if (process.can_execv and std.posix.getenvZ("ZIG_IS_DETECTING_LIBC_PATHS") != null) {
220 dev.check(.cc_command);
230221 // In this case we have accidentally invoked ourselves as "the system C compiler"
231222 // to figure out where libc is installed. This is essentially infinite recursion
232223 // via child process execution due to the CC environment variable pointing to Zig.
......@@ -260,39 +251,49 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
260251 const cmd = args[1];
261252 const cmd_args = args[2..];
262253 if (mem.eql(u8, cmd, "build-exe")) {
254 dev.check(.build_exe_command);
263255 return buildOutputType(gpa, arena, args, .{ .build = .Exe });
264256 } else if (mem.eql(u8, cmd, "build-lib")) {
257 dev.check(.build_lib_command);
265258 return buildOutputType(gpa, arena, args, .{ .build = .Lib });
266259 } else if (mem.eql(u8, cmd, "build-obj")) {
260 dev.check(.build_obj_command);
267261 return buildOutputType(gpa, arena, args, .{ .build = .Obj });
268262 } else if (mem.eql(u8, cmd, "test")) {
263 dev.check(.test_command);
269264 return buildOutputType(gpa, arena, args, .zig_test);
270265 } else if (mem.eql(u8, cmd, "run")) {
266 dev.check(.run_command);
271267 return buildOutputType(gpa, arena, args, .run);
272268 } else if (mem.eql(u8, cmd, "dlltool") or
273269 mem.eql(u8, cmd, "ranlib") or
274270 mem.eql(u8, cmd, "lib") or
275271 mem.eql(u8, cmd, "ar"))
276272 {
273 dev.check(.ar_command);
277274 return process.exit(try llvmArMain(arena, args));
278275 } else if (mem.eql(u8, cmd, "build")) {
276 dev.check(.build_command);
279277 return cmdBuild(gpa, arena, cmd_args);
280278 } else if (mem.eql(u8, cmd, "clang") or
281279 mem.eql(u8, cmd, "-cc1") or mem.eql(u8, cmd, "-cc1as"))
282280 {
281 dev.check(.clang_command);
283282 return process.exit(try clangMain(arena, args));
284283 } else if (mem.eql(u8, cmd, "ld.lld") or
285284 mem.eql(u8, cmd, "lld-link") or
286285 mem.eql(u8, cmd, "wasm-ld"))
287286 {
287 dev.check(.lld_linker);
288288 return process.exit(try lldMain(arena, args, true));
289 } else if (build_options.only_core_functionality) {
290 @panic("only a few subcommands are supported in a zig2.c build");
291289 } else if (mem.eql(u8, cmd, "cc")) {
290 dev.check(.cc_command);
292291 return buildOutputType(gpa, arena, args, .cc);
293292 } else if (mem.eql(u8, cmd, "c++")) {
293 dev.check(.cc_command);
294294 return buildOutputType(gpa, arena, args, .cpp);
295295 } else if (mem.eql(u8, cmd, "translate-c")) {
296 dev.check(.translate_c_command);
296297 return buildOutputType(gpa, arena, args, .translate_c);
297298 } else if (mem.eql(u8, cmd, "rc")) {
298299 const use_server = cmd_args.len > 0 and std.mem.eql(u8, cmd_args[0], "--zig-integration");
......@@ -332,16 +333,19 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
332333 } else if (mem.eql(u8, cmd, "init")) {
333334 return cmdInit(gpa, arena, cmd_args);
334335 } else if (mem.eql(u8, cmd, "targets")) {
336 dev.check(.targets_command);
335337 const host = std.zig.resolveTargetQueryOrFatal(.{});
336338 const stdout = io.getStdOut().writer();
337339 return @import("print_targets.zig").cmdTargets(arena, cmd_args, stdout, host);
338340 } else if (mem.eql(u8, cmd, "version")) {
341 dev.check(.version_command);
339342 try std.io.getStdOut().writeAll(build_options.version ++ "\n");
340343 // Check libc++ linkage to make sure Zig was built correctly, but only
341344 // for "env" and "version" to avoid affecting the startup time for
342345 // build-critical commands (check takes about ~10 μs)
343346 return verifyLibcxxCorrectlyLinked();
344347 } else if (mem.eql(u8, cmd, "env")) {
348 dev.check(.env_command);
345349 verifyLibcxxCorrectlyLinked();
346350 return @import("print_env.zig").cmdEnv(arena, cmd_args, io.getStdOut().writer());
347351 } else if (mem.eql(u8, cmd, "reduce")) {
......@@ -350,8 +354,10 @@ fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
350354 .root_src_path = "reduce.zig",
351355 });
352356 } else if (mem.eql(u8, cmd, "zen")) {
357 dev.check(.zen_command);
353358 return io.getStdOut().writeAll(info_zen);
354359 } else if (mem.eql(u8, cmd, "help") or mem.eql(u8, cmd, "-h") or mem.eql(u8, cmd, "--help")) {
360 dev.check(.help_command);
355361 return io.getStdOut().writeAll(usage);
356362 } else if (mem.eql(u8, cmd, "ast-check")) {
357363 return cmdAstCheck(gpa, arena, cmd_args);
......@@ -726,14 +732,10 @@ const ArgMode = union(enum) {
726732 run,
727733};
728734
729/// Avoid dragging networking into zig2.c because it adds dependencies on some
730/// linker symbols that are annoying to satisfy while bootstrapping.
731const Ip4Address = if (build_options.only_core_functionality) void else std.net.Ip4Address;
732
733735const Listen = union(enum) {
734736 none,
735 ip4: Ip4Address,
736 stdio,
737 stdio: if (dev.env.supports(.stdio_listen)) void else noreturn,
738 ip4: if (dev.env.supports(.network_listen)) std.net.Ip4Address else noreturn,
737739};
738740
739741const ArgsIterator = struct {
......@@ -1338,9 +1340,10 @@ fn buildOutputType(
13381340 } else if (mem.eql(u8, arg, "--listen")) {
13391341 const next_arg = args_iter.nextOrFatal();
13401342 if (mem.eql(u8, next_arg, "-")) {
1343 dev.check(.stdio_listen);
13411344 listen = .stdio;
13421345 } else {
1343 if (build_options.only_core_functionality) unreachable;
1346 dev.check(.network_listen);
13441347 // example: --listen 127.0.0.1:9000
13451348 var it = std.mem.splitScalar(u8, next_arg, ':');
13461349 const host = it.next().?;
......@@ -1351,6 +1354,7 @@ fn buildOutputType(
13511354 fatal("invalid host: '{s}': {s}", .{ host, @errorName(err) }) };
13521355 }
13531356 } else if (mem.eql(u8, arg, "--listen=-")) {
1357 dev.check(.stdio_listen);
13541358 listen = .stdio;
13551359 } else if (mem.eql(u8, arg, "--debug-link-snapshot")) {
13561360 if (!build_options.enable_link_snapshots) {
......@@ -1359,6 +1363,7 @@ fn buildOutputType(
13591363 enable_link_snapshots = true;
13601364 }
13611365 } else if (mem.eql(u8, arg, "-fincremental")) {
1366 dev.check(.incremental);
13621367 opt_incremental = true;
13631368 } else if (mem.eql(u8, arg, "-fno-incremental")) {
13641369 opt_incremental = false;
......@@ -1762,7 +1767,7 @@ fn buildOutputType(
17621767 }
17631768 },
17641769 .cc, .cpp => {
1765 if (build_options.only_c) unreachable;
1770 dev.check(.cc_command);
17661771
17671772 emit_h = .no;
17681773 soname = .no;
......@@ -3395,7 +3400,6 @@ fn buildOutputType(
33953400 switch (listen) {
33963401 .none => {},
33973402 .stdio => {
3398 if (build_options.only_c) unreachable;
33993403 try serve(
34003404 comp,
34013405 std.io.getStdIn(),
......@@ -3409,8 +3413,6 @@ fn buildOutputType(
34093413 return cleanExit();
34103414 },
34113415 .ip4 => |ip4_addr| {
3412 if (build_options.only_core_functionality) unreachable;
3413
34143416 const addr: std.net.Address = .{ .in = ip4_addr };
34153417
34163418 var server = try addr.listen(.{
......@@ -3454,50 +3456,50 @@ fn buildOutputType(
34543456 else => |e| return e,
34553457 };
34563458 }
3457 if (build_options.only_c) return cleanExit();
34583459 try comp.makeBinFileExecutable();
34593460 saveState(comp, incremental);
34603461
3461 if (test_exec_args.items.len == 0 and target.ofmt == .c) default_exec_args: {
3462 // Default to using `zig run` to execute the produced .c code from `zig test`.
3463 const c_code_loc = emit_bin_loc orelse break :default_exec_args;
3464 const c_code_directory = c_code_loc.directory orelse comp.bin_file.?.emit.directory;
3465 const c_code_path = try fs.path.join(arena, &[_][]const u8{
3466 c_code_directory.path orelse ".", c_code_loc.basename,
3467 });
3468 try test_exec_args.appendSlice(arena, &.{ self_exe_path, "run" });
3469 if (zig_lib_directory.path) |p| {
3470 try test_exec_args.appendSlice(arena, &.{ "-I", p });
3471 }
3472
3473 if (create_module.resolved_options.link_libc) {
3474 try test_exec_args.append(arena, "-lc");
3475 } else if (target.os.tag == .windows) {
3476 try test_exec_args.appendSlice(arena, &.{
3477 "--subsystem", "console",
3478 "-lkernel32", "-lntdll",
3462 if (switch (arg_mode) {
3463 .run => true,
3464 .zig_test => !test_no_exec,
3465 else => false,
3466 }) {
3467 dev.checkAny(&.{ .run_command, .test_command });
3468
3469 if (test_exec_args.items.len == 0 and target.ofmt == .c) default_exec_args: {
3470 // Default to using `zig run` to execute the produced .c code from `zig test`.
3471 const c_code_loc = emit_bin_loc orelse break :default_exec_args;
3472 const c_code_directory = c_code_loc.directory orelse comp.bin_file.?.emit.directory;
3473 const c_code_path = try fs.path.join(arena, &[_][]const u8{
3474 c_code_directory.path orelse ".", c_code_loc.basename,
34793475 });
3480 }
3476 try test_exec_args.appendSlice(arena, &.{ self_exe_path, "run" });
3477 if (zig_lib_directory.path) |p| {
3478 try test_exec_args.appendSlice(arena, &.{ "-I", p });
3479 }
34813480
3482 const first_cli_mod = create_module.modules.values()[0];
3483 if (first_cli_mod.target_arch_os_abi) |triple| {
3484 try test_exec_args.appendSlice(arena, &.{ "-target", triple });
3485 }
3486 if (first_cli_mod.target_mcpu) |mcpu| {
3487 try test_exec_args.append(arena, try std.fmt.allocPrint(arena, "-mcpu={s}", .{mcpu}));
3488 }
3489 if (create_module.dynamic_linker) |dl| {
3490 try test_exec_args.appendSlice(arena, &.{ "--dynamic-linker", dl });
3481 if (create_module.resolved_options.link_libc) {
3482 try test_exec_args.append(arena, "-lc");
3483 } else if (target.os.tag == .windows) {
3484 try test_exec_args.appendSlice(arena, &.{
3485 "--subsystem", "console",
3486 "-lkernel32", "-lntdll",
3487 });
3488 }
3489
3490 const first_cli_mod = create_module.modules.values()[0];
3491 if (first_cli_mod.target_arch_os_abi) |triple| {
3492 try test_exec_args.appendSlice(arena, &.{ "-target", triple });
3493 }
3494 if (first_cli_mod.target_mcpu) |mcpu| {
3495 try test_exec_args.append(arena, try std.fmt.allocPrint(arena, "-mcpu={s}", .{mcpu}));
3496 }
3497 if (create_module.dynamic_linker) |dl| {
3498 try test_exec_args.appendSlice(arena, &.{ "--dynamic-linker", dl });
3499 }
3500 try test_exec_args.append(arena, c_code_path);
34913501 }
3492 try test_exec_args.append(arena, c_code_path);
3493 }
34943502
3495 const run_or_test = switch (arg_mode) {
3496 .run => true,
3497 .zig_test => !test_no_exec,
3498 else => false,
3499 };
3500 if (run_or_test) {
35013503 try runOrTest(
35023504 comp,
35033505 gpa,
......@@ -4459,7 +4461,8 @@ fn cmdTranslateC(
44594461 file_system_inputs: ?*std.ArrayListUnmanaged(u8),
44604462 prog_node: std.Progress.Node,
44614463) !void {
4462 if (build_options.only_core_functionality) @panic("@translate-c is not available in a zig2.c build");
4464 dev.check(.translate_c_command);
4465
44634466 const color: Color = .auto;
44644467 assert(comp.c_source_files.len == 1);
44654468 const c_source_file = comp.c_source_files[0];
......@@ -4627,6 +4630,8 @@ const usage_init =
46274630;
46284631
46294632fn cmdInit(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
4633 dev.check(.init_command);
4634
46304635 {
46314636 var i: usize = 0;
46324637 while (i < args.len) : (i += 1) {
......@@ -4678,6 +4683,8 @@ fn cmdInit(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
46784683}
46794684
46804685fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
4686 dev.check(.build_command);
4687
46814688 var build_file: ?[]const u8 = null;
46824689 var override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena);
46834690 var override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);
......@@ -4969,16 +4976,12 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
49694976 });
49704977 defer thread_pool.deinit();
49714978
4972 // Dummy http client that is not actually used when only_core_functionality is enabled.
4979 // Dummy http client that is not actually used when fetch_command is unsupported.
49734980 // Prevents bootstrap from depending on a bunch of unnecessary stuff.
4974 const HttpClient = if (build_options.only_core_functionality) struct {
4981 var http_client: if (dev.env.supports(.fetch_command)) std.http.Client else struct {
49754982 allocator: Allocator,
4976 fn deinit(self: *@This()) void {
4977 _ = self;
4978 }
4979 } else std.http.Client;
4980
4981 var http_client: HttpClient = .{ .allocator = gpa };
4983 fn deinit(_: @This()) void {}
4984 } = .{ .allocator = gpa };
49824985 defer http_client.deinit();
49834986
49844987 var unlazy_set: Package.Fetch.JobQueue.UnlazySet = .{};
......@@ -5045,16 +5048,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
50455048 var cleanup_build_dir: ?fs.Dir = null;
50465049 defer if (cleanup_build_dir) |*dir| dir.close();
50475050
5048 if (build_options.only_core_functionality) {
5049 try createEmptyDependenciesModule(
5050 arena,
5051 root_mod,
5052 global_cache_directory,
5053 local_cache_directory,
5054 builtin_mod,
5055 config,
5056 );
5057 } else {
5051 if (dev.env.supports(.fetch_command)) {
50585052 const fetch_prog_node = root_prog_node.start("Fetch Packages", 0);
50595053 defer fetch_prog_node.end();
50605054
......@@ -5203,7 +5197,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
52035197 }
52045198 }
52055199 }
5206 }
5200 } else try createEmptyDependenciesModule(
5201 arena,
5202 root_mod,
5203 global_cache_directory,
5204 local_cache_directory,
5205 builtin_mod,
5206 config,
5207 );
52075208
52085209 try root_mod.deps.put(arena, "@build", build_mod);
52095210
......@@ -5269,7 +5270,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
52695270 if (code == 2) process.exit(2);
52705271
52715272 if (code == 3) {
5272 if (build_options.only_core_functionality) process.exit(3);
5273 if (!dev.env.supports(.fetch_command)) process.exit(3);
52735274 // Indicates the configure phase failed due to missing lazy
52745275 // dependencies and stdout contains the hashes of the ones
52755276 // that are missing.
......@@ -5346,6 +5347,8 @@ fn jitCmd(
53465347 args: []const []const u8,
53475348 options: JitCmdOptions,
53485349) !void {
5350 dev.check(.jit_command);
5351
53495352 const color: Color = .auto;
53505353 const root_prog_node = if (options.progress_node) |node| node else std.Progress.start(.{
53515354 .disable_printing = (color == .off),
......@@ -5995,6 +5998,8 @@ fn cmdAstCheck(
59955998 arena: Allocator,
59965999 args: []const []const u8,
59976000) !void {
6001 dev.check(.ast_check_command);
6002
59986003 const Zir = std.zig.Zir;
59996004
60006005 var color: Color = .auto;
......@@ -6154,6 +6159,8 @@ fn cmdDetectCpu(
61546159 arena: Allocator,
61556160 args: []const []const u8,
61566161) !void {
6162 dev.check(.detect_cpu_command);
6163
61576164 _ = gpa;
61586165 _ = arena;
61596166
......@@ -6293,6 +6300,8 @@ fn cmdDumpLlvmInts(
62936300 arena: Allocator,
62946301 args: []const []const u8,
62956302) !void {
6303 dev.check(.llvm_ints_command);
6304
62966305 _ = gpa;
62976306
62986307 if (!build_options.have_llvm)
......@@ -6336,6 +6345,8 @@ fn cmdDumpZir(
63366345 arena: Allocator,
63376346 args: []const []const u8,
63386347) !void {
6348 dev.check(.dump_zir_command);
6349
63396350 _ = arena;
63406351 const Zir = std.zig.Zir;
63416352
......@@ -6395,6 +6406,8 @@ fn cmdChangelist(
63956406 arena: Allocator,
63966407 args: []const []const u8,
63976408) !void {
6409 dev.check(.changelist_command);
6410
63986411 const color: Color = .auto;
63996412 const Zir = std.zig.Zir;
64006413
......@@ -6895,6 +6908,8 @@ fn cmdFetch(
68956908 arena: Allocator,
68966909 args: []const []const u8,
68976910) !void {
6911 dev.check(.fetch_command);
6912
68986913 const color: Color = .auto;
68996914 const work_around_btrfs_bug = native_os == .linux and
69006915 EnvVar.ZIG_BTRFS_WORKAROUND.isSet();
src/mingw.zig+3-1
......@@ -9,6 +9,7 @@ const builtin = @import("builtin");
99const Compilation = @import("Compilation.zig");
1010const build_options = @import("build_options");
1111const Cache = std.Build.Cache;
12const dev = @import("dev.zig");
1213
1314pub const CRTFile = enum {
1415 crt2_o,
......@@ -157,7 +158,8 @@ fn add_cc_args(
157158}
158159
159160pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void {
160 if (build_options.only_c) @compileError("building import libs not included in core functionality");
161 dev.check(.build_import_lib);
162
161163 var arena_allocator = std.heap.ArenaAllocator.init(comp.gpa);
162164 defer arena_allocator.deinit();
163165 const arena = arena_allocator.allocator();
stage1/config.zig.in+1-2
......@@ -12,5 +12,4 @@ pub const enable_tracy = false;
1212pub const value_tracing = false;
1313pub const skip_non_native = false;
1414pub const force_gpa = false;
15pub const only_c = false;
16pub const only_core_functionality = true;
15pub const dev = .core;