Skip to content

Commit 810f3f5

Browse files
committed
build system: follow-up enhancements regarding LazyPath
* introduce LazyPath.cwd_relative variant and use it for --zig-lib-dir. closes #12685 * move overrideZigLibDir and setMainPkgPath to options fields set once and then never mutated. * avoid introducing Build/util.zig * use doc comments for deprecation notices so that they show up in generated documentation. * introduce InstallArtifact.Options, accept it as a parameter to addInstallArtifact, and move override_dest_dir into it. Instead of configuring the installation via Compile step, configure the installation via the InstallArtifact step. In retrospect this is obvious. * remove calls to pushInstalledFile in InstallArtifact. See #14943 * rewrite InstallArtifact to not incorrectly observe whether a Compile step has any generated outputs. InstallArtifact is meant to trigger output generation. * fix child process evaluation code handling of `-fno-emit-bin`. * don't store out_h_filename, out_ll_filename, etc., pointlessly. these are all just simple extensions appended to the root name. * make emit_directory optional. It's possible to have nothing outputted, for example, if you're just type-checking. * avoid passing -femit-foo/-fno-emit-foo when it is the default * rename ConfigHeader.getTemplate to getOutput * deprecate addOptionArtifact * update the random number seed of Options step caching. * avoid using `inline for` pointlessly * avoid using `override_Dest_dir` pointlessly * avoid emitting an executable pointlessly in test cases * fix compiler_rt_panic test case warning about _start Removes forceBuild and forceEmit. Let's consider these additions separately. Nearly all of the usage sites were suspicious.
1 parent cc918f6 commit 810f3f5

File tree

29 files changed

+397
-388
lines changed

29 files changed

+397
-388
lines changed

build.zig

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ pub fn build(b: *std.Build) !void {
4545
const docgen_cmd = b.addRunArtifact(docgen_exe);
4646
docgen_cmd.addArgs(&.{ "--zig", b.zig_exe });
4747
if (b.zig_lib_dir) |p| {
48-
docgen_cmd.addArgs(&.{ "--zig-lib-dir", b.pathFromRoot(p) });
48+
docgen_cmd.addArg("--zig-lib-dir");
49+
docgen_cmd.addFileArg(p);
4950
}
5051
docgen_cmd.addFileArg(.{ .path = "doc/langref.html.in" });
5152
const langref_file = docgen_cmd.addOutputFileArg("langref.html");
@@ -57,8 +58,8 @@ pub fn build(b: *std.Build) !void {
5758
const autodoc_test = b.addTest(.{
5859
.root_source_file = .{ .path = "lib/std/std.zig" },
5960
.target = target,
61+
.zig_lib_dir = .{ .path = "lib" },
6062
});
61-
autodoc_test.overrideZigLibDir(.{ .path = "lib" });
6263
const install_std_docs = b.addInstallDirectory(.{
6364
.source_dir = autodoc_test.getEmittedDocs(),
6465
.install_dir = .prefix,
@@ -87,8 +88,8 @@ pub fn build(b: *std.Build) !void {
8788
.name = "check-case",
8889
.root_source_file = .{ .path = "test/src/Cases.zig" },
8990
.optimize = optimize,
91+
.main_pkg_path = .{ .path = "." },
9092
});
91-
check_case_exe.setMainPkgPath(.{ .path = "." });
9293
check_case_exe.stack_size = stack_size;
9394
check_case_exe.single_threaded = single_threaded;
9495

@@ -203,7 +204,7 @@ pub fn build(b: *std.Build) !void {
203204
);
204205

205206
if (!no_bin) {
206-
const install_exe = b.addInstallArtifact(exe);
207+
const install_exe = b.addInstallArtifact(exe, .{});
207208
if (flat) {
208209
install_exe.dest_dir = .prefix;
209210
}
@@ -357,8 +358,8 @@ pub fn build(b: *std.Build) !void {
357358
else
358359
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
359360

360-
exe.addIncludePath(.{ .path = tracy_path });
361-
exe.addCSourceFile(.{ .file = .{ .path = client_cpp }, .flags = tracy_c_flags });
361+
exe.addIncludePath(.{ .cwd_relative = tracy_path });
362+
exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags });
362363
if (!enable_llvm) {
363364
exe.linkSystemLibraryName("c++");
364365
}
@@ -597,7 +598,7 @@ fn addCmakeCfgOptionsToExe(
597598
// useful for package maintainers
598599
exe.headerpad_max_install_names = true;
599600
}
600-
exe.addObjectFile(.{ .path = b.pathJoin(&[_][]const u8{
601+
exe.addObjectFile(.{ .cwd_relative = b.pathJoin(&[_][]const u8{
601602
cfg.cmake_binary_dir,
602603
"zigcpp",
603604
b.fmt("{s}{s}{s}", .{
@@ -607,9 +608,9 @@ fn addCmakeCfgOptionsToExe(
607608
}),
608609
}) });
609610
assert(cfg.lld_include_dir.len != 0);
610-
exe.addIncludePath(.{ .path = cfg.lld_include_dir });
611-
exe.addIncludePath(.{ .path = cfg.llvm_include_dir });
612-
exe.addLibraryPath(.{ .path = cfg.llvm_lib_dir });
611+
exe.addIncludePath(.{ .cwd_relative = cfg.lld_include_dir });
612+
exe.addIncludePath(.{ .cwd_relative = cfg.llvm_include_dir });
613+
exe.addLibraryPath(.{ .cwd_relative = cfg.llvm_lib_dir });
613614
addCMakeLibraryList(exe, cfg.clang_libraries);
614615
addCMakeLibraryList(exe, cfg.lld_libraries);
615616
addCMakeLibraryList(exe, cfg.llvm_libraries);
@@ -665,7 +666,7 @@ fn addCmakeCfgOptionsToExe(
665666
}
666667

667668
if (cfg.dia_guids_lib.len != 0) {
668-
exe.addObjectFile(.{ .path = cfg.dia_guids_lib });
669+
exe.addObjectFile(.{ .cwd_relative = cfg.dia_guids_lib });
669670
}
670671
}
671672

@@ -726,7 +727,7 @@ fn addCxxKnownPath(
726727
}
727728
return error.RequiredLibraryNotFound;
728729
}
729-
exe.addObjectFile(.{ .path = path_unpadded });
730+
exe.addObjectFile(.{ .cwd_relative = path_unpadded });
730731

731732
// TODO a way to integrate with system c++ include files here
732733
// c++ -E -Wp,-v -xc++ /dev/null
@@ -746,7 +747,7 @@ fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void {
746747
} else if (exe.target.isWindows() and mem.endsWith(u8, lib, ".lib") and !fs.path.isAbsolute(lib)) {
747748
exe.linkSystemLibrary(lib[0 .. lib.len - ".lib".len]);
748749
} else {
749-
exe.addObjectFile(.{ .path = lib });
750+
exe.addObjectFile(.{ .cwd_relative = lib });
750751
}
751752
}
752753
}

lib/build_runner.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ pub fn main() !void {
188188
usageAndErr(builder, false, stderr_stream);
189189
};
190190
} else if (mem.eql(u8, arg, "--zig-lib-dir")) {
191-
builder.zig_lib_dir = nextArg(args, &arg_idx) orelse {
191+
builder.zig_lib_dir = .{ .cwd_relative = nextArg(args, &arg_idx) orelse {
192192
std.debug.print("Expected argument after {s}\n\n", .{arg});
193193
usageAndErr(builder, false, stderr_stream);
194-
};
194+
} };
195195
} else if (mem.eql(u8, arg, "--debug-log")) {
196196
const next_arg = nextArg(args, &arg_idx) orelse {
197197
std.debug.print("Expected argument after {s}\n\n", .{arg});

0 commit comments

Comments
 (0)