From fe855691f6f742a14678cb617422977c2a55be39 Mon Sep 17 00:00:00 2001 From: mlugg Date: Wed, 21 May 2025 01:45:05 +0100 Subject: [PATCH 1/2] std.Build.Step.Run: inherit build runner cwd Right now, if you override the build root with `--build-root`, then `Run` steps can fail to execute because of incorrect path handling in the compiler: `std.process.Child` gets a cwd-relative path, but also has its cwd set to the build root. The latter behavior is really weird; it doesn't match my expectations, nor does it match how we spawn child `zig` processes. So, this commit makes the child process inherit the build runner's cwd, as `LazyPath.getPath2` *expects* it to. After investigating, this behavior dates all the way back to 2017; it was introduced in 4543413. So, there isn't any clear/documented reason for this; it should be safe to revert, since under the modern `LazyPath` system it is strictly a bug AFAICT. --- lib/std/Build/Step/Run.zig | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index eede464ab6..b7ad1307fb 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -1334,9 +1334,6 @@ fn spawnChildAndCollect( var child = std.process.Child.init(argv, arena); if (run.cwd) |lazy_cwd| { child.cwd = lazy_cwd.getPath2(b, &run.step); - } else { - child.cwd = b.build_root.path; - child.cwd_dir = b.build_root.handle; } child.env_map = run.env_map orelse &b.graph.env_map; child.request_resource_usage_statistics = true; From cdba1d591aae2f5ac5dcd5ae186f5696f218710c Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Tue, 20 May 2025 22:59:07 -0400 Subject: [PATCH 2/2] test-cli: port build options test to new build system API Since we need testing for passing `--build-file` and `--cache-dir` together anyway, use it to test the disabled build options test. --- test/standalone/options/build.zig | 2 +- test/tests.zig | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/test/standalone/options/build.zig b/test/standalone/options/build.zig index 07efea2a7b..5f1e496c4b 100644 --- a/test/standalone/options/build.zig +++ b/test/standalone/options/build.zig @@ -8,7 +8,7 @@ pub fn build(b: *std.Build) void { }) }); const options = b.addOptions(); - main.addOptions("build_options", options); + main.root_module.addOptions("build_options", options); options.addOption(bool, "bool_true", b.option(bool, "bool_true", "t").?); options.addOption(bool, "bool_false", b.option(bool, "bool_false", "f").?); options.addOption(u32, "int", b.option(u32, "int", "i").?); diff --git a/test/tests.zig b/test/tests.zig index 04c89444df..a25d3527c0 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -1657,16 +1657,23 @@ pub fn addCliTests(b: *std.Build) *Step { } { - // TODO this should move to become a CLI test rather than standalone - // cases.addBuildFile("test/standalone/options/build.zig", .{ - // .extra_argv = &.{ - // "-Dbool_true", - // "-Dbool_false=false", - // "-Dint=1234", - // "-De=two", - // "-Dstring=hello", - // }, - // }); + const run_test = b.addSystemCommand(&.{ + b.graph.zig_exe, + "build", + "test", + "-Dbool_true", + "-Dbool_false=false", + "-Dint=1234", + "-De=two", + "-Dstring=hello", + }); + run_test.addArg("--build-file"); + run_test.addFileArg(b.path("test/standalone/options/build.zig")); + run_test.addArg("--cache-dir"); + run_test.addFileArg(.{ .cwd_relative = b.cache_root.join(b.allocator, &.{}) catch @panic("OOM") }); + run_test.setName("test build options"); + + step.dependOn(&run_test.step); } return step;