maker: progress towards updating zig CLI lowering

This commit is contained in:
Andrew Kelley
2026-02-26 20:33:59 -08:00
parent 56ec3614d9
commit 3962d87bb2
2 changed files with 85 additions and 21 deletions
+30 -20
View File
@@ -30,8 +30,8 @@ pub fn make(
const graph = maker.graph;
const step = maker.stepByIndex(step_index);
compile.zig_args.clearRetainingCapacity();
if (true) @panic("TODO implement compile.make()");
try lowerZigArgs(compile, step_index, maker, &compile.zig_args, false);
if (true) @panic("TODO implement compile.make()");
const process_arena = graph.arena; // TODO don't leak into the process_arena
const maybe_output_dir = step.evalZigProcess(
@@ -92,10 +92,13 @@ fn lowerZigArgs(
const graph = maker.graph;
const arena = graph.arena; // TODO don't leak into the process arena
const gpa = maker.gpa;
const conf = &maker.scanned_config.configuration;
const conf_step = step_index.ptr(conf);
const conf_comp = conf_step.extended.get(conf.extra).compile;
try zig_args.append(gpa, graph.zig_exe);
const cmd = switch (compile.kind) {
const cmd = switch (conf_comp.flags3.kind) {
.lib => "build-lib",
.exe => "build-exe",
.obj => "build-obj",
@@ -107,25 +110,32 @@ fn lowerZigArgs(
if (graph.reference_trace) |some| {
try zig_args.append(gpa, try allocPrint(arena, "-freference-trace={d}", .{some}));
}
try addFlag(&zig_args, "allow-so-scripts", compile.allow_so_scripts orelse graph.allow_so_scripts);
try addFlag(gpa, zig_args, "allow-so-scripts", conf_comp.flags2.allow_so_scripts.toBool() orelse graph.allow_so_scripts);
try addFlag(&zig_args, "llvm", compile.use_llvm);
try addFlag(&zig_args, "lld", compile.use_lld);
try addFlag(&zig_args, "new-linker", compile.use_new_linker);
try addFlag(gpa, zig_args, "llvm", conf_comp.flags2.use_llvm.toBool());
try addFlag(gpa, zig_args, "lld", conf_comp.flags2.use_lld.toBool());
try addFlag(gpa, zig_args, "new-linker", conf_comp.flags2.use_new_linker.toBool());
if (compile.root_module.resolved_target.?.query.ofmt) |ofmt| {
try zig_args.append(gpa, try allocPrint(arena, "-ofmt={t}", .{ofmt}));
const root_module = conf_comp.root_module.get(conf);
if (root_module.resolved_target.get(conf).?.query.unwrap()) |query| {
if (query.get(conf).flags.object_format.get()) |ofmt| {
try zig_args.append(gpa, try allocPrint(arena, "-ofmt={t}", .{ofmt}));
}
}
switch (compile.entry) {
switch (conf_comp.flags3.entry) {
.default => {},
.disabled => try zig_args.append(gpa, "-fno-entry"),
.enabled => try zig_args.append(gpa, "-fentry"),
.symbol_name => |entry_name| {
try zig_args.append(gpa, try allocPrint(arena, "-fentry={s}", .{entry_name}));
.symbol_name => {
const symbol_name = conf_comp.entry.value.?.slice(conf);
try zig_args.append(gpa, try allocPrint(arena, "-fentry={s}", .{symbol_name}));
},
}
if (true) @panic("TODO");
{
for (compile.force_undefined_symbols.keys()) |symbol_name| {
try zig_args.append(gpa, "--force_undefined");
@@ -408,7 +418,7 @@ fn lowerZigArgs(
if (!my_responsibility) continue;
if (cli_named_modules.modules.getIndex(mod)) |module_cli_index| {
const module_cli_name = cli_named_modules.names.keys()[module_cli_index];
try mod.appendZigProcessFlags(&zig_args, step);
try mod.appendZigProcessFlags(zig_args, step);
// --dep arguments
try zig_args.ensureUnusedCapacity(mod.import_table.count() * 2);
@@ -507,7 +517,7 @@ fn lowerZigArgs(
if (compile.generated_llvm_ir != null) try zig_args.append(gpa, "-femit-llvm-ir");
if (compile.generated_h != null) try zig_args.append(gpa, "-femit-h");
try addFlag(&zig_args, "formatted-panics", compile.formatted_panics);
try addFlag(gpa, zig_args, "formatted-panics", compile.formatted_panics);
switch (compile.compress_debug_sections) {
.none => {},
@@ -612,9 +622,9 @@ fn lowerZigArgs(
try zig_args.append(gpa, "--discard-all");
}
try addFlag(&zig_args, "compiler-rt", compile.bundle_compiler_rt);
try addFlag(&zig_args, "ubsan-rt", compile.bundle_ubsan_rt);
try addFlag(&zig_args, "dll-export-fns", compile.dll_export_fns);
try addFlag(gpa, zig_args, "compiler-rt", compile.bundle_compiler_rt);
try addFlag(gpa, zig_args, "ubsan-rt", compile.bundle_ubsan_rt);
try addFlag(gpa, zig_args, "dll-export-fns", compile.dll_export_fns);
if (compile.rdynamic) {
try zig_args.append(gpa, "-rdynamic");
}
@@ -718,7 +728,7 @@ fn lowerZigArgs(
try zig_args.appendSlice(gpa, &.{ "-rcincludes", @tagName(compile.rc_includes) });
}
try addFlag(&zig_args, "each-lib-rpath", compile.each_lib_rpath);
try addFlag(gpa, zig_args, "each-lib-rpath", compile.each_lib_rpath);
if (compile.build_id orelse graph.build_id) |build_id| {
try zig_args.append(gpa, switch (build_id) {
@@ -739,7 +749,7 @@ fn lowerZigArgs(
try zig_args.append(gpa, zig_lib_dir);
}
try addFlag(&zig_args, "PIE", compile.pie);
try addFlag(gpa, zig_args, "PIE", compile.pie);
if (compile.lto) |lto| {
try zig_args.append(gpa, switch (lto) {
@@ -749,7 +759,7 @@ fn lowerZigArgs(
});
}
try addFlag(&zig_args, "sanitize-coverage-trace-pc-guard", compile.sanitize_coverage_trace_pc_guard);
try addFlag(gpa, zig_args, "sanitize-coverage-trace-pc-guard", compile.sanitize_coverage_trace_pc_guard);
if (compile.subsystem) |subsystem| {
try zig_args.appendSlice(gpa, &.{ "--subsystem", @tagName(subsystem) });
@@ -763,7 +773,7 @@ fn lowerZigArgs(
"--error-limit", try allocPrint(arena, "{d}", .{err_limit}),
});
try addFlag(&zig_args, "incremental", graph.incremental);
try addFlag(gpa, zig_args, "incremental", graph.incremental);
try zig_args.append(gpa, "--listen=-");
+55 -1
View File
@@ -1147,6 +1147,10 @@ pub const Module = struct {
pub const Index = enum(u32) {
_,
pub fn get(this: @This(), c: *const Configuration) Module {
return extraData(c, Module, @intFromEnum(this));
}
};
pub const Flags = packed struct(u32) {
@@ -1318,6 +1322,14 @@ pub const DefaultingBool = enum(u2) {
true => .true,
};
}
pub fn toBool(db: DefaultingBool) ?bool {
return switch (db) {
.false => false,
.true => true,
.default => null,
};
}
};
pub const SystemLib = struct {
@@ -1431,11 +1443,26 @@ pub const ResolvedTarget = struct {
pub const Index = enum(u32) {
_,
pub fn get(this: @This(), c: *const Configuration) ?ResolvedTarget {
return extraData(c, ResolvedTarget, @intFromEnum(this));
}
};
pub const OptionalIndex = enum(u32) {
none = maxInt(u32),
_,
pub fn unwrap(this: @This()) ?Index {
return switch (this) {
.none => null,
_ => @enumFromInt(@intFromEnum(this)),
};
}
pub fn get(this: @This(), c: *const Configuration) ?ResolvedTarget {
return (unwrap(this) orelse return null).get(c);
}
};
};
@@ -1468,6 +1495,10 @@ pub const TargetQuery = struct {
pub fn length(i: Index, extra: []const u32) usize {
return Storage.dataLength(extra, @intFromEnum(i), TargetQuery);
}
pub fn get(this: @This(), c: *const Configuration) TargetQuery {
return extraData(c, TargetQuery, @intFromEnum(this));
}
};
pub const OptionalIndex = enum(u32) {
@@ -1479,6 +1510,13 @@ pub const TargetQuery = struct {
assert(result != .none);
return result;
}
pub fn unwrap(this: @This()) ?Index {
return switch (this) {
.none => null,
_ => @enumFromInt(@intFromEnum(this)),
};
}
};
pub const CpuModel = enum(u2) {
@@ -1680,6 +1718,22 @@ pub const TargetQuery = struct {
// TODO comptime assert the enums match
return @enumFromInt(@intFromEnum(x orelse return .default));
}
pub fn get(this: @This()) ?std.Target.ObjectFormat {
return switch (this) {
.c => .c,
.coff => .coff,
.elf => .elf,
.hex => .hex,
.macho => .macho,
.plan9 => .plan9,
.raw => .raw,
.spirv => .spirv,
.wasm => .wasm,
.default => null,
};
}
};
pub const Flags = packed struct(u32) {
@@ -1933,7 +1987,7 @@ pub const Storage = enum {
}
const end = meta_start + Field.extraLen(len);
i.* = end;
return .{ .data = end - len, .len = len };
return .{ .data = @ptrFromInt(end - len), .len = len };
},
},
},