From 52a3e7b7cd1dfe6f09f94f50c1edd7c231a111e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Mon, 8 Apr 2024 20:44:46 +0100 Subject: [PATCH 01/14] std.Build: rename `path` identifiers This frees up the `path` identifier for a container-scope function. --- lib/std/Build.zig | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 2c644ce4b031..a9aac995bd49 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -1674,9 +1674,9 @@ pub fn findProgram(self: *Build, names: []const []const u8, paths: []const []con return name; } var it = mem.tokenizeScalar(u8, PATH, fs.path.delimiter); - while (it.next()) |path| { + while (it.next()) |p| { const full_path = self.pathJoin(&.{ - path, + p, self.fmt("{s}{s}", .{ name, exe_extension }), }); return fs.realpathAlloc(self.allocator, full_path) catch continue; @@ -1687,9 +1687,9 @@ pub fn findProgram(self: *Build, names: []const []const u8, paths: []const []con if (fs.path.isAbsolute(name)) { return name; } - for (paths) |path| { + for (paths) |p| { const full_path = self.pathJoin(&.{ - path, + p, self.fmt("{s}{s}", .{ name, exe_extension }), }); return fs.realpathAlloc(self.allocator, full_path) catch continue; @@ -1771,7 +1771,7 @@ pub fn getInstallPath(self: *Build, dir: InstallDir, dest_rel_path: []const u8) .bin => self.exe_dir, .lib => self.lib_dir, .header => self.h_dir, - .custom => |path| self.pathJoin(&.{ self.install_path, path }), + .custom => |p| self.pathJoin(&.{ self.install_path, p }), }; return fs.path.resolve( self.allocator, @@ -2093,9 +2093,9 @@ pub const GeneratedFile = struct { // so that we can join it with another path (e.g. build root, cache root, etc.) // // dirname("") should still be null, because we can't go up any further. -fn dirnameAllowEmpty(path: []const u8) ?[]const u8 { - return fs.path.dirname(path) orelse { - if (fs.path.isAbsolute(path) or path.len == 0) return null; +fn dirnameAllowEmpty(p: []const u8) ?[]const u8 { + return fs.path.dirname(p) orelse { + if (fs.path.isAbsolute(p) or p.len == 0) return null; return ""; }; @@ -2152,9 +2152,9 @@ pub const LazyPath = union(enum) { /// Returns a new file source that will have a relative path to the build root guaranteed. /// Asserts the parameter is not an absolute path. - pub fn relative(path: []const u8) LazyPath { - std.debug.assert(!std.fs.path.isAbsolute(path)); - return LazyPath{ .path = path }; + pub fn relative(p: []const u8) LazyPath { + std.debug.assert(!std.fs.path.isAbsolute(p)); + return LazyPath{ .path = p }; } /// Returns a lazy path referring to the directory containing this path. @@ -2262,13 +2262,13 @@ pub const LazyPath = union(enum) { (src_builder.cache_root.join(src_builder.allocator, &.{"."}) catch @panic("OOM")); const gen_step = gen.generated.step; - var path = getPath2(LazyPath{ .generated = gen.generated }, src_builder, asking_step); + var p = getPath2(LazyPath{ .generated = gen.generated }, src_builder, asking_step); var i: usize = 0; while (i <= gen.up) : (i += 1) { // path is absolute. // dirname will return null only if we're at root. // Typically, we'll stop well before that at the cache root. - path = fs.path.dirname(path) orelse { + p = fs.path.dirname(p) orelse { dumpBadDirnameHelp(gen_step, asking_step, \\dirname() reached root. \\No more directories left to go up. @@ -2277,7 +2277,7 @@ pub const LazyPath = union(enum) { @panic("misconfigured build script"); }; - if (mem.eql(u8, path, cache_root_path) and i < gen.up) { + if (mem.eql(u8, p, cache_root_path) and i < gen.up) { // If we hit the cache root and there's still more to go, // the script attempted to go too far. dumpBadDirnameHelp(gen_step, asking_step, @@ -2288,7 +2288,7 @@ pub const LazyPath = union(enum) { @panic("misconfigured build script"); } } - return path; + return p; }, .dependency => |dep| { return dep.dependency.builder.pathJoin(&[_][]const u8{ From 2229967390c9bb054a7a62a49ae14711c928221f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Mon, 8 Apr 2024 20:58:43 +0100 Subject: [PATCH 02/14] std.Build: add `path*()` family of helper functions These functions let a std.Build construct a LazyPath. At the moment this is mostly pointless relative to the old way of doing things but once the internal structure of LazyPath changes it will make it significantly easier to make local changes without having to rewrite them everywhere else that uses a LazyPath. --- build.zig | 48 +++++++++---------- lib/compiler/build_runner.zig | 2 +- lib/init/build.zig | 8 ++-- lib/std/Build.zig | 20 ++++++-- lib/std/Build/Module.zig | 4 +- lib/std/Build/Step/Compile.zig | 6 +-- lib/std/Build/Step/ConfigHeader.zig | 2 +- lib/std/Build/Step/Options.zig | 2 +- lib/std/Build/Step/Run.zig | 12 ++--- lib/std/Build/Step/TranslateC.zig | 2 +- lib/std/Build/Step/WriteFile.zig | 6 +-- test/link/bss/build.zig | 2 +- test/link/common_symbols/build.zig | 2 +- test/link/common_symbols_alignment/build.zig | 2 +- test/link/glibc_compat/build.zig | 4 +- .../interdependent_static_c_libs/build.zig | 12 ++--- test/link/macho.zig | 6 +-- .../static_libs_from_object_files/build.zig | 6 +-- test/link/wasm/archive/build.zig | 2 +- test/link/wasm/basic-features/build.zig | 2 +- test/link/wasm/bss/build.zig | 4 +- test/link/wasm/export-data/build.zig | 2 +- test/link/wasm/export/build.zig | 6 +-- test/link/wasm/extern-mangle/build.zig | 2 +- test/link/wasm/extern/build.zig | 4 +- test/link/wasm/function-table/build.zig | 6 +-- test/link/wasm/infer-features/build.zig | 4 +- test/link/wasm/producers/build.zig | 2 +- test/link/wasm/segments/build.zig | 2 +- test/link/wasm/shared-memory/build.zig | 2 +- test/link/wasm/stack_pointer/build.zig | 2 +- test/link/wasm/type/build.zig | 2 +- test/standalone/build.zig | 2 +- test/standalone/c_compiler/build.zig | 4 +- test/standalone/child_process/build.zig | 4 +- test/standalone/cmakedefine/build.zig | 10 ++-- test/standalone/coff_dwarf/build.zig | 4 +- test/standalone/compiler_rt_panic/build.zig | 2 +- test/standalone/dep_diamond/build.zig | 8 ++-- .../dep_mutually_recursive/build.zig | 6 +-- test/standalone/dep_recursive/build.zig | 4 +- test/standalone/dep_shared_builtin/build.zig | 4 +- test/standalone/dep_triangle/build.zig | 6 +-- test/standalone/depend_on_main_mod/build.zig | 4 +- test/standalone/dirname/build.zig | 10 ++-- .../standalone/embed_generated_file/build.zig | 4 +- test/standalone/emit_asm_and_bin/build.zig | 2 +- test/standalone/empty_env/build.zig | 2 +- test/standalone/extern/build.zig | 4 +- test/standalone/global_linkage/build.zig | 6 +-- test/standalone/install_headers/build.zig | 6 +-- test/standalone/install_raw_hex/build.zig | 2 +- test/standalone/ios/build.zig | 8 ++-- test/standalone/issue_11595/build.zig | 2 +- test/standalone/issue_12588/build.zig | 2 +- test/standalone/issue_12706/build.zig | 2 +- test/standalone/issue_13970/build.zig | 6 +-- test/standalone/issue_339/build.zig | 2 +- test/standalone/issue_5825/build.zig | 2 +- test/standalone/issue_794/build.zig | 4 +- test/standalone/issue_8550/build.zig | 6 +-- .../standalone/load_dynamic_library/build.zig | 4 +- test/standalone/mix_c_files/build.zig | 4 +- test/standalone/mix_o_files/build.zig | 4 +- test/standalone/options/build.zig | 2 +- test/standalone/pie/build.zig | 2 +- test/standalone/pkg_import/build.zig | 4 +- test/standalone/self_exe_symlink/build.zig | 4 +- test/standalone/shared_library/build.zig | 4 +- test/standalone/sigpipe/build.zig | 2 +- test/standalone/simple/build.zig | 4 +- test/standalone/stack_iterator/build.zig | 8 ++-- test/standalone/static_c_lib/build.zig | 8 ++-- test/standalone/strip_empty_loop/build.zig | 2 +- test/standalone/strip_struct_init/build.zig | 2 +- .../test_runner_module_imports/build.zig | 6 +-- test/standalone/test_runner_path/build.zig | 2 +- test/standalone/use_alias/build.zig | 4 +- .../standalone/windows_entry_points/build.zig | 8 ++-- test/standalone/windows_resources/build.zig | 4 +- test/standalone/windows_spawn/build.zig | 4 +- test/standalone/zerolength_check/build.zig | 2 +- test/tests.zig | 36 +++++++------- 83 files changed, 224 insertions(+), 212 deletions(-) diff --git a/build.zig b/build.zig index 21059abd3c80..3dd7295c073e 100644 --- a/build.zig +++ b/build.zig @@ -34,7 +34,7 @@ pub fn build(b: *std.Build) !void { const docgen_exe = b.addExecutable(.{ .name = "docgen", - .root_source_file = .{ .path = "tools/docgen.zig" }, + .root_source_file = b.path("tools/docgen.zig"), .target = b.host, .optimize = .Debug, .single_threaded = single_threaded, @@ -46,7 +46,7 @@ pub fn build(b: *std.Build) !void { docgen_cmd.addArg("--zig-lib-dir"); docgen_cmd.addDirectoryArg(p); } - docgen_cmd.addFileArg(.{ .path = "doc/langref.html.in" }); + docgen_cmd.addFileArg(b.path("doc/langref.html.in")); const langref_file = docgen_cmd.addOutputFileArg("langref.html"); const install_langref = b.addInstallFileWithDir(langref_file, .prefix, "doc/langref.html"); if (!skip_install_langref) { @@ -55,9 +55,9 @@ pub fn build(b: *std.Build) !void { const autodoc_test = b.addObject(.{ .name = "std", - .root_source_file = .{ .path = "lib/std/std.zig" }, + .root_source_file = b.path("lib/std/std.zig"), .target = target, - .zig_lib_dir = .{ .path = "lib" }, + .zig_lib_dir = b.path("lib"), .optimize = .Debug, }); const install_std_docs = b.addInstallDirectory(.{ @@ -86,7 +86,7 @@ pub fn build(b: *std.Build) !void { const check_case_exe = b.addExecutable(.{ .name = "check-case", - .root_source_file = .{ .path = "test/src/Cases.zig" }, + .root_source_file = b.path("test/src/Cases.zig"), .target = b.host, .optimize = optimize, .single_threaded = single_threaded, @@ -135,7 +135,7 @@ pub fn build(b: *std.Build) !void { if (!skip_install_lib_files) { b.installDirectory(.{ - .source_dir = .{ .path = "lib" }, + .source_dir = b.path("lib"), .install_dir = if (flat) .prefix else .lib, .install_subdir = if (flat) "lib" else "zig", .exclude_extensions = &[_][]const u8{ @@ -377,8 +377,8 @@ pub fn build(b: *std.Build) !void { else &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; - exe.addIncludePath(.{ .cwd_relative = tracy_path }); - exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags }); + exe.addIncludePath(b.pathCwd(tracy_path)); + exe.addCSourceFile(.{ .file = b.pathCwd(client_cpp), .flags = tracy_c_flags }); if (!enable_llvm) { exe.root_module.linkSystemLibrary("c++", .{ .use_pkg_config = .no }); } @@ -552,12 +552,12 @@ pub fn build(b: *std.Build) !void { const update_mingw_exe = b.addExecutable(.{ .name = "update_mingw", .target = b.host, - .root_source_file = .{ .path = "tools/update_mingw.zig" }, + .root_source_file = b.path("tools/update_mingw.zig"), }); const update_mingw_run = b.addRunArtifact(update_mingw_exe); - update_mingw_run.addDirectoryArg(.{ .path = "lib" }); + update_mingw_run.addDirectoryArg(b.path("lib")); if (opt_mingw_src_path) |mingw_src_path| { - update_mingw_run.addDirectoryArg(.{ .cwd_relative = mingw_src_path }); + update_mingw_run.addDirectoryArg(b.pathCwd(mingw_src_path)); } else { // Intentionally cause an error if this build step is requested. update_mingw_run.addArg("--missing-mingw-source-directory"); @@ -606,10 +606,10 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { }); run_opt.addArtifactArg(exe); run_opt.addArg("-o"); - run_opt.addFileArg(.{ .path = "stage1/zig1.wasm" }); + run_opt.addFileArg(b.path("stage1/zig1.wasm")); const copy_zig_h = b.addWriteFiles(); - copy_zig_h.addCopyFileToSource(.{ .path = "lib/zig.h" }, "stage1/zig.h"); + copy_zig_h.addCopyFileToSource(b.path("lib/zig.h"), "stage1/zig.h"); const update_zig1_step = b.step("update-zig1", "Update stage1/zig1.wasm"); update_zig1_step.dependOn(&run_opt.step); @@ -627,7 +627,7 @@ const AddCompilerStepOptions = struct { fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.Step.Compile { const exe = b.addExecutable(.{ .name = "zig", - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = options.target, .optimize = options.optimize, .max_rss = 7_000_000_000, @@ -638,11 +638,11 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St exe.stack_size = stack_size; const aro_module = b.createModule(.{ - .root_source_file = .{ .path = "lib/compiler/aro/aro.zig" }, + .root_source_file = b.path("lib/compiler/aro/aro.zig"), }); const aro_translate_c_module = b.createModule(.{ - .root_source_file = .{ .path = "lib/compiler/aro_translate_c.zig" }, + .root_source_file = b.path("lib/compiler/aro_translate_c.zig"), .imports = &.{ .{ .name = "aro", @@ -680,7 +680,7 @@ fn addCmakeCfgOptionsToExe( // useful for package maintainers exe.headerpad_max_install_names = true; } - exe.addObjectFile(.{ .cwd_relative = b.pathJoin(&[_][]const u8{ + exe.addObjectFile(b.pathCwd(b.pathJoin(&[_][]const u8{ cfg.cmake_binary_dir, "zigcpp", b.fmt("{s}{s}{s}", .{ @@ -688,11 +688,11 @@ fn addCmakeCfgOptionsToExe( "zigcpp", cfg.cmake_static_library_suffix, }), - }) }); + }))); assert(cfg.lld_include_dir.len != 0); - exe.addIncludePath(.{ .cwd_relative = cfg.lld_include_dir }); - exe.addIncludePath(.{ .cwd_relative = cfg.llvm_include_dir }); - exe.addLibraryPath(.{ .cwd_relative = cfg.llvm_lib_dir }); + exe.addIncludePath(b.pathCwd(cfg.lld_include_dir)); + exe.addIncludePath(b.pathCwd(cfg.llvm_include_dir)); + exe.addLibraryPath(b.pathCwd(cfg.llvm_lib_dir)); addCMakeLibraryList(exe, cfg.clang_libraries); addCMakeLibraryList(exe, cfg.lld_libraries); addCMakeLibraryList(exe, cfg.llvm_libraries); @@ -755,7 +755,7 @@ fn addCmakeCfgOptionsToExe( } if (cfg.dia_guids_lib.len != 0) { - exe.addObjectFile(.{ .cwd_relative = cfg.dia_guids_lib }); + exe.addObjectFile(b.pathCwd(cfg.dia_guids_lib)); } } @@ -827,7 +827,7 @@ fn addCxxKnownPath( } return error.RequiredLibraryNotFound; } - exe.addObjectFile(.{ .cwd_relative = path_unpadded }); + exe.addObjectFile(b.pathCwd(path_unpadded)); // TODO a way to integrate with system c++ include files here // c++ -E -Wp,-v -xc++ /dev/null @@ -849,7 +849,7 @@ fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void { { exe.linkSystemLibrary(lib[0 .. lib.len - ".lib".len]); } else { - exe.addObjectFile(.{ .cwd_relative = lib }); + exe.addObjectFile(exe.step.owner.pathCwd(lib)); } } } diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig index eb5f52ab4473..6e1a9b8c2480 100644 --- a/lib/compiler/build_runner.zig +++ b/lib/compiler/build_runner.zig @@ -188,7 +188,7 @@ pub fn main() !void { }); }; } else if (mem.eql(u8, arg, "--zig-lib-dir")) { - builder.zig_lib_dir = .{ .cwd_relative = nextArgOrFatal(args, &arg_idx) }; + builder.zig_lib_dir = builder.pathCwd(nextArgOrFatal(args, &arg_idx)); } else if (mem.eql(u8, arg, "--seed")) { const next_arg = nextArg(args, &arg_idx) orelse fatalWithHint("expected u32 after '{s}'", .{arg}); diff --git a/lib/init/build.zig b/lib/init/build.zig index e513acdf254e..d53cbbb982c3 100644 --- a/lib/init/build.zig +++ b/lib/init/build.zig @@ -19,7 +19,7 @@ pub fn build(b: *std.Build) void { .name = "$", // In this case the main source file is merely a path, however, in more // complicated build scripts, this could be a generated file. - .root_source_file = .{ .path = "src/root.zig" }, + .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, }); @@ -31,7 +31,7 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "$", - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); @@ -67,7 +67,7 @@ pub fn build(b: *std.Build) void { // Creates a step for unit testing. This only builds the test executable // but does not run it. const lib_unit_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/root.zig" }, + .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, }); @@ -75,7 +75,7 @@ pub fn build(b: *std.Build) void { const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); const exe_unit_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); diff --git a/lib/std/Build.zig b/lib/std/Build.zig index a9aac995bd49..af924fed02d9 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -1547,7 +1547,7 @@ pub fn addInstallArtifact( ///`dest_rel_path` is relative to prefix path pub fn installFile(self: *Build, src_path: []const u8, dest_rel_path: []const u8) void { - self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .prefix, dest_rel_path).step); + self.getInstallStep().dependOn(&self.addInstallFileWithDir(self.path(src_path), .prefix, dest_rel_path).step); } pub fn installDirectory(self: *Build, options: Step.InstallDir.Options) void { @@ -1556,12 +1556,12 @@ pub fn installDirectory(self: *Build, options: Step.InstallDir.Options) void { ///`dest_rel_path` is relative to bin path pub fn installBinFile(self: *Build, src_path: []const u8, dest_rel_path: []const u8) void { - self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .bin, dest_rel_path).step); + self.getInstallStep().dependOn(&self.addInstallFileWithDir(self.path(src_path), .bin, dest_rel_path).step); } ///`dest_rel_path` is relative to lib path pub fn installLibFile(self: *Build, src_path: []const u8, dest_rel_path: []const u8) void { - self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .lib, dest_rel_path).step); + self.getInstallStep().dependOn(&self.addInstallFileWithDir(self.path(src_path), .lib, dest_rel_path).step); } pub fn addObjCopy(b: *Build, source: LazyPath, options: Step.ObjCopy.Options) *Step.ObjCopy { @@ -2085,6 +2085,20 @@ pub const GeneratedFile = struct { } }; +pub fn path(b: *Build, p: []const u8) LazyPath { + // TODO: absolute paths + return .{ .path = b.dupePath(p) }; +} + +pub fn pathCwd(b: *Build, p: []const u8) LazyPath { + // TODO: absolute paths? + return .{ .cwd_relative = b.dupePath(p) }; +} + +pub fn pathGenerated(_: *Build, g: *const GeneratedFile) LazyPath { + return .{ .generated = g }; +} + // dirnameAllowEmpty is a variant of fs.path.dirname // that allows "" to refer to the root for relative paths. // diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig index 02386de4308f..41e83bfb66d3 100644 --- a/lib/std/Build/Module.zig +++ b/lib/std/Build/Module.zig @@ -451,7 +451,7 @@ pub fn linkFramework(m: *Module, name: []const u8, options: LinkFrameworkOptions pub const AddCSourceFilesOptions = struct { /// When provided, `files` are relative to `root` rather than the /// package that owns the `Compile` step. - root: LazyPath = .{ .path = "" }, + root: ?LazyPath = null, files: []const []const u8, flags: []const []const u8 = &.{}, }; @@ -472,7 +472,7 @@ pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void { const c_source_files = allocator.create(CSourceFiles) catch @panic("OOM"); c_source_files.* = .{ - .root = options.root, + .root = options.root orelse m.owner.path("."), .files = b.dupeStrings(options.files), .flags = b.dupeStrings(options.flags), }; diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 4a5364176aab..3b081112662d 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -313,7 +313,7 @@ pub const HeaderInstallation = union(enum) { // If/when the build-root relative paths are updated to encode which build root they are // relative to, this workaround should be removed. const duped_source: LazyPath = switch (self.source) { - .path => |root_rel| .{ .cwd_relative = b.pathFromRoot(root_rel) }, + .path => |root_rel| b.pathCwd(b.pathFromRoot(root_rel)), else => self.source.dupe(b), }; @@ -830,13 +830,13 @@ pub fn setLibCFile(self: *Compile, libc_file: ?LazyPath) void { fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath { if (output_file.*) |g| { - return .{ .generated = g }; + return self.step.owner.pathGenerated(g); } const arena = self.step.owner.allocator; const generated_file = arena.create(GeneratedFile) catch @panic("OOM"); generated_file.* = .{ .step = &self.step }; output_file.* = generated_file; - return .{ .generated = generated_file }; + return self.step.owner.pathGenerated(generated_file); } /// Returns the path to the directory that contains the emitted binary file. diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig index 46631cac24a4..b38908550a8e 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -105,7 +105,7 @@ pub fn addValues(self: *ConfigHeader, values: anytype) void { } pub fn getOutput(self: *ConfigHeader) std.Build.LazyPath { - return .{ .generated = &self.output_file }; + return self.step.owner.pathGenerated(&self.output_file); } fn addValuesInner(self: *ConfigHeader, values: anytype) !void { diff --git a/lib/std/Build/Step/Options.zig b/lib/std/Build/Step/Options.zig index 178e2c3b96f3..3e0ce4970358 100644 --- a/lib/std/Build/Step/Options.zig +++ b/lib/std/Build/Step/Options.zig @@ -407,7 +407,7 @@ pub const getSource = getOutput; /// Returns the main artifact of this Build Step which is a Zig source file /// generated from the key-value pairs of the Options. pub fn getOutput(self: *Options) LazyPath { - return .{ .generated = &self.generated_file }; + return self.step.owner.pathGenerated(&self.generated_file); } fn make(step: *Step, prog_node: *std.Progress.Node) !void { diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index b3550624fc6d..7e608cc4fb63 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -213,7 +213,7 @@ pub fn addPrefixedOutputFileArg( self.setName(b.fmt("{s} ({s})", .{ self.step.name, basename })); } - return .{ .generated = &output.generated_file }; + return self.step.owner.pathGenerated(&output.generated_file); } /// Appends an input file to the command line arguments. @@ -299,7 +299,7 @@ pub fn addPrefixedDepFileOutputArg(self: *Run, prefix: []const u8, basename: []c self.argv.append(.{ .output = dep_file }) catch @panic("OOM"); - return .{ .generated = &dep_file.generated_file }; + return self.step.pathGenerated(&dep_file.generated_file); } pub fn addArg(self: *Run, arg: []const u8) void { @@ -414,7 +414,7 @@ pub fn addCheck(self: *Run, new_check: StdIo.Check) void { pub fn captureStdErr(self: *Run) std.Build.LazyPath { assert(self.stdio != .inherit); - if (self.captured_stderr) |output| return .{ .generated = &output.generated_file }; + if (self.captured_stderr) |output| return self.step.owner.pathGenerated(&output.generated_file); const output = self.step.owner.allocator.create(Output) catch @panic("OOM"); output.* = .{ @@ -423,13 +423,13 @@ pub fn captureStdErr(self: *Run) std.Build.LazyPath { .generated_file = .{ .step = &self.step }, }; self.captured_stderr = output; - return .{ .generated = &output.generated_file }; + return self.step.owner.pathGenerated(&output.generated_file); } pub fn captureStdOut(self: *Run) std.Build.LazyPath { assert(self.stdio != .inherit); - if (self.captured_stdout) |output| return .{ .generated = &output.generated_file }; + if (self.captured_stdout) |output| return self.step.owner.pathGenerated(&output.generated_file); const output = self.step.owner.allocator.create(Output) catch @panic("OOM"); output.* = .{ @@ -438,7 +438,7 @@ pub fn captureStdOut(self: *Run) std.Build.LazyPath { .generated_file = .{ .step = &self.step }, }; self.captured_stdout = output; - return .{ .generated = &output.generated_file }; + return self.step.owner.pathGenerated(&output.generated_file); } /// Returns whether the Run step has side effects *other than* updating the output arguments. diff --git a/lib/std/Build/Step/TranslateC.zig b/lib/std/Build/Step/TranslateC.zig index ac421a67cad5..a2307c4b37cd 100644 --- a/lib/std/Build/Step/TranslateC.zig +++ b/lib/std/Build/Step/TranslateC.zig @@ -59,7 +59,7 @@ pub const AddExecutableOptions = struct { }; pub fn getOutput(self: *TranslateC) std.Build.LazyPath { - return .{ .generated = &self.output_file }; + return self.step.owner.pathGenerated(&self.output_file); } /// Creates a step to build an executable from the translated source. diff --git a/lib/std/Build/Step/WriteFile.zig b/lib/std/Build/Step/WriteFile.zig index 310decdfe757..166c762c7e18 100644 --- a/lib/std/Build/Step/WriteFile.zig +++ b/lib/std/Build/Step/WriteFile.zig @@ -31,7 +31,7 @@ pub const File = struct { contents: Contents, pub fn getPath(self: *File) std.Build.LazyPath { - return .{ .generated = &self.generated_file }; + return self.generated_file.step.owner.pathGenerated(&self.generated_file); } }; @@ -58,7 +58,7 @@ pub const Directory = struct { }; pub fn getPath(self: *Directory) std.Build.LazyPath { - return .{ .generated = &self.generated_dir }; + return self.generated_dir.step.owner.pathGenerated(&self.generated_dir); } }; @@ -181,7 +181,7 @@ pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8) /// Returns a `LazyPath` representing the base directory that contains all the /// files from this `WriteFile`. pub fn getDirectory(wf: *WriteFile) std.Build.LazyPath { - return .{ .generated = &wf.generated_directory }; + return wf.step.owner.pathGenerated(&wf.generated_directory); } fn maybeUpdateName(wf: *WriteFile) void { diff --git a/test/link/bss/build.zig b/test/link/bss/build.zig index 865af0a4889f..cbe913781caf 100644 --- a/test/link/bss/build.zig +++ b/test/link/bss/build.zig @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "bss", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .target = b.host, .optimize = .Debug, }); diff --git a/test/link/common_symbols/build.zig b/test/link/common_symbols/build.zig index 9b5c9da66292..dd093a891a14 100644 --- a/test/link/common_symbols/build.zig +++ b/test/link/common_symbols/build.zig @@ -22,7 +22,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize }); const test_exe = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, }); test_exe.linkLibrary(lib_a); diff --git a/test/link/common_symbols_alignment/build.zig b/test/link/common_symbols_alignment/build.zig index 63aff339a976..7e732762ef8a 100644 --- a/test/link/common_symbols_alignment/build.zig +++ b/test/link/common_symbols_alignment/build.zig @@ -22,7 +22,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize }); const test_exe = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, }); test_exe.linkLibrary(lib_a); diff --git a/test/link/glibc_compat/build.zig b/test/link/glibc_compat/build.zig index e0cc1a70d81f..67a58200c3cc 100644 --- a/test/link/glibc_compat/build.zig +++ b/test/link/glibc_compat/build.zig @@ -21,7 +21,7 @@ pub fn build(b: *std.Build) void { .{ .arch_os_abi = t }, ) catch unreachable), }); - exe.addCSourceFile(.{ .file = .{ .path = "main.c" } }); + exe.addCSourceFile(.{ .file = b.path("main.c") }); exe.linkLibC(); // TODO: actually test the output _ = exe.getEmittedBin(); @@ -45,7 +45,7 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = t, - .root_source_file = .{ .path = "glibc_runtime_check.zig" }, + .root_source_file = b.path("glibc_runtime_check.zig"), .target = target, }); exe.linkLibC(); diff --git a/test/link/interdependent_static_c_libs/build.zig b/test/link/interdependent_static_c_libs/build.zig index 01ed218cce3f..7b84235b0c1e 100644 --- a/test/link/interdependent_static_c_libs/build.zig +++ b/test/link/interdependent_static_c_libs/build.zig @@ -16,24 +16,24 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize .optimize = optimize, .target = b.host, }); - lib_a.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &[_][]const u8{} }); - lib_a.addIncludePath(.{ .path = "." }); + lib_a.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} }); + lib_a.addIncludePath(b.path(".")); const lib_b = b.addStaticLibrary(.{ .name = "b", .optimize = optimize, .target = b.host, }); - lib_b.addCSourceFile(.{ .file = .{ .path = "b.c" }, .flags = &[_][]const u8{} }); - lib_b.addIncludePath(.{ .path = "." }); + lib_b.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} }); + lib_b.addIncludePath(b.path(".")); const test_exe = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, }); test_exe.linkLibrary(lib_a); test_exe.linkLibrary(lib_b); - test_exe.addIncludePath(.{ .path = "." }); + test_exe.addIncludePath(b.path(".")); test_step.dependOn(&b.addRunArtifact(test_exe).step); } diff --git a/test/link/macho.zig b/test/link/macho.zig index 9e91e14da379..4fc6f1b5f1b6 100644 --- a/test/link/macho.zig +++ b/test/link/macho.zig @@ -836,9 +836,9 @@ fn testLinkDirectlyCppTbd(b: *Build, opts: Options) *Step { , .cpp_source_flags = &.{ "-nostdlib++", "-nostdinc++" }, }); - exe.root_module.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include" }) }); - exe.root_module.addIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include/c++/v1" }) }); - exe.root_module.addObjectFile(.{ .path = b.pathJoin(&.{ sdk, "/usr/lib/libc++.tbd" }) }); + exe.root_module.addSystemIncludePath(b.path(b.pathJoin(&.{ sdk, "/usr/include" }))); + exe.root_module.addIncludePath(b.path(b.pathJoin(&.{ sdk, "/usr/include/c++/v1" }))); + exe.root_module.addObjectFile(b.path(b.pathJoin(&.{ sdk, "/usr/lib/libc++.tbd" }))); const check = exe.checkObject(); check.checkInSymtab(); diff --git a/test/link/static_libs_from_object_files/build.zig b/test/link/static_libs_from_object_files/build.zig index d0ea78bbd66c..dd679e7ef809 100644 --- a/test/link/static_libs_from_object_files/build.zig +++ b/test/link/static_libs_from_object_files/build.zig @@ -57,7 +57,7 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built { const exe = b.addExecutable(.{ .name = "test1", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = b.host, }); @@ -93,7 +93,7 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built const exe = b.addExecutable(.{ .name = "test2", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .target = b.host, .optimize = optimize, }); @@ -134,7 +134,7 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built const exe = b.addExecutable(.{ .name = "test3", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .target = b.host, .optimize = optimize, }); diff --git a/test/link/wasm/archive/build.zig b/test/link/wasm/archive/build.zig index cd91feae65dd..34c5818ad88b 100644 --- a/test/link/wasm/archive/build.zig +++ b/test/link/wasm/archive/build.zig @@ -17,7 +17,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize // and therefore link with its archive file. const lib = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .strip = false, diff --git a/test/link/wasm/basic-features/build.zig b/test/link/wasm/basic-features/build.zig index 6f9e82d09df3..87355a5c1288 100644 --- a/test/link/wasm/basic-features/build.zig +++ b/test/link/wasm/basic-features/build.zig @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { // Library with explicitly set cpu features const lib = b.addExecutable(.{ .name = "lib", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = .Debug, .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, diff --git a/test/link/wasm/bss/build.zig b/test/link/wasm/bss/build.zig index 3a1592f394d5..dc7d1bae4b9a 100644 --- a/test/link/wasm/bss/build.zig +++ b/test/link/wasm/bss/build.zig @@ -16,7 +16,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt { const lib = b.addExecutable(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .root_source_file = b.path("lib.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .optimize = optimize_mode, .strip = false, @@ -64,7 +64,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt { const lib = b.addExecutable(.{ .name = "lib", - .root_source_file = .{ .path = "lib2.zig" }, + .root_source_file = b.path("lib2.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .optimize = optimize_mode, .strip = false, diff --git a/test/link/wasm/export-data/build.zig b/test/link/wasm/export-data/build.zig index 05b2ca161bbf..7e3c5e584139 100644 --- a/test/link/wasm/export-data/build.zig +++ b/test/link/wasm/export-data/build.zig @@ -11,7 +11,7 @@ pub fn build(b: *std.Build) void { const lib = b.addExecutable(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .root_source_file = b.path("lib.zig"), .optimize = .ReleaseSafe, // to make the output deterministic in address positions .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), }); diff --git a/test/link/wasm/export/build.zig b/test/link/wasm/export/build.zig index ab2893ce3c6a..368826843a6c 100644 --- a/test/link/wasm/export/build.zig +++ b/test/link/wasm/export/build.zig @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const no_export = b.addExecutable(.{ .name = "no-export", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), }); @@ -25,7 +25,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize const dynamic_export = b.addExecutable(.{ .name = "dynamic", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), }); @@ -36,7 +36,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize const force_export = b.addExecutable(.{ .name = "force", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), }); diff --git a/test/link/wasm/extern-mangle/build.zig b/test/link/wasm/extern-mangle/build.zig index 41a00eefc97d..5a4cbc1cdae3 100644 --- a/test/link/wasm/extern-mangle/build.zig +++ b/test/link/wasm/extern-mangle/build.zig @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const lib = b.addExecutable(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .root_source_file = b.path("lib.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .optimize = optimize, }); diff --git a/test/link/wasm/extern/build.zig b/test/link/wasm/extern/build.zig index baa2b6d61e81..77dcbc47c51c 100644 --- a/test/link/wasm/extern/build.zig +++ b/test/link/wasm/extern/build.zig @@ -15,11 +15,11 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const exe = b.addExecutable(.{ .name = "extern", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }), }); - exe.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &.{} }); + exe.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} }); exe.use_llvm = false; exe.use_lld = false; diff --git a/test/link/wasm/function-table/build.zig b/test/link/wasm/function-table/build.zig index aca66e4f7157..3042ddf5d55e 100644 --- a/test/link/wasm/function-table/build.zig +++ b/test/link/wasm/function-table/build.zig @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const import_table = b.addExecutable(.{ .name = "import_table", - .root_source_file = .{ .path = "lib.zig" }, + .root_source_file = b.path("lib.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .optimize = optimize, }); @@ -27,7 +27,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize const export_table = b.addExecutable(.{ .name = "export_table", - .root_source_file = .{ .path = "lib.zig" }, + .root_source_file = b.path("lib.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .optimize = optimize, }); @@ -39,7 +39,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize const regular_table = b.addExecutable(.{ .name = "regular_table", - .root_source_file = .{ .path = "lib.zig" }, + .root_source_file = b.path("lib.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .optimize = optimize, }); diff --git a/test/link/wasm/infer-features/build.zig b/test/link/wasm/infer-features/build.zig index e3fe860f5406..e72e3934f75b 100644 --- a/test/link/wasm/infer-features/build.zig +++ b/test/link/wasm/infer-features/build.zig @@ -13,13 +13,13 @@ pub fn build(b: *std.Build) void { .os_tag = .freestanding, }), }); - c_obj.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &.{} }); + c_obj.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} }); // Wasm library that doesn't have any features specified. This will // infer its featureset from other linked object files. const lib = b.addExecutable(.{ .name = "lib", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = .Debug, .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, diff --git a/test/link/wasm/producers/build.zig b/test/link/wasm/producers/build.zig index 4fb777e1232d..2dae6e3f9bd1 100644 --- a/test/link/wasm/producers/build.zig +++ b/test/link/wasm/producers/build.zig @@ -16,7 +16,7 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const lib = b.addExecutable(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .root_source_file = b.path("lib.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .optimize = optimize, .strip = false, diff --git a/test/link/wasm/segments/build.zig b/test/link/wasm/segments/build.zig index 86073ff9770d..3c8bac3f0730 100644 --- a/test/link/wasm/segments/build.zig +++ b/test/link/wasm/segments/build.zig @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const lib = b.addExecutable(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .root_source_file = b.path("lib.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .optimize = optimize, .strip = false, diff --git a/test/link/wasm/shared-memory/build.zig b/test/link/wasm/shared-memory/build.zig index 0cad2560cbe6..7807a95a4fc4 100644 --- a/test/link/wasm/shared-memory/build.zig +++ b/test/link/wasm/shared-memory/build.zig @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode) void { const exe = b.addExecutable(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .root_source_file = b.path("lib.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp }, diff --git a/test/link/wasm/stack_pointer/build.zig b/test/link/wasm/stack_pointer/build.zig index e95c27827ed0..e42e36288001 100644 --- a/test/link/wasm/stack_pointer/build.zig +++ b/test/link/wasm/stack_pointer/build.zig @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const lib = b.addExecutable(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .root_source_file = b.path("lib.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .optimize = optimize, .strip = false, diff --git a/test/link/wasm/type/build.zig b/test/link/wasm/type/build.zig index b62886c74eb3..46b80dbfe5dc 100644 --- a/test/link/wasm/type/build.zig +++ b/test/link/wasm/type/build.zig @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const exe = b.addExecutable(.{ .name = "lib", - .root_source_file = .{ .path = "lib.zig" }, + .root_source_file = b.path("lib.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), .optimize = optimize, .strip = false, diff --git a/test/standalone/build.zig b/test/standalone/build.zig index 673a52cedd5e..b2575bc83e3e 100644 --- a/test/standalone/build.zig +++ b/test/standalone/build.zig @@ -44,7 +44,7 @@ pub fn build(b: *std.Build) void { }) |tool_src_path| { const tool = b.addTest(.{ .name = std.fs.path.stem(tool_src_path), - .root_source_file = .{ .path = tool_src_path }, + .root_source_file = b.path(tool_src_path), .optimize = .Debug, .target = tools_target, }); diff --git a/test/standalone/c_compiler/build.zig b/test/standalone/c_compiler/build.zig index 0550ad8cee75..a3c842d8d51e 100644 --- a/test/standalone/c_compiler/build.zig +++ b/test/standalone/c_compiler/build.zig @@ -30,7 +30,7 @@ fn add( .optimize = optimize, .target = target, }); - exe_c.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &[0][]const u8{} }); + exe_c.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[0][]const u8{} }); exe_c.linkLibC(); const exe_cpp = b.addExecutable(.{ @@ -39,7 +39,7 @@ fn add( .target = target, }); b.default_step.dependOn(&exe_cpp.step); - exe_cpp.addCSourceFile(.{ .file = .{ .path = "test.cpp" }, .flags = &[0][]const u8{} }); + exe_cpp.addCSourceFile(.{ .file = b.path("test.cpp"), .flags = &[0][]const u8{} }); exe_cpp.linkLibCpp(); switch (target.result.os.tag) { diff --git a/test/standalone/child_process/build.zig b/test/standalone/child_process/build.zig index 89558c00e609..35317602b5e9 100644 --- a/test/standalone/child_process/build.zig +++ b/test/standalone/child_process/build.zig @@ -12,14 +12,14 @@ pub fn build(b: *std.Build) void { const child = b.addExecutable(.{ .name = "child", - .root_source_file = .{ .path = "child.zig" }, + .root_source_file = b.path("child.zig"), .optimize = optimize, .target = target, }); const main = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = target, }); diff --git a/test/standalone/cmakedefine/build.zig b/test/standalone/cmakedefine/build.zig index 967aa7ecbd96..d90441360fce 100644 --- a/test/standalone/cmakedefine/build.zig +++ b/test/standalone/cmakedefine/build.zig @@ -4,7 +4,7 @@ const ConfigHeader = std.Build.Step.ConfigHeader; pub fn build(b: *std.Build) void { const config_header = b.addConfigHeader( .{ - .style = .{ .cmake = .{ .path = "config.h.in" } }, + .style = .{ .cmake = b.path("config.h.in") }, .include_path = "config.h", }, .{ @@ -28,7 +28,7 @@ pub fn build(b: *std.Build) void { const pwd_sh = b.addConfigHeader( .{ - .style = .{ .cmake = .{ .path = "pwd.sh.in" } }, + .style = .{ .cmake = b.path("pwd.sh.in") }, .include_path = "pwd.sh", }, .{ .DIR = "${PWD}" }, @@ -36,7 +36,7 @@ pub fn build(b: *std.Build) void { const sigil_header = b.addConfigHeader( .{ - .style = .{ .cmake = .{ .path = "sigil.h.in" } }, + .style = .{ .cmake = b.path("sigil.h.in") }, .include_path = "sigil.h", }, .{}, @@ -44,7 +44,7 @@ pub fn build(b: *std.Build) void { const stack_header = b.addConfigHeader( .{ - .style = .{ .cmake = .{ .path = "stack.h.in" } }, + .style = .{ .cmake = b.path("stack.h.in") }, .include_path = "stack.h", }, .{ @@ -57,7 +57,7 @@ pub fn build(b: *std.Build) void { const wrapper_header = b.addConfigHeader( .{ - .style = .{ .cmake = .{ .path = "wrapper.h.in" } }, + .style = .{ .cmake = b.path("wrapper.h.in") }, .include_path = "wrapper.h", }, .{ diff --git a/test/standalone/coff_dwarf/build.zig b/test/standalone/coff_dwarf/build.zig index cd7c17efb37e..f0a6d5a1f74a 100644 --- a/test/standalone/coff_dwarf/build.zig +++ b/test/standalone/coff_dwarf/build.zig @@ -18,7 +18,7 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = target, }); @@ -28,7 +28,7 @@ pub fn build(b: *std.Build) void { .optimize = optimize, .target = target, }); - lib.addCSourceFile(.{ .file = .{ .path = "shared_lib.c" }, .flags = &.{"-gdwarf"} }); + lib.addCSourceFile(.{ .file = b.path("shared_lib.c"), .flags = &.{"-gdwarf"} }); lib.linkLibC(); exe.linkLibrary(lib); diff --git a/test/standalone/compiler_rt_panic/build.zig b/test/standalone/compiler_rt_panic/build.zig index 8ad7732a931b..93331a028245 100644 --- a/test/standalone/compiler_rt_panic/build.zig +++ b/test/standalone/compiler_rt_panic/build.zig @@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void { }); exe.linkLibC(); exe.addCSourceFile(.{ - .file = .{ .path = "main.c" }, + .file = b.path("main.c"), .flags = &.{}, }); exe.link_gc_sections = false; diff --git a/test/standalone/dep_diamond/build.zig b/test/standalone/dep_diamond/build.zig index 9190b29594cf..b14503e34919 100644 --- a/test/standalone/dep_diamond/build.zig +++ b/test/standalone/dep_diamond/build.zig @@ -7,21 +7,21 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const shared = b.createModule(.{ - .root_source_file = .{ .path = "shared.zig" }, + .root_source_file = b.path("shared.zig"), }); const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "test.zig" }, + .root_source_file = b.path("test.zig"), .target = b.host, .optimize = optimize, }); exe.root_module.addAnonymousImport("foo", .{ - .root_source_file = .{ .path = "foo.zig" }, + .root_source_file = b.path("foo.zig"), .imports = &.{.{ .name = "shared", .module = shared }}, }); exe.root_module.addAnonymousImport("bar", .{ - .root_source_file = .{ .path = "bar.zig" }, + .root_source_file = b.path("bar.zig"), .imports = &.{.{ .name = "shared", .module = shared }}, }); diff --git a/test/standalone/dep_mutually_recursive/build.zig b/test/standalone/dep_mutually_recursive/build.zig index 04589d9b5ba4..804abbce18d6 100644 --- a/test/standalone/dep_mutually_recursive/build.zig +++ b/test/standalone/dep_mutually_recursive/build.zig @@ -7,17 +7,17 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const foo = b.createModule(.{ - .root_source_file = .{ .path = "foo.zig" }, + .root_source_file = b.path("foo.zig"), }); const bar = b.createModule(.{ - .root_source_file = .{ .path = "bar.zig" }, + .root_source_file = b.path("bar.zig"), }); foo.addImport("bar", bar); bar.addImport("foo", foo); const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "test.zig" }, + .root_source_file = b.path("test.zig"), .target = b.host, .optimize = optimize, }); diff --git a/test/standalone/dep_recursive/build.zig b/test/standalone/dep_recursive/build.zig index a6334e6a9763..0ab732db4b06 100644 --- a/test/standalone/dep_recursive/build.zig +++ b/test/standalone/dep_recursive/build.zig @@ -7,13 +7,13 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const foo = b.createModule(.{ - .root_source_file = .{ .path = "foo.zig" }, + .root_source_file = b.path("foo.zig"), }); foo.addImport("foo", foo); const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "test.zig" }, + .root_source_file = b.path("test.zig"), .target = b.host, .optimize = optimize, }); diff --git a/test/standalone/dep_shared_builtin/build.zig b/test/standalone/dep_shared_builtin/build.zig index 33d53ad166ba..de84e2848d59 100644 --- a/test/standalone/dep_shared_builtin/build.zig +++ b/test/standalone/dep_shared_builtin/build.zig @@ -8,12 +8,12 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "test.zig" }, + .root_source_file = b.path("test.zig"), .target = b.host, .optimize = optimize, }); exe.root_module.addAnonymousImport("foo", .{ - .root_source_file = .{ .path = "foo.zig" }, + .root_source_file = b.path("foo.zig"), }); const run = b.addRunArtifact(exe); diff --git a/test/standalone/dep_triangle/build.zig b/test/standalone/dep_triangle/build.zig index b15555499753..f9f29099d5e7 100644 --- a/test/standalone/dep_triangle/build.zig +++ b/test/standalone/dep_triangle/build.zig @@ -7,17 +7,17 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const shared = b.createModule(.{ - .root_source_file = .{ .path = "shared.zig" }, + .root_source_file = b.path("shared.zig"), }); const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "test.zig" }, + .root_source_file = b.path("test.zig"), .target = b.host, .optimize = optimize, }); exe.root_module.addAnonymousImport("foo", .{ - .root_source_file = .{ .path = "foo.zig" }, + .root_source_file = b.path("foo.zig"), .imports = &.{.{ .name = "shared", .module = shared }}, }); exe.root_module.addImport("shared", shared); diff --git a/test/standalone/depend_on_main_mod/build.zig b/test/standalone/depend_on_main_mod/build.zig index bbef64693e59..42e96e0aa067 100644 --- a/test/standalone/depend_on_main_mod/build.zig +++ b/test/standalone/depend_on_main_mod/build.zig @@ -9,13 +9,13 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "depend_on_main_mod", - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); const foo_module = b.addModule("foo", .{ - .root_source_file = .{ .path = "src/foo.zig" }, + .root_source_file = b.path("src/foo.zig"), }); foo_module.addImport("root2", &exe.root_module); diff --git a/test/standalone/dirname/build.zig b/test/standalone/dirname/build.zig index 272ed54b3835..31f432e841e1 100644 --- a/test/standalone/dirname/build.zig +++ b/test/standalone/dirname/build.zig @@ -6,9 +6,7 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Test it"); b.default_step = test_step; - const touch_src = std.Build.LazyPath{ - .path = "touch.zig", - }; + const touch_src = b.path("touch.zig"); const touch = b.addExecutable(.{ .name = "touch", @@ -20,14 +18,14 @@ pub fn build(b: *std.Build) void { const exists_in = b.addExecutable(.{ .name = "exists_in", - .root_source_file = .{ .path = "exists_in.zig" }, + .root_source_file = b.path("exists_in.zig"), .optimize = .Debug, .target = target, }); const has_basename = b.addExecutable(.{ .name = "has_basename", - .root_source_file = .{ .path = "has_basename.zig" }, + .root_source_file = b.path("has_basename.zig"), .optimize = .Debug, .target = target, }); @@ -63,7 +61,7 @@ pub fn build(b: *std.Build) void { var file = dir.createFile("foo.txt", .{}) catch @panic("failed to create file"); file.close(); - break :setup_abspath std.Build.LazyPath{ .cwd_relative = temp_dir }; + break :setup_abspath b.pathCwd(temp_dir); }; addTestRun(test_step, exists_in, abs_path, &.{"foo.txt"}); } diff --git a/test/standalone/embed_generated_file/build.zig b/test/standalone/embed_generated_file/build.zig index 3f67cdea5421..f7430b7716ba 100644 --- a/test/standalone/embed_generated_file/build.zig +++ b/test/standalone/embed_generated_file/build.zig @@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void { const bootloader = b.addExecutable(.{ .name = "bootloader", - .root_source_file = .{ .path = "bootloader.zig" }, + .root_source_file = b.path("bootloader.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .x86, .os_tag = .freestanding, @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { }); const exe = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = .Debug, }); exe.root_module.addAnonymousImport("bootloader.elf", .{ diff --git a/test/standalone/emit_asm_and_bin/build.zig b/test/standalone/emit_asm_and_bin/build.zig index 2f671bb6cce5..51b4066e6ab6 100644 --- a/test/standalone/emit_asm_and_bin/build.zig +++ b/test/standalone/emit_asm_and_bin/build.zig @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void { b.default_step = test_step; const main = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = b.standardOptimizeOption(.{}), }); // TODO: actually check these two artifacts for correctness diff --git a/test/standalone/empty_env/build.zig b/test/standalone/empty_env/build.zig index a2fe48312827..b8e488f830e5 100644 --- a/test/standalone/empty_env/build.zig +++ b/test/standalone/empty_env/build.zig @@ -14,7 +14,7 @@ pub fn build(b: *std.Build) void { const main = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .target = b.host, .optimize = optimize, }); diff --git a/test/standalone/extern/build.zig b/test/standalone/extern/build.zig index 401deb3dc4d1..878b92ab5838 100644 --- a/test/standalone/extern/build.zig +++ b/test/standalone/extern/build.zig @@ -5,12 +5,12 @@ pub fn build(b: *std.Build) void { const obj = b.addObject(.{ .name = "exports", - .root_source_file = .{ .path = "exports.zig" }, + .root_source_file = b.path("exports.zig"), .target = b.host, .optimize = optimize, }); const main = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, }); main.addObject(obj); diff --git a/test/standalone/global_linkage/build.zig b/test/standalone/global_linkage/build.zig index 13b7fcfa0e5f..9edbc9612967 100644 --- a/test/standalone/global_linkage/build.zig +++ b/test/standalone/global_linkage/build.zig @@ -9,20 +9,20 @@ pub fn build(b: *std.Build) void { const obj1 = b.addStaticLibrary(.{ .name = "obj1", - .root_source_file = .{ .path = "obj1.zig" }, + .root_source_file = b.path("obj1.zig"), .optimize = optimize, .target = target, }); const obj2 = b.addStaticLibrary(.{ .name = "obj2", - .root_source_file = .{ .path = "obj2.zig" }, + .root_source_file = b.path("obj2.zig"), .optimize = optimize, .target = target, }); const main = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, }); main.linkLibrary(obj1); diff --git a/test/standalone/install_headers/build.zig b/test/standalone/install_headers/build.zig index 4c9bbb501ae7..5455d7846d54 100644 --- a/test/standalone/install_headers/build.zig +++ b/test/standalone/install_headers/build.zig @@ -32,7 +32,7 @@ pub fn build(b: *std.Build) void { \\} ) }); - libfoo.installHeadersDirectory(.{ .path = "include" }, "foo", .{ .exclude_extensions = &.{".ignore_me.h"} }); + libfoo.installHeadersDirectory(b.path("include"), "foo", .{ .exclude_extensions = &.{".ignore_me.h"} }); libfoo.installHeader(b.addWriteFiles().add("d.h", \\#define FOO_D "D" \\ @@ -78,7 +78,7 @@ pub fn build(b: *std.Build) void { }); const check_exists = b.addExecutable(.{ .name = "check_exists", - .root_source_file = .{ .path = "check_exists.zig" }, + .root_source_file = b.path("check_exists.zig"), .target = b.resolveTargetQuery(.{}), .optimize = .Debug, }); @@ -92,7 +92,7 @@ pub fn build(b: *std.Build) void { "custom/include/foo/config.h", "custom/include/bar.h", }); - run_check_exists.setCwd(.{ .cwd_relative = b.getInstallPath(.prefix, "") }); + run_check_exists.setCwd(b.pathCwd(b.getInstallPath(.prefix, ""))); run_check_exists.expectExitCode(0); run_check_exists.step.dependOn(&install_libfoo.step); test_step.dependOn(&run_check_exists.step); diff --git a/test/standalone/install_raw_hex/build.zig b/test/standalone/install_raw_hex/build.zig index d1ec55ab5349..515528534ee7 100644 --- a/test/standalone/install_raw_hex/build.zig +++ b/test/standalone/install_raw_hex/build.zig @@ -16,7 +16,7 @@ pub fn build(b: *std.Build) void { const elf = b.addExecutable(.{ .name = "zig-nrf52-blink.elf", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .target = target, .optimize = optimize, }); diff --git a/test/standalone/ios/build.zig b/test/standalone/ios/build.zig index 356f12a3d902..daabe8990dbf 100644 --- a/test/standalone/ios/build.zig +++ b/test/standalone/ios/build.zig @@ -21,10 +21,10 @@ pub fn build(b: *std.Build) void { .optimize = optimize, .target = target, }); - exe.addCSourceFile(.{ .file = .{ .path = "main.m" }, .flags = &.{} }); - exe.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include" }) }); - exe.addSystemFrameworkPath(.{ .path = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); - exe.addLibraryPath(.{ .path = b.pathJoin(&.{ sdk, "/usr/lib" }) }); + exe.addCSourceFile(.{ .file = b.path("main.m"), .flags = &.{} }); + exe.addSystemIncludePath(b.path(b.pathJoin(&.{ sdk, "/usr/include" }))); + exe.addSystemFrameworkPath(b.path(b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }))); + exe.addLibraryPath(b.path(b.pathJoin(&.{ sdk, "/usr/lib" }))); exe.linkFramework("Foundation"); exe.linkFramework("UIKit"); exe.linkLibC(); diff --git a/test/standalone/issue_11595/build.zig b/test/standalone/issue_11595/build.zig index c591b3058b5d..b6e17f1eef6d 100644 --- a/test/standalone/issue_11595/build.zig +++ b/test/standalone/issue_11595/build.zig @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "zigtest", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .target = target, .optimize = optimize, }); diff --git a/test/standalone/issue_12588/build.zig b/test/standalone/issue_12588/build.zig index aaf8f6c3149b..255f67c83b40 100644 --- a/test/standalone/issue_12588/build.zig +++ b/test/standalone/issue_12588/build.zig @@ -8,7 +8,7 @@ pub fn build(b: *std.Build) void { const obj = b.addObject(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = b.host, }); diff --git a/test/standalone/issue_12706/build.zig b/test/standalone/issue_12706/build.zig index 9a80dae256fe..528eba89d3a7 100644 --- a/test/standalone/issue_12706/build.zig +++ b/test/standalone/issue_12706/build.zig @@ -10,7 +10,7 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = target, }); diff --git a/test/standalone/issue_13970/build.zig b/test/standalone/issue_13970/build.zig index cc70144596df..e7d3a8243162 100644 --- a/test/standalone/issue_13970/build.zig +++ b/test/standalone/issue_13970/build.zig @@ -5,15 +5,15 @@ pub fn build(b: *std.Build) void { b.default_step = test_step; const test1 = b.addTest(.{ - .root_source_file = .{ .path = "test_root/empty.zig" }, + .root_source_file = b.path("test_root/empty.zig"), .test_runner = "src/main.zig", }); const test2 = b.addTest(.{ - .root_source_file = .{ .path = "src/empty.zig" }, + .root_source_file = b.path("src/empty.zig"), .test_runner = "src/main.zig", }); const test3 = b.addTest(.{ - .root_source_file = .{ .path = "empty.zig" }, + .root_source_file = b.path("empty.zig"), .test_runner = "src/main.zig", }); diff --git a/test/standalone/issue_339/build.zig b/test/standalone/issue_339/build.zig index 5dc686a77924..6327c5ed97fe 100644 --- a/test/standalone/issue_339/build.zig +++ b/test/standalone/issue_339/build.zig @@ -9,7 +9,7 @@ pub fn build(b: *std.Build) void { const obj = b.addObject(.{ .name = "test", - .root_source_file = .{ .path = "test.zig" }, + .root_source_file = b.path("test.zig"), .target = target, .optimize = optimize, }); diff --git a/test/standalone/issue_5825/build.zig b/test/standalone/issue_5825/build.zig index 078a9415701b..d4462bb5a108 100644 --- a/test/standalone/issue_5825/build.zig +++ b/test/standalone/issue_5825/build.zig @@ -16,7 +16,7 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const obj = b.addObject(.{ .name = "issue_5825", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = target, }); diff --git a/test/standalone/issue_794/build.zig b/test/standalone/issue_794/build.zig index eb05aa9b4fd5..d42ff1f3049f 100644 --- a/test/standalone/issue_794/build.zig +++ b/test/standalone/issue_794/build.zig @@ -5,9 +5,9 @@ pub fn build(b: *std.Build) void { b.default_step = test_step; const test_artifact = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), }); - test_artifact.addIncludePath(.{ .path = "a_directory" }); + test_artifact.addIncludePath(b.path("a_directory")); // TODO: actually check the output _ = test_artifact.getEmittedBin(); diff --git a/test/standalone/issue_8550/build.zig b/test/standalone/issue_8550/build.zig index 557019cfdc04..a0dea518d683 100644 --- a/test/standalone/issue_8550/build.zig +++ b/test/standalone/issue_8550/build.zig @@ -15,12 +15,12 @@ pub fn build(b: *std.Build) !void { const kernel = b.addExecutable(.{ .name = "kernel", - .root_source_file = .{ .path = "./main.zig" }, + .root_source_file = b.path("./main.zig"), .optimize = optimize, .target = target, }); - kernel.addObjectFile(.{ .path = "./boot.S" }); - kernel.setLinkerScript(.{ .path = "./linker.ld" }); + kernel.addObjectFile(b.path("./boot.S")); + kernel.setLinkerScript(b.path("./linker.ld")); b.installArtifact(kernel); test_step.dependOn(&kernel.step); diff --git a/test/standalone/load_dynamic_library/build.zig b/test/standalone/load_dynamic_library/build.zig index 140f276ebe04..27f8f6de7cce 100644 --- a/test/standalone/load_dynamic_library/build.zig +++ b/test/standalone/load_dynamic_library/build.zig @@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void { const lib = b.addSharedLibrary(.{ .name = "add", - .root_source_file = .{ .path = "add.zig" }, + .root_source_file = b.path("add.zig"), .version = .{ .major = 1, .minor = 0, .patch = 0 }, .optimize = optimize, .target = target, @@ -25,7 +25,7 @@ pub fn build(b: *std.Build) void { const main = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = target, }); diff --git a/test/standalone/mix_c_files/build.zig b/test/standalone/mix_c_files/build.zig index e91f87e13284..779d4d030e08 100644 --- a/test/standalone/mix_c_files/build.zig +++ b/test/standalone/mix_c_files/build.zig @@ -18,11 +18,11 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .target = b.host, .optimize = optimize, }); - exe.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &[_][]const u8{"-std=c11"} }); + exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c11"} }); exe.linkLibC(); const run_cmd = b.addRunArtifact(exe); diff --git a/test/standalone/mix_o_files/build.zig b/test/standalone/mix_o_files/build.zig index aa648145a831..dd8ef9a4c4bb 100644 --- a/test/standalone/mix_o_files/build.zig +++ b/test/standalone/mix_o_files/build.zig @@ -9,7 +9,7 @@ pub fn build(b: *std.Build) void { const obj = b.addObject(.{ .name = "base64", - .root_source_file = .{ .path = "base64.zig" }, + .root_source_file = b.path("base64.zig"), .optimize = optimize, .target = target, }); @@ -20,7 +20,7 @@ pub fn build(b: *std.Build) void { .target = target, }); exe.addCSourceFile(.{ - .file = .{ .path = "test.c" }, + .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c99"}, }); exe.addObject(obj); diff --git a/test/standalone/options/build.zig b/test/standalone/options/build.zig index 97cf91c1fbc3..747a5e72ea9d 100644 --- a/test/standalone/options/build.zig +++ b/test/standalone/options/build.zig @@ -2,7 +2,7 @@ const std = @import("std"); pub fn build(b: *std.Build) void { const main = b.addTest(.{ - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = b.host, .optimize = .Debug, }); diff --git a/test/standalone/pie/build.zig b/test/standalone/pie/build.zig index 2e9f99ff4b67..25ed330abce2 100644 --- a/test/standalone/pie/build.zig +++ b/test/standalone/pie/build.zig @@ -11,7 +11,7 @@ pub fn build(b: *std.Build) void { }); const main = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = target, }); diff --git a/test/standalone/pkg_import/build.zig b/test/standalone/pkg_import/build.zig index 207f924f9be9..4bef1d756f48 100644 --- a/test/standalone/pkg_import/build.zig +++ b/test/standalone/pkg_import/build.zig @@ -8,11 +8,11 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "test", - .root_source_file = .{ .path = "test.zig" }, + .root_source_file = b.path("test.zig"), .optimize = optimize, .target = b.host, }); - exe.root_module.addAnonymousImport("my_pkg", .{ .root_source_file = .{ .path = "pkg.zig" } }); + exe.root_module.addAnonymousImport("my_pkg", .{ .root_source_file = b.path("pkg.zig") }); const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); diff --git a/test/standalone/self_exe_symlink/build.zig b/test/standalone/self_exe_symlink/build.zig index d61d50257433..77799cfa00cc 100644 --- a/test/standalone/self_exe_symlink/build.zig +++ b/test/standalone/self_exe_symlink/build.zig @@ -15,14 +15,14 @@ pub fn build(b: *std.Build) void { const main = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = target, }); const create_symlink_exe = b.addExecutable(.{ .name = "create-symlink", - .root_source_file = .{ .path = "create-symlink.zig" }, + .root_source_file = b.path("create-symlink.zig"), .optimize = optimize, .target = target, }); diff --git a/test/standalone/shared_library/build.zig b/test/standalone/shared_library/build.zig index 4d409295e866..2765a2ec07bb 100644 --- a/test/standalone/shared_library/build.zig +++ b/test/standalone/shared_library/build.zig @@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void { const target = b.host; const lib = b.addSharedLibrary(.{ .name = "mathtest", - .root_source_file = .{ .path = "mathtest.zig" }, + .root_source_file = b.path("mathtest.zig"), .version = .{ .major = 1, .minor = 0, .patch = 0 }, .target = target, .optimize = optimize, @@ -25,7 +25,7 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); exe.addCSourceFile(.{ - .file = .{ .path = "test.c" }, + .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c99"}, }); exe.linkLibrary(lib); diff --git a/test/standalone/sigpipe/build.zig b/test/standalone/sigpipe/build.zig index 07005795e291..8e1cb5e1227f 100644 --- a/test/standalone/sigpipe/build.zig +++ b/test/standalone/sigpipe/build.zig @@ -29,7 +29,7 @@ pub fn build(b: *std.build.Builder) !void { options.addOption(bool, "keep_sigpipe", keep_sigpipe); const exe = b.addExecutable(.{ .name = "breakpipe", - .root_source_file = .{ .path = "breakpipe.zig" }, + .root_source_file = b.path("breakpipe.zig"), }); exe.addOptions("build_options", options); const run = b.addRunArtifact(exe); diff --git a/test/standalone/simple/build.zig b/test/standalone/simple/build.zig index 8bcfbe0fcac2..c623780fa5df 100644 --- a/test/standalone/simple/build.zig +++ b/test/standalone/simple/build.zig @@ -42,7 +42,7 @@ pub fn build(b: *std.Build) void { if (case.is_exe) { const exe = b.addExecutable(.{ .name = std.fs.path.stem(case.src_path), - .root_source_file = .{ .path = case.src_path }, + .root_source_file = b.path(case.src_path), .optimize = optimize, .target = resolved_target, }); @@ -56,7 +56,7 @@ pub fn build(b: *std.Build) void { if (case.is_test) { const exe = b.addTest(.{ .name = std.fs.path.stem(case.src_path), - .root_source_file = .{ .path = case.src_path }, + .root_source_file = b.path(case.src_path), .optimize = optimize, .target = resolved_target, }); diff --git a/test/standalone/stack_iterator/build.zig b/test/standalone/stack_iterator/build.zig index 463a533ac400..7041aaa0b89d 100644 --- a/test/standalone/stack_iterator/build.zig +++ b/test/standalone/stack_iterator/build.zig @@ -19,7 +19,7 @@ pub fn build(b: *std.Build) void { { const exe = b.addExecutable(.{ .name = "unwind_fp", - .root_source_file = .{ .path = "unwind.zig" }, + .root_source_file = b.path("unwind.zig"), .target = target, .optimize = optimize, .unwind_tables = if (target.result.isDarwin()) true else null, @@ -42,7 +42,7 @@ pub fn build(b: *std.Build) void { { const exe = b.addExecutable(.{ .name = "unwind_nofp", - .root_source_file = .{ .path = "unwind.zig" }, + .root_source_file = b.path("unwind.zig"), .target = target, .optimize = optimize, .unwind_tables = true, @@ -74,14 +74,14 @@ pub fn build(b: *std.Build) void { c_shared_lib.defineCMacro("LIB_API", "__declspec(dllexport)"); c_shared_lib.addCSourceFile(.{ - .file = .{ .path = "shared_lib.c" }, + .file = b.path("shared_lib.c"), .flags = &.{"-fomit-frame-pointer"}, }); c_shared_lib.linkLibC(); const exe = b.addExecutable(.{ .name = "shared_lib_unwind", - .root_source_file = .{ .path = "shared_lib_unwind.zig" }, + .root_source_file = b.path("shared_lib_unwind.zig"), .target = target, .optimize = optimize, .unwind_tables = if (target.result.isDarwin()) true else null, diff --git a/test/standalone/static_c_lib/build.zig b/test/standalone/static_c_lib/build.zig index 244107b0f1e1..c025aa9b3938 100644 --- a/test/standalone/static_c_lib/build.zig +++ b/test/standalone/static_c_lib/build.zig @@ -11,15 +11,15 @@ pub fn build(b: *std.Build) void { .optimize = optimize, .target = b.host, }); - foo.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &[_][]const u8{} }); - foo.addIncludePath(.{ .path = "." }); + foo.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &[_][]const u8{} }); + foo.addIncludePath(b.path(".")); const test_exe = b.addTest(.{ - .root_source_file = .{ .path = "foo.zig" }, + .root_source_file = b.path("foo.zig"), .optimize = optimize, }); test_exe.linkLibrary(foo); - test_exe.addIncludePath(.{ .path = "." }); + test_exe.addIncludePath(b.path(".")); test_step.dependOn(&b.addRunArtifact(test_exe).step); } diff --git a/test/standalone/strip_empty_loop/build.zig b/test/standalone/strip_empty_loop/build.zig index 4875bd9128c7..aadfbd2fc0b0 100644 --- a/test/standalone/strip_empty_loop/build.zig +++ b/test/standalone/strip_empty_loop/build.zig @@ -9,7 +9,7 @@ pub fn build(b: *std.Build) void { const main = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = target, .strip = true, diff --git a/test/standalone/strip_struct_init/build.zig b/test/standalone/strip_struct_init/build.zig index 2d903f973a1f..ef7960d13051 100644 --- a/test/standalone/strip_struct_init/build.zig +++ b/test/standalone/strip_struct_init/build.zig @@ -7,7 +7,7 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const main = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .strip = true, }); diff --git a/test/standalone/test_runner_module_imports/build.zig b/test/standalone/test_runner_module_imports/build.zig index af8e68d71789..222bd31d28e8 100644 --- a/test/standalone/test_runner_module_imports/build.zig +++ b/test/standalone/test_runner_module_imports/build.zig @@ -2,13 +2,13 @@ const std = @import("std"); pub fn build(b: *std.Build) void { const t = b.addTest(.{ - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .test_runner = "test_runner/main.zig", }); - const module1 = b.createModule(.{ .root_source_file = .{ .path = "module1/main.zig" } }); + const module1 = b.createModule(.{ .root_source_file = b.path("module1/main.zig") }); const module2 = b.createModule(.{ - .root_source_file = .{ .path = "module2/main.zig" }, + .root_source_file = b.path("module2/main.zig"), .imports = &.{.{ .name = "module1", .module = module1 }}, }); diff --git a/test/standalone/test_runner_path/build.zig b/test/standalone/test_runner_path/build.zig index 352a18efe058..eebb9d3e959f 100644 --- a/test/standalone/test_runner_path/build.zig +++ b/test/standalone/test_runner_path/build.zig @@ -7,7 +7,7 @@ pub fn build(b: *std.Build) void { b.default_step = test_step; const test_exe = b.addTest(.{ - .root_source_file = .{ .path = "test.zig" }, + .root_source_file = b.path("test.zig"), }); test_exe.test_runner = "test_runner.zig"; diff --git a/test/standalone/use_alias/build.zig b/test/standalone/use_alias/build.zig index 0511cd3935fc..7ee501713c32 100644 --- a/test/standalone/use_alias/build.zig +++ b/test/standalone/use_alias/build.zig @@ -7,10 +7,10 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const main = b.addTest(.{ - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, }); - main.addIncludePath(.{ .path = "." }); + main.addIncludePath(b.path(".")); test_step.dependOn(&b.addRunArtifact(main).step); } diff --git a/test/standalone/windows_entry_points/build.zig b/test/standalone/windows_entry_points/build.zig index 25c48391475a..c3d9c4994083 100644 --- a/test/standalone/windows_entry_points/build.zig +++ b/test/standalone/windows_entry_points/build.zig @@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void { .optimize = .Debug, .link_libc = true, }); - exe.addCSourceFile(.{ .file = .{ .path = "main.c" } }); + exe.addCSourceFile(.{ .file = b.path("main.c") }); _ = exe.getEmittedBin(); test_step.dependOn(&exe.step); @@ -31,7 +31,7 @@ pub fn build(b: *std.Build) void { .link_libc = true, }); exe.mingw_unicode_entry_point = true; - exe.addCSourceFile(.{ .file = .{ .path = "wmain.c" } }); + exe.addCSourceFile(.{ .file = b.path("wmain.c") }); _ = exe.getEmittedBin(); test_step.dependOn(&exe.step); @@ -45,7 +45,7 @@ pub fn build(b: *std.Build) void { .link_libc = true, }); // Note: `exe.subsystem = .Windows;` is not necessary - exe.addCSourceFile(.{ .file = .{ .path = "winmain.c" } }); + exe.addCSourceFile(.{ .file = b.path("winmain.c") }); _ = exe.getEmittedBin(); test_step.dependOn(&exe.step); @@ -60,7 +60,7 @@ pub fn build(b: *std.Build) void { }); exe.mingw_unicode_entry_point = true; // Note: `exe.subsystem = .Windows;` is not necessary - exe.addCSourceFile(.{ .file = .{ .path = "wwinmain.c" } }); + exe.addCSourceFile(.{ .file = b.path("wwinmain.c") }); _ = exe.getEmittedBin(); test_step.dependOn(&exe.step); diff --git a/test/standalone/windows_resources/build.zig b/test/standalone/windows_resources/build.zig index 51117515715a..6a72dee2a61e 100644 --- a/test/standalone/windows_resources/build.zig +++ b/test/standalone/windows_resources/build.zig @@ -25,12 +25,12 @@ fn add( ) void { const exe = b.addExecutable(.{ .name = "zig_resource_test", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .target = target, .optimize = .Debug, }); exe.addWin32ResourceFile(.{ - .file = .{ .path = "res/zig.rc" }, + .file = b.path("res/zig.rc"), .flags = &.{"/c65001"}, // UTF-8 code page }); exe.rc_includes = switch (rc_includes) { diff --git a/test/standalone/windows_spawn/build.zig b/test/standalone/windows_spawn/build.zig index a52cbd7202a3..aef6ed4594f3 100644 --- a/test/standalone/windows_spawn/build.zig +++ b/test/standalone/windows_spawn/build.zig @@ -12,14 +12,14 @@ pub fn build(b: *std.Build) void { const hello = b.addExecutable(.{ .name = "hello", - .root_source_file = .{ .path = "hello.zig" }, + .root_source_file = b.path("hello.zig"), .optimize = optimize, .target = target, }); const main = b.addExecutable(.{ .name = "main", - .root_source_file = .{ .path = "main.zig" }, + .root_source_file = b.path("main.zig"), .optimize = optimize, .target = target, }); diff --git a/test/standalone/zerolength_check/build.zig b/test/standalone/zerolength_check/build.zig index dacfc841c1a7..8118c6e17231 100644 --- a/test/standalone/zerolength_check/build.zig +++ b/test/standalone/zerolength_check/build.zig @@ -12,7 +12,7 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const unit_tests = b.addTest(.{ - .root_source_file = .{ .path = "src/main.zig" }, + .root_source_file = b.path("src/main.zig"), .target = b.resolveTargetQuery(.{ .os_tag = .wasi, .cpu_arch = .wasm32, diff --git a/test/tests.zig b/test/tests.zig index 286ac7e91ce6..c7e6217f44e8 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -641,7 +641,7 @@ pub fn addStackTraceTests( ) *Step { const check_exe = b.addExecutable(.{ .name = "check-stack-trace", - .root_source_file = .{ .path = "test/src/check-stack-trace.zig" }, + .root_source_file = b.path("test/src/check-stack-trace.zig"), .target = b.host, .optimize = .Debug, }); @@ -722,7 +722,7 @@ pub fn addCliTests(b: *std.Build) *Step { // Test `zig init`. const tmp_path = b.makeTempPath(); const init_exe = b.addSystemCommand(&.{ b.graph.zig_exe, "init" }); - init_exe.setCwd(.{ .cwd_relative = tmp_path }); + init_exe.setCwd(b.pathCwd(tmp_path)); init_exe.setName("zig init"); init_exe.expectStdOutEqual(""); init_exe.expectStdErrEqual("info: created build.zig\n" ++ @@ -743,13 +743,13 @@ pub fn addCliTests(b: *std.Build) *Step { run_bad.step.dependOn(&init_exe.step); const run_test = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "test" }); - run_test.setCwd(.{ .cwd_relative = tmp_path }); + run_test.setCwd(b.pathCwd(tmp_path)); run_test.setName("zig build test"); run_test.expectStdOutEqual(""); run_test.step.dependOn(&init_exe.step); const run_run = b.addSystemCommand(&.{ b.graph.zig_exe, "build", "run" }); - run_run.setCwd(.{ .cwd_relative = tmp_path }); + run_run.setCwd(b.pathCwd(tmp_path)); run_run.setName("zig build run"); run_run.expectStdOutEqual("Run `zig build test` to run the tests.\n"); run_run.expectStdErrEqual("All your codebase are belong to us.\n"); @@ -827,7 +827,7 @@ pub fn addCliTests(b: *std.Build) *Step { // Test zig fmt affecting only the appropriate files. const run1 = b.addSystemCommand(&.{ b.graph.zig_exe, "fmt", "fmt1.zig" }); run1.setName("run zig fmt one file"); - run1.setCwd(.{ .cwd_relative = tmp_path }); + run1.setCwd(b.pathCwd(tmp_path)); run1.has_side_effects = true; // stdout should be file path + \n run1.expectStdOutEqual("fmt1.zig\n"); @@ -835,7 +835,7 @@ pub fn addCliTests(b: *std.Build) *Step { // Test excluding files and directories from a run const run2 = b.addSystemCommand(&.{ b.graph.zig_exe, "fmt", "--exclude", "fmt2.zig", "--exclude", "subdir", "." }); run2.setName("run zig fmt on directory with exclusions"); - run2.setCwd(.{ .cwd_relative = tmp_path }); + run2.setCwd(b.pathCwd(tmp_path)); run2.has_side_effects = true; run2.expectStdOutEqual(""); run2.step.dependOn(&run1.step); @@ -843,7 +843,7 @@ pub fn addCliTests(b: *std.Build) *Step { // Test excluding non-existent file const run3 = b.addSystemCommand(&.{ b.graph.zig_exe, "fmt", "--exclude", "fmt2.zig", "--exclude", "nonexistent.zig", "." }); run3.setName("run zig fmt on directory with non-existent exclusion"); - run3.setCwd(.{ .cwd_relative = tmp_path }); + run3.setCwd(b.pathCwd(tmp_path)); run3.has_side_effects = true; run3.expectStdOutEqual("." ++ s ++ "subdir" ++ s ++ "fmt3.zig\n"); run3.step.dependOn(&run2.step); @@ -851,7 +851,7 @@ pub fn addCliTests(b: *std.Build) *Step { // running it on the dir, only the new file should be changed const run4 = b.addSystemCommand(&.{ b.graph.zig_exe, "fmt", "." }); run4.setName("run zig fmt the directory"); - run4.setCwd(.{ .cwd_relative = tmp_path }); + run4.setCwd(b.pathCwd(tmp_path)); run4.has_side_effects = true; run4.expectStdOutEqual("." ++ s ++ "fmt2.zig\n"); run4.step.dependOn(&run3.step); @@ -859,7 +859,7 @@ pub fn addCliTests(b: *std.Build) *Step { // both files have been formatted, nothing should change now const run5 = b.addSystemCommand(&.{ b.graph.zig_exe, "fmt", "." }); run5.setName("run zig fmt with nothing to do"); - run5.setCwd(.{ .cwd_relative = tmp_path }); + run5.setCwd(b.pathCwd(tmp_path)); run5.has_side_effects = true; run5.expectStdOutEqual(""); run5.step.dependOn(&run4.step); @@ -873,13 +873,13 @@ pub fn addCliTests(b: *std.Build) *Step { // Test `zig fmt` handling UTF-16 decoding. const run6 = b.addSystemCommand(&.{ b.graph.zig_exe, "fmt", "." }); run6.setName("run zig fmt convert UTF-16 to UTF-8"); - run6.setCwd(.{ .cwd_relative = tmp_path }); + run6.setCwd(b.pathCwd(tmp_path)); run6.has_side_effects = true; run6.expectStdOutEqual("." ++ s ++ "fmt6.zig\n"); run6.step.dependOn(&write6.step); // TODO change this to an exact match - const check6 = b.addCheckFile(.{ .path = fmt6_path }, .{ + const check6 = b.addCheckFile(b.path(fmt6_path), .{ .expected_matches = &.{ "// no reason", }, @@ -1037,7 +1037,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { options.max_rss; const these_tests = b.addTest(.{ - .root_source_file = .{ .path = options.root_src }, + .root_source_file = b.path(options.root_src), .optimize = test_target.optimize_mode, .target = resolved_target, .max_rss = max_rss, @@ -1046,7 +1046,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { .single_threaded = test_target.single_threaded, .use_llvm = test_target.use_llvm, .use_lld = test_target.use_lld, - .zig_lib_dir = .{ .path = "lib" }, + .zig_lib_dir = b.path("lib"), .pic = test_target.pic, .strip = test_target.strip, }); @@ -1062,7 +1062,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { const use_lld = if (test_target.use_lld == false) "-no-lld" else ""; const use_pic = if (test_target.pic == true) "-pic" else ""; - for (options.include_paths) |include_path| these_tests.addIncludePath(.{ .path = include_path }); + for (options.include_paths) |include_path| these_tests.addIncludePath(b.path(include_path)); const qualified_name = b.fmt("{s}-{s}-{s}-{s}{s}{s}{s}{s}{s}", .{ options.name, @@ -1084,7 +1084,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { .name = qualified_name, .link_libc = test_target.link_libc, .target = b.resolveTargetQuery(altered_query), - .zig_lib_dir = .{ .path = "lib" }, + .zig_lib_dir = b.path("lib"), }); compile_c.addCSourceFile(.{ .file = these_tests.getEmittedBin(), @@ -1113,7 +1113,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { "-Wno-absolute-value", }, }); - compile_c.addIncludePath(.{ .path = "lib" }); // for zig.h + compile_c.addIncludePath(b.path("lib")); // for zig.h if (target.os.tag == .windows) { if (true) { // Unfortunately this requires about 8G of RAM for clang to compile @@ -1189,7 +1189,7 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S if (c_abi_target.use_lld == false) "-no-lld" else "", if (c_abi_target.pic == true) "-pic" else "", }), - .root_source_file = .{ .path = "test/c_abi/main.zig" }, + .root_source_file = b.path("test/c_abi/main.zig"), .target = resolved_target, .optimize = optimize_mode, .link_libc = true, @@ -1199,7 +1199,7 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S .strip = c_abi_target.strip, }); test_step.addCSourceFile(.{ - .file = .{ .path = "test/c_abi/cfuncs.c" }, + .file = b.path("test/c_abi/cfuncs.c"), .flags = &.{"-std=c99"}, }); for (c_abi_target.c_defines) |define| test_step.defineCMacro(define, null); From 659ff232e09e7949ff5e34d8d9b0133240878daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Mon, 8 Apr 2024 21:21:32 +0100 Subject: [PATCH 03/14] std.Build.LazyPath: use a union field in a struct This adds a `root` field to LazyPath which contains the actual union data. This means the LazyPath is now a struct instead of a union itself. --- lib/std/Build.zig | 160 ++++++++++++++-------------- lib/std/Build/Module.zig | 2 +- lib/std/Build/Step/Compile.zig | 8 +- lib/std/Build/Step/ConfigHeader.zig | 2 +- 4 files changed, 88 insertions(+), 84 deletions(-) diff --git a/lib/std/Build.zig b/lib/std/Build.zig index af924fed02d9..7093cf8f63f3 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -2087,16 +2087,16 @@ pub const GeneratedFile = struct { pub fn path(b: *Build, p: []const u8) LazyPath { // TODO: absolute paths - return .{ .path = b.dupePath(p) }; + return .{ .root = .{ .path = b.dupePath(p) } }; } pub fn pathCwd(b: *Build, p: []const u8) LazyPath { // TODO: absolute paths? - return .{ .cwd_relative = b.dupePath(p) }; + return .{ .root = .{ .cwd_relative = b.dupePath(p) } }; } pub fn pathGenerated(_: *Build, g: *const GeneratedFile) LazyPath { - return .{ .generated = g }; + return .{ .root = .{ .generated = g } }; } // dirnameAllowEmpty is a variant of fs.path.dirname @@ -2130,45 +2130,47 @@ test dirnameAllowEmpty { } /// A reference to an existing or future path. -pub const LazyPath = union(enum) { - /// A source file path relative to build root. - /// This should not be an absolute path, but in an older iteration of the zig build - /// system API, it was allowed to be absolute. Absolute paths should use `cwd_relative`. - path: []const u8, - - /// A file that is generated by an interface. Those files usually are - /// not available until built by a build step. - generated: *const GeneratedFile, - - /// One of the parent directories of a file generated by an interface. - /// The path is not available until built by a build step. - generated_dirname: struct { +pub const LazyPath = struct { + root: union(enum) { + /// A source file path relative to build root. + /// This should not be an absolute path, but in an older iteration of the zig build + /// system API, it was allowed to be absolute. Absolute paths should use `cwd_relative`. + path: []const u8, + + /// A file that is generated by an interface. Those files usually are + /// not available until built by a build step. generated: *const GeneratedFile, - /// The number of parent directories to go up. - /// 0 means the directory of the generated file, - /// 1 means the parent of that directory, and so on. - up: usize, - }, + /// One of the parent directories of a file generated by an interface. + /// The path is not available until built by a build step. + generated_dirname: struct { + generated: *const GeneratedFile, + + /// The number of parent directories to go up. + /// 0 means the directory of the generated file, + /// 1 means the parent of that directory, and so on. + up: usize, + }, - /// An absolute path or a path relative to the current working directory of - /// the build runner process. - /// This is uncommon but used for system environment paths such as `--zig-lib-dir` which - /// ignore the file system path of build.zig and instead are relative to the directory from - /// which `zig build` was invoked. - /// Use of this tag indicates a dependency on the host system. - cwd_relative: []const u8, - - dependency: struct { - dependency: *Dependency, - sub_path: []const u8, + /// An absolute path or a path relative to the current working directory of + /// the build runner process. + /// This is uncommon but used for system environment paths such as `--zig-lib-dir` which + /// ignore the file system path of build.zig and instead are relative to the directory from + /// which `zig build` was invoked. + /// Use of this tag indicates a dependency on the host system. + cwd_relative: []const u8, + + dependency: struct { + dependency: *Dependency, + sub_path: []const u8, + }, }, /// Returns a new file source that will have a relative path to the build root guaranteed. /// Asserts the parameter is not an absolute path. pub fn relative(p: []const u8) LazyPath { std.debug.assert(!std.fs.path.isAbsolute(p)); - return LazyPath{ .path = p }; + return LazyPath{ .root = .{ .path = p } }; } /// Returns a lazy path referring to the directory containing this path. @@ -2179,62 +2181,64 @@ pub const LazyPath = union(enum) { /// Similarly, if the path is a generated file inside zig-cache, /// the dirname is not allowed to traverse outside of zig-cache. pub fn dirname(self: LazyPath) LazyPath { - return switch (self) { - .generated => |gen| .{ .generated_dirname = .{ .generated = gen, .up = 0 } }, - .generated_dirname => |gen| .{ .generated_dirname = .{ .generated = gen.generated, .up = gen.up + 1 } }, - .path => |p| .{ - .path = dirnameAllowEmpty(p) orelse { - dumpBadDirnameHelp(null, null, - \\dirname() attempted to traverse outside the build root. - \\This is not allowed. - \\ - , .{}) catch {}; - @panic("misconfigured build script"); - }, - }, - .cwd_relative => |p| .{ - .cwd_relative = dirnameAllowEmpty(p) orelse { - // If we get null, it means one of two things: - // - p was absolute, and is now root - // - p was relative, and is now "" - // In either case, the build script tried to go too far - // and we should panic. - if (fs.path.isAbsolute(p)) { + return .{ + .root = switch (self.root) { + .generated => |gen| .{ .generated_dirname = .{ .generated = gen, .up = 0 } }, + .generated_dirname => |gen| .{ .generated_dirname = .{ .generated = gen.generated, .up = gen.up + 1 } }, + .path => |p| .{ + .path = dirnameAllowEmpty(p) orelse { dumpBadDirnameHelp(null, null, - \\dirname() attempted to traverse outside the root. - \\No more directories left to go up. + \\dirname() attempted to traverse outside the build root. + \\This is not allowed. \\ , .{}) catch {}; @panic("misconfigured build script"); - } else { + }, + }, + .cwd_relative => |p| .{ + .cwd_relative = dirnameAllowEmpty(p) orelse { + // If we get null, it means one of two things: + // - p was absolute, and is now root + // - p was relative, and is now "" + // In either case, the build script tried to go too far + // and we should panic. + if (fs.path.isAbsolute(p)) { + dumpBadDirnameHelp(null, null, + \\dirname() attempted to traverse outside the root. + \\No more directories left to go up. + \\ + , .{}) catch {}; + @panic("misconfigured build script"); + } else { + dumpBadDirnameHelp(null, null, + \\dirname() attempted to traverse outside the current working directory. + \\This is not allowed. + \\ + , .{}) catch {}; + @panic("misconfigured build script"); + } + }, + }, + .dependency => |dep| .{ .dependency = .{ + .dependency = dep.dependency, + .sub_path = dirnameAllowEmpty(dep.sub_path) orelse { dumpBadDirnameHelp(null, null, - \\dirname() attempted to traverse outside the current working directory. + \\dirname() attempted to traverse outside the dependency root. \\This is not allowed. \\ , .{}) catch {}; @panic("misconfigured build script"); - } - }, + }, + } }, }, - .dependency => |dep| .{ .dependency = .{ - .dependency = dep.dependency, - .sub_path = dirnameAllowEmpty(dep.sub_path) orelse { - dumpBadDirnameHelp(null, null, - \\dirname() attempted to traverse outside the dependency root. - \\This is not allowed. - \\ - , .{}) catch {}; - @panic("misconfigured build script"); - }, - } }, }; } /// Returns a string that can be shown to represent the file source. /// Either returns the path or `"generated"`. pub fn getDisplayName(self: LazyPath) []const u8 { - return switch (self) { - .path, .cwd_relative => self.path, + return switch (self.root) { + .path, .cwd_relative => self.root.path, .generated => "generated", .generated_dirname => "generated", .dependency => "dependency", @@ -2243,7 +2247,7 @@ pub const LazyPath = union(enum) { /// Adds dependencies this file source implies to the given step. pub fn addStepDependencies(self: LazyPath, other_step: *Step) void { - switch (self) { + switch (self.root) { .path, .cwd_relative, .dependency => {}, .generated => |gen| other_step.dependOn(gen.step), .generated_dirname => |gen| other_step.dependOn(gen.generated.step), @@ -2262,7 +2266,7 @@ pub const LazyPath = union(enum) { /// `asking_step` is only used for debugging purposes; it's the step being /// run that is asking for the path. pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 { - switch (self) { + switch (self.root) { .path => |p| return src_builder.pathFromRoot(p), .cwd_relative => |p| return src_builder.pathFromCwd(p), .generated => |gen| return gen.path orelse { @@ -2276,7 +2280,7 @@ pub const LazyPath = union(enum) { (src_builder.cache_root.join(src_builder.allocator, &.{"."}) catch @panic("OOM")); const gen_step = gen.generated.step; - var p = getPath2(LazyPath{ .generated = gen.generated }, src_builder, asking_step); + var p = getPath2(LazyPath{ .root = .{ .generated = gen.generated } }, src_builder, asking_step); var i: usize = 0; while (i <= gen.up) : (i += 1) { // path is absolute. @@ -2315,7 +2319,7 @@ pub const LazyPath = union(enum) { /// Duplicates the file source for a given builder. pub fn dupe(self: LazyPath, b: *Build) LazyPath { - return switch (self) { + return .{ .root = switch (self.root) { .path => |p| .{ .path = b.dupePath(p) }, .cwd_relative => |p| .{ .cwd_relative = b.dupePath(p) }, .generated => |gen| .{ .generated = gen }, @@ -2326,7 +2330,7 @@ pub const LazyPath = union(enum) { }, }, .dependency => |dep| .{ .dependency = dep }, - }; + } }; } }; diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig index 41e83bfb66d3..baccc88588af 100644 --- a/lib/std/Build/Module.zig +++ b/lib/std/Build/Module.zig @@ -573,7 +573,7 @@ pub fn addLibraryPath(m: *Module, directory_path: LazyPath) void { pub fn addRPath(m: *Module, directory_path: LazyPath) void { const b = m.owner; - switch (directory_path) { + switch (directory_path.root) { .path, .cwd_relative => |path| { // TODO: remove this check after people upgrade and stop expecting it to work if (std.mem.startsWith(u8, path, "@executable_path") or diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 3b081112662d..9208aa1ec4a8 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -271,8 +271,8 @@ pub const HeaderInstallation = union(enum) { // As a temporary workaround, we convert build root-relative paths to absolute paths. // If/when the build-root relative paths are updated to encode which build root they are // relative to, this workaround should be removed. - const duped_source: LazyPath = switch (self.source) { - .path => |root_rel| .{ .cwd_relative = b.pathFromRoot(root_rel) }, + const duped_source: LazyPath = switch (self.source.root) { + .path => |root_rel| .{ .root = .{ .cwd_relative = b.pathFromRoot(root_rel) } }, else => self.source.dupe(b), }; @@ -312,8 +312,8 @@ pub const HeaderInstallation = union(enum) { // As a temporary workaround, we convert build root-relative paths to absolute paths. // If/when the build-root relative paths are updated to encode which build root they are // relative to, this workaround should be removed. - const duped_source: LazyPath = switch (self.source) { - .path => |root_rel| b.pathCwd(b.pathFromRoot(root_rel)), + const duped_source: LazyPath = switch (self.source.root) { + .path => |root_rel| .{ .root = .{ .cwd_relative = b.pathFromRoot(root_rel) } }, else => self.source.dupe(b), }; diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig index b38908550a8e..eac706acff6b 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -57,7 +57,7 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader { var include_path: []const u8 = "config.h"; if (options.style.getPath()) |s| default_include_path: { - const sub_path = switch (s) { + const sub_path = switch (s.root) { .path => |path| path, .generated, .generated_dirname => break :default_include_path, .cwd_relative => |sub_path| sub_path, From 9793ee28bfa285615050e1817ad7e33b9232314a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Mon, 8 Apr 2024 21:27:56 +0100 Subject: [PATCH 04/14] std.Build.LazyPath: remove `relative()` function This function won't be possible to implement once LazyPath requires a pointer to std.Build that owns it. --- lib/std/Build.zig | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 7093cf8f63f3..ea89c510d6ea 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -2166,12 +2166,7 @@ pub const LazyPath = struct { }, }, - /// Returns a new file source that will have a relative path to the build root guaranteed. - /// Asserts the parameter is not an absolute path. - pub fn relative(p: []const u8) LazyPath { - std.debug.assert(!std.fs.path.isAbsolute(p)); - return LazyPath{ .root = .{ .path = p } }; - } + pub const relative = @compileError("use std.Build.path() instead"); /// Returns a lazy path referring to the directory containing this path. /// From 3172383ec25d145130eaa6f49ed05cdb33673ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Mon, 8 Apr 2024 21:35:36 +0100 Subject: [PATCH 05/14] std.Build.LazyPath: add `owner` builder --- lib/std/Build.zig | 15 +++++++++------ lib/std/Build/Step/Compile.zig | 6 ++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/std/Build.zig b/lib/std/Build.zig index ea89c510d6ea..0136bae6ac83 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -2087,16 +2087,16 @@ pub const GeneratedFile = struct { pub fn path(b: *Build, p: []const u8) LazyPath { // TODO: absolute paths - return .{ .root = .{ .path = b.dupePath(p) } }; + return .{ .owner = b, .root = .{ .path = b.dupePath(p) } }; } pub fn pathCwd(b: *Build, p: []const u8) LazyPath { // TODO: absolute paths? - return .{ .root = .{ .cwd_relative = b.dupePath(p) } }; + return .{ .owner = b, .root = .{ .cwd_relative = b.dupePath(p) } }; } -pub fn pathGenerated(_: *Build, g: *const GeneratedFile) LazyPath { - return .{ .root = .{ .generated = g } }; +pub fn pathGenerated(b: *Build, g: *const GeneratedFile) LazyPath { + return .{ .owner = b, .root = .{ .generated = g } }; } // dirnameAllowEmpty is a variant of fs.path.dirname @@ -2131,6 +2131,7 @@ test dirnameAllowEmpty { /// A reference to an existing or future path. pub const LazyPath = struct { + owner: *std.Build, root: union(enum) { /// A source file path relative to build root. /// This should not be an absolute path, but in an older iteration of the zig build @@ -2177,6 +2178,7 @@ pub const LazyPath = struct { /// the dirname is not allowed to traverse outside of zig-cache. pub fn dirname(self: LazyPath) LazyPath { return .{ + .owner = self.owner, .root = switch (self.root) { .generated => |gen| .{ .generated_dirname = .{ .generated = gen, .up = 0 } }, .generated_dirname => |gen| .{ .generated_dirname = .{ .generated = gen.generated, .up = gen.up + 1 } }, @@ -2275,7 +2277,7 @@ pub const LazyPath = struct { (src_builder.cache_root.join(src_builder.allocator, &.{"."}) catch @panic("OOM")); const gen_step = gen.generated.step; - var p = getPath2(LazyPath{ .root = .{ .generated = gen.generated } }, src_builder, asking_step); + var p = getPath2(LazyPath{ .owner = self.owner, .root = .{ .generated = gen.generated } }, src_builder, asking_step); var i: usize = 0; while (i <= gen.up) : (i += 1) { // path is absolute. @@ -2314,7 +2316,8 @@ pub const LazyPath = struct { /// Duplicates the file source for a given builder. pub fn dupe(self: LazyPath, b: *Build) LazyPath { - return .{ .root = switch (self.root) { + // TODO(lacc97): no longer require `b` parameter + return .{ .owner = b, .root = switch (self.root) { .path => |p| .{ .path = b.dupePath(p) }, .cwd_relative => |p| .{ .cwd_relative = b.dupePath(p) }, .generated => |gen| .{ .generated = gen }, diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 9208aa1ec4a8..0992f02fedb5 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -271,8 +271,9 @@ pub const HeaderInstallation = union(enum) { // As a temporary workaround, we convert build root-relative paths to absolute paths. // If/when the build-root relative paths are updated to encode which build root they are // relative to, this workaround should be removed. + // TODO(lacc97): fix const duped_source: LazyPath = switch (self.source.root) { - .path => |root_rel| .{ .root = .{ .cwd_relative = b.pathFromRoot(root_rel) } }, + .path => |root_rel| .{ .owner = self.source.owner, .root = .{ .cwd_relative = b.pathFromRoot(root_rel) } }, else => self.source.dupe(b), }; @@ -312,8 +313,9 @@ pub const HeaderInstallation = union(enum) { // As a temporary workaround, we convert build root-relative paths to absolute paths. // If/when the build-root relative paths are updated to encode which build root they are // relative to, this workaround should be removed. + // TODO(lacc97): fix const duped_source: LazyPath = switch (self.source.root) { - .path => |root_rel| .{ .root = .{ .cwd_relative = b.pathFromRoot(root_rel) } }, + .path => |root_rel| .{ .owner = self.source.owner, .root = .{ .cwd_relative = b.pathFromRoot(root_rel) } }, else => self.source.dupe(b), }; From 15f54f1c999f3b6ec39d38e936905d7531d6b6c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Mon, 8 Apr 2024 22:52:08 +0100 Subject: [PATCH 06/14] std.Build.LazyPath: `dupe()` no longer requires a *std.Build parameter We can simply use the LazyPath's owner. --- lib/std/Build.zig | 30 +++++++++++++++++------------- lib/std/Build/Module.zig | 24 ++++++++++++------------ lib/std/Build/Step/CheckFile.zig | 2 +- lib/std/Build/Step/CheckObject.zig | 2 +- lib/std/Build/Step/Compile.zig | 21 +++++++++------------ lib/std/Build/Step/InstallDir.zig | 2 +- lib/std/Build/Step/InstallFile.zig | 2 +- lib/std/Build/Step/Run.zig | 4 ++-- lib/std/Build/Step/TranslateC.zig | 2 +- lib/std/Build/Step/WriteFile.zig | 2 +- 10 files changed, 46 insertions(+), 45 deletions(-) diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 0136bae6ac83..92aebd7a9b29 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -2314,21 +2314,25 @@ pub const LazyPath = struct { } } - /// Duplicates the file source for a given builder. - pub fn dupe(self: LazyPath, b: *Build) LazyPath { - // TODO(lacc97): no longer require `b` parameter - return .{ .owner = b, .root = switch (self.root) { - .path => |p| .{ .path = b.dupePath(p) }, - .cwd_relative => |p| .{ .cwd_relative = b.dupePath(p) }, - .generated => |gen| .{ .generated = gen }, - .generated_dirname => |gen| .{ - .generated_dirname = .{ - .generated = gen.generated, - .up = gen.up, + /// Duplicates the file source. + pub fn dupe(self: LazyPath) LazyPath { + return .{ + .owner = self.owner, + .root = switch (self.root) { + // TODO: do we really need to dupe path, cwd_relative? the LazyPath should + // already own its path + .path => |p| .{ .path = self.owner.dupePath(p) }, + .cwd_relative => |p| .{ .cwd_relative = self.owner.dupePath(p) }, + .generated => |gen| .{ .generated = gen }, + .generated_dirname => |gen| .{ + .generated_dirname = .{ + .generated = gen.generated, + .up = gen.up, + }, }, + .dependency => |dep| .{ .dependency = dep }, }, - .dependency => |dep| .{ .dependency = dep }, - } }; + }; } }; diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig index baccc88588af..964d46623b7e 100644 --- a/lib/std/Build/Module.zig +++ b/lib/std/Build/Module.zig @@ -91,7 +91,7 @@ pub const CSourceFile = struct { pub fn dupe(self: CSourceFile, b: *std.Build) CSourceFile { return .{ - .file = self.file.dupe(b), + .file = self.file.dupe(), .flags = b.dupeStrings(self.flags), }; } @@ -113,7 +113,7 @@ pub const RcSourceFile = struct { pub fn dupe(self: RcSourceFile, b: *std.Build) RcSourceFile { return .{ - .file = self.file.dupe(b), + .file = self.file.dupe(), .flags = b.dupeStrings(self.flags), }; } @@ -190,7 +190,7 @@ pub fn init(m: *Module, owner: *std.Build, options: CreateOptions, compile: ?*St m.* = .{ .owner = owner, .depending_steps = .{}, - .root_source_file = if (options.root_source_file) |lp| lp.dupe(owner) else null, + .root_source_file = if (options.root_source_file) |lp| lp.dupe() else null, .import_table = .{}, .resolved_target = options.target, .optimize = options.optimize, @@ -507,13 +507,13 @@ pub fn addWin32ResourceFile(m: *Module, source: RcSourceFile) void { pub fn addAssemblyFile(m: *Module, source: LazyPath) void { const b = m.owner; - m.link_objects.append(b.allocator, .{ .assembly_file = source.dupe(b) }) catch @panic("OOM"); + m.link_objects.append(b.allocator, .{ .assembly_file = source.dupe() }) catch @panic("OOM"); addLazyPathDependenciesOnly(m, source); } pub fn addObjectFile(m: *Module, object: LazyPath) void { const b = m.owner; - m.link_objects.append(b.allocator, .{ .static_path = object.dupe(b) }) catch @panic("OOM"); + m.link_objects.append(b.allocator, .{ .static_path = object.dupe() }) catch @panic("OOM"); addLazyPathDependenciesOnly(m, object); } @@ -529,19 +529,19 @@ pub fn linkLibrary(m: *Module, library: *Step.Compile) void { pub fn addAfterIncludePath(m: *Module, lazy_path: LazyPath) void { const b = m.owner; - m.include_dirs.append(b.allocator, .{ .path_after = lazy_path.dupe(b) }) catch @panic("OOM"); + m.include_dirs.append(b.allocator, .{ .path_after = lazy_path.dupe() }) catch @panic("OOM"); addLazyPathDependenciesOnly(m, lazy_path); } pub fn addSystemIncludePath(m: *Module, lazy_path: LazyPath) void { const b = m.owner; - m.include_dirs.append(b.allocator, .{ .path_system = lazy_path.dupe(b) }) catch @panic("OOM"); + m.include_dirs.append(b.allocator, .{ .path_system = lazy_path.dupe() }) catch @panic("OOM"); addLazyPathDependenciesOnly(m, lazy_path); } pub fn addIncludePath(m: *Module, lazy_path: LazyPath) void { const b = m.owner; - m.include_dirs.append(b.allocator, .{ .path = lazy_path.dupe(b) }) catch @panic("OOM"); + m.include_dirs.append(b.allocator, .{ .path = lazy_path.dupe() }) catch @panic("OOM"); addLazyPathDependenciesOnly(m, lazy_path); } @@ -553,21 +553,21 @@ pub fn addConfigHeader(m: *Module, config_header: *Step.ConfigHeader) void { pub fn addSystemFrameworkPath(m: *Module, directory_path: LazyPath) void { const b = m.owner; - m.include_dirs.append(b.allocator, .{ .framework_path_system = directory_path.dupe(b) }) catch + m.include_dirs.append(b.allocator, .{ .framework_path_system = directory_path.dupe() }) catch @panic("OOM"); addLazyPathDependenciesOnly(m, directory_path); } pub fn addFrameworkPath(m: *Module, directory_path: LazyPath) void { const b = m.owner; - m.include_dirs.append(b.allocator, .{ .framework_path = directory_path.dupe(b) }) catch + m.include_dirs.append(b.allocator, .{ .framework_path = directory_path.dupe() }) catch @panic("OOM"); addLazyPathDependenciesOnly(m, directory_path); } pub fn addLibraryPath(m: *Module, directory_path: LazyPath) void { const b = m.owner; - m.lib_paths.append(b.allocator, directory_path.dupe(b)) catch @panic("OOM"); + m.lib_paths.append(b.allocator, directory_path.dupe()) catch @panic("OOM"); addLazyPathDependenciesOnly(m, directory_path); } @@ -584,7 +584,7 @@ pub fn addRPath(m: *Module, directory_path: LazyPath) void { }, else => {}, } - m.rpaths.append(b.allocator, .{ .lazy_path = directory_path.dupe(b) }) catch @panic("OOM"); + m.rpaths.append(b.allocator, .{ .lazy_path = directory_path.dupe() }) catch @panic("OOM"); addLazyPathDependenciesOnly(m, directory_path); } diff --git a/lib/std/Build/Step/CheckFile.zig b/lib/std/Build/Step/CheckFile.zig index 19d697a3b65c..861259276a6d 100644 --- a/lib/std/Build/Step/CheckFile.zig +++ b/lib/std/Build/Step/CheckFile.zig @@ -34,7 +34,7 @@ pub fn create( .owner = owner, .makeFn = make, }), - .source = source.dupe(owner), + .source = source.dupe(), .expected_matches = owner.dupeStrings(options.expected_matches), .expected_exact = options.expected_exact, }; diff --git a/lib/std/Build/Step/CheckObject.zig b/lib/std/Build/Step/CheckObject.zig index c39a487649bc..5311f1985b3e 100644 --- a/lib/std/Build/Step/CheckObject.zig +++ b/lib/std/Build/Step/CheckObject.zig @@ -34,7 +34,7 @@ pub fn create( .owner = owner, .makeFn = make, }), - .source = source.dupe(owner), + .source = source.dupe(), .checks = std.ArrayList(Check).init(gpa), .obj_format = obj_format, }; diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 0992f02fedb5..478eeb741ee6 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -274,7 +274,7 @@ pub const HeaderInstallation = union(enum) { // TODO(lacc97): fix const duped_source: LazyPath = switch (self.source.root) { .path => |root_rel| .{ .owner = self.source.owner, .root = .{ .cwd_relative = b.pathFromRoot(root_rel) } }, - else => self.source.dupe(b), + else => self.source.dupe(), }; return .{ @@ -316,7 +316,7 @@ pub const HeaderInstallation = union(enum) { // TODO(lacc97): fix const duped_source: LazyPath = switch (self.source.root) { .path => |root_rel| .{ .owner = self.source.owner, .root = .{ .cwd_relative = b.pathFromRoot(root_rel) } }, - else => self.source.dupe(b), + else => self.source.dupe(), }; return .{ @@ -427,7 +427,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { self.root_module.init(owner, options.root_module, self); if (options.zig_lib_dir) |lp| { - self.zig_lib_dir = lp.dupe(self.step.owner); + self.zig_lib_dir = lp.dupe(); lp.addStepDependencies(&self.step); } @@ -435,7 +435,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { // gets embedded, so for any other target the manifest file is just ignored. if (target.ofmt == .coff) { if (options.win32_manifest) |lp| { - self.win32_manifest = lp.dupe(self.step.owner); + self.win32_manifest = lp.dupe(); lp.addStepDependencies(&self.step); } } @@ -478,7 +478,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { pub fn installHeader(cs: *Compile, source: LazyPath, dest_rel_path: []const u8) void { const b = cs.step.owner; const installation: HeaderInstallation = .{ .file = .{ - .source = source.dupe(b), + .source = source.dupe(), .dest_rel_path = b.dupePath(dest_rel_path), } }; cs.installed_headers.append(installation) catch @panic("OOM"); @@ -497,7 +497,7 @@ pub fn installHeadersDirectory( ) void { const b = cs.step.owner; const installation: HeaderInstallation = .{ .directory = .{ - .source = source.dupe(b), + .source = source.dupe(), .dest_rel_path = b.dupePath(dest_rel_path), .options = options.dupe(b), } }; @@ -582,14 +582,12 @@ pub fn checkObject(self: *Compile) *Step.CheckObject { pub const setLinkerScriptPath = setLinkerScript; pub fn setLinkerScript(self: *Compile, source: LazyPath) void { - const b = self.step.owner; - self.linker_script = source.dupe(b); + self.linker_script = source.dupe(); source.addStepDependencies(&self.step); } pub fn setVersionScript(self: *Compile, source: LazyPath) void { - const b = self.step.owner; - self.version_script = source.dupe(b); + self.version_script = source.dupe(); source.addStepDependencies(&self.step); } @@ -826,8 +824,7 @@ pub fn setVerboseCC(self: *Compile, value: bool) void { } pub fn setLibCFile(self: *Compile, libc_file: ?LazyPath) void { - const b = self.step.owner; - self.libc_file = if (libc_file) |f| f.dupe(b) else null; + self.libc_file = if (libc_file) |f| f.dupe() else null; } fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath { diff --git a/lib/std/Build/Step/InstallDir.zig b/lib/std/Build/Step/InstallDir.zig index f29a6ef2b8fa..2b9bbd96c590 100644 --- a/lib/std/Build/Step/InstallDir.zig +++ b/lib/std/Build/Step/InstallDir.zig @@ -31,7 +31,7 @@ pub const Options = struct { fn dupe(self: Options, b: *std.Build) Options { return .{ - .source_dir = self.source_dir.dupe(b), + .source_dir = self.source_dir.dupe(), .install_dir = self.install_dir.dupe(b), .install_subdir = b.dupe(self.install_subdir), .exclude_extensions = b.dupeStrings(self.exclude_extensions), diff --git a/lib/std/Build/Step/InstallFile.zig b/lib/std/Build/Step/InstallFile.zig index 1ad9fa7d5d79..ac9ad64ebc5b 100644 --- a/lib/std/Build/Step/InstallFile.zig +++ b/lib/std/Build/Step/InstallFile.zig @@ -28,7 +28,7 @@ pub fn create( .owner = owner, .makeFn = make, }), - .source = source.dupe(owner), + .source = source.dupe(), .dir = dir.dupe(owner), .dest_rel_path = owner.dupePath(dest_rel_path), }; diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index 7e608cc4fb63..26195c20b57d 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -246,7 +246,7 @@ pub fn addPrefixedFileArg(self: *Run, prefix: []const u8, lp: std.Build.LazyPath const prefixed_file_source: PrefixedLazyPath = .{ .prefix = b.dupe(prefix), - .lazy_path = lp.dupe(b), + .lazy_path = lp.dupe(), }; self.argv.append(.{ .lazy_path = prefixed_file_source }) catch @panic("OOM"); lp.addStepDependencies(&self.step); @@ -267,7 +267,7 @@ pub fn addPrefixedDirectoryArg(self: *Run, prefix: []const u8, directory_source: const prefixed_directory_source: PrefixedLazyPath = .{ .prefix = b.dupe(prefix), - .lazy_path = directory_source.dupe(b), + .lazy_path = directory_source.dupe(), }; self.argv.append(.{ .directory_source = prefixed_directory_source }) catch @panic("OOM"); directory_source.addStepDependencies(&self.step); diff --git a/lib/std/Build/Step/TranslateC.zig b/lib/std/Build/Step/TranslateC.zig index a2307c4b37cd..c92b5da952c7 100644 --- a/lib/std/Build/Step/TranslateC.zig +++ b/lib/std/Build/Step/TranslateC.zig @@ -28,7 +28,7 @@ pub const Options = struct { pub fn create(owner: *std.Build, options: Options) *TranslateC { const self = owner.allocator.create(TranslateC) catch @panic("OOM"); - const source = options.root_source_file.dupe(owner); + const source = options.root_source_file.dupe(); self.* = TranslateC{ .step = Step.init(.{ .id = .translate_c, diff --git a/lib/std/Build/Step/WriteFile.zig b/lib/std/Build/Step/WriteFile.zig index 166c762c7e18..2d037b24a926 100644 --- a/lib/std/Build/Step/WriteFile.zig +++ b/lib/std/Build/Step/WriteFile.zig @@ -139,7 +139,7 @@ pub fn addCopyDirectory( const gpa = b.allocator; const dir = gpa.create(Directory) catch @panic("OOM"); dir.* = .{ - .source = source.dupe(b), + .source = source.dupe(), .sub_path = b.dupePath(sub_path), .options = options.dupe(b), .generated_dir = .{ .step = &wf.step }, From 80e89369c7b9b762f093bd2a4836ec42abe9498a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Mon, 8 Apr 2024 22:55:37 +0100 Subject: [PATCH 07/14] std.Build.Dependency: add standalone test to exercise code paths I couldn't find any other place where Dependency.path() was being used, so I added a standalone test that uses it, in addition to some of the other Dependency functions for a somewhat more thorough test of how dependencies might be used. --- test/standalone/build.zig.zon | 3 +++ test/standalone/build_dep/build.zig | 34 +++++++++++++++++++++++++ test/standalone/build_dep/build.zig.zon | 7 +++++ test/standalone/build_dep/dep/build.zig | 16 ++++++++++++ test/standalone/build_dep/dep/main1.zig | 1 + test/standalone/build_dep/dep/main2.zig | 1 + test/standalone/build_dep/dep/root.zig | 1 + test/standalone/build_dep/main3.zig | 5 ++++ 8 files changed, 68 insertions(+) create mode 100644 test/standalone/build_dep/build.zig create mode 100644 test/standalone/build_dep/build.zig.zon create mode 100644 test/standalone/build_dep/dep/build.zig create mode 100644 test/standalone/build_dep/dep/main1.zig create mode 100644 test/standalone/build_dep/dep/main2.zig create mode 100644 test/standalone/build_dep/dep/root.zig create mode 100644 test/standalone/build_dep/main3.zig diff --git a/test/standalone/build.zig.zon b/test/standalone/build.zig.zon index 8b59f261179e..e9cb52a75e67 100644 --- a/test/standalone/build.zig.zon +++ b/test/standalone/build.zig.zon @@ -155,6 +155,9 @@ .install_headers = .{ .path = "install_headers", }, + .build_dep = .{ + .path = "build_dep", + }, }, .paths = .{ "build.zig", diff --git a/test/standalone/build_dep/build.zig b/test/standalone/build_dep/build.zig new file mode 100644 index 000000000000..9ddb0b28e4c3 --- /dev/null +++ b/test/standalone/build_dep/build.zig @@ -0,0 +1,34 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.host; + const optimize = .Debug; + + const test_step = b.step("test", "Test it"); + + const dependency = b.dependency("dep", .{}); + + const dep_main1 = dependency.artifact("main1"); + const dep_main1_run = b.addRunArtifact(dep_main1); + + const dep_main2 = b.addExecutable(.{ + .name = "main2", + .root_source_file = dependency.path("main2.zig"), + .target = target, + .optimize = optimize, + }); + const dep_main2_run = b.addRunArtifact(dep_main2); + + const dep_main3 = b.addExecutable(.{ + .name = "main3", + .root_source_file = b.path("main3.zig"), + .target = target, + .optimize = optimize, + }); + dep_main3.root_module.addImport("dep_root", dependency.module("root")); + const dep_main3_run = b.addRunArtifact(dep_main3); + + test_step.dependOn(&dep_main1_run.step); + test_step.dependOn(&dep_main2_run.step); + test_step.dependOn(&dep_main3_run.step); +} diff --git a/test/standalone/build_dep/build.zig.zon b/test/standalone/build_dep/build.zig.zon new file mode 100644 index 000000000000..5ad97b14ec1e --- /dev/null +++ b/test/standalone/build_dep/build.zig.zon @@ -0,0 +1,7 @@ +.{ + .name = "build_dep", + .version = "0.0.0", + .paths = .{ "build.zig", "build.zig.zon", "dep" }, + .dependencies = .{ + .dep = .{ .path = "dep" } }, +} diff --git a/test/standalone/build_dep/dep/build.zig b/test/standalone/build_dep/dep/build.zig new file mode 100644 index 000000000000..c33faa524da4 --- /dev/null +++ b/test/standalone/build_dep/dep/build.zig @@ -0,0 +1,16 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + _ = b.addModule("root", .{ + .root_source_file = b.path("root.zig"), + .target = b.host, + .optimize = .Debug, + }); + const exe = b.addExecutable(.{ + .name = "main1", + .root_source_file = b.path("main1.zig"), + .target = b.host, + .optimize = .Debug, + }); + b.installArtifact(exe); +} diff --git a/test/standalone/build_dep/dep/main1.zig b/test/standalone/build_dep/dep/main1.zig new file mode 100644 index 000000000000..902b554db075 --- /dev/null +++ b/test/standalone/build_dep/dep/main1.zig @@ -0,0 +1 @@ +pub fn main() void {} diff --git a/test/standalone/build_dep/dep/main2.zig b/test/standalone/build_dep/dep/main2.zig new file mode 100644 index 000000000000..902b554db075 --- /dev/null +++ b/test/standalone/build_dep/dep/main2.zig @@ -0,0 +1 @@ +pub fn main() void {} diff --git a/test/standalone/build_dep/dep/root.zig b/test/standalone/build_dep/dep/root.zig new file mode 100644 index 000000000000..87d61fa63e88 --- /dev/null +++ b/test/standalone/build_dep/dep/root.zig @@ -0,0 +1 @@ +pub fn foo() void {} diff --git a/test/standalone/build_dep/main3.zig b/test/standalone/build_dep/main3.zig new file mode 100644 index 000000000000..484dfae10bdc --- /dev/null +++ b/test/standalone/build_dep/main3.zig @@ -0,0 +1,5 @@ +const dep = @import("dep_root"); + +pub fn main() void { + dep.foo(); +} From 62c740f8a4ef70dffa82b366268d0807a98661fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Mon, 8 Apr 2024 22:58:49 +0100 Subject: [PATCH 08/14] std.Build.Dependency: update `path()` function for new LazyPath --- lib/std/Build.zig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 92aebd7a9b29..52fcfc1b014a 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -1814,9 +1814,12 @@ pub const Dependency = struct { pub fn path(d: *Dependency, sub_path: []const u8) LazyPath { return .{ - .dependency = .{ - .dependency = d, - .sub_path = sub_path, + .owner = d.builder, + .root = .{ + .dependency = .{ + .dependency = d, + .sub_path = sub_path, + }, }, }; } From 05f1a08c60e2e8f0f703cadaa182c954753a640d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Mon, 8 Apr 2024 23:08:36 +0100 Subject: [PATCH 09/14] std.Build.LazyPath: expunge `dependency` union field The use case is subsumed by the `path` union field. --- lib/std/Build.zig | 37 ++++++----------------------- lib/std/Build/Step/ConfigHeader.zig | 1 - 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 52fcfc1b014a..ece3b0e95470 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -1816,10 +1816,7 @@ pub const Dependency = struct { return .{ .owner = d.builder, .root = .{ - .dependency = .{ - .dependency = d, - .sub_path = sub_path, - }, + .path = sub_path, }, }; } @@ -2163,11 +2160,6 @@ pub const LazyPath = struct { /// which `zig build` was invoked. /// Use of this tag indicates a dependency on the host system. cwd_relative: []const u8, - - dependency: struct { - dependency: *Dependency, - sub_path: []const u8, - }, }, pub const relative = @compileError("use std.Build.path() instead"); @@ -2219,17 +2211,6 @@ pub const LazyPath = struct { } }, }, - .dependency => |dep| .{ .dependency = .{ - .dependency = dep.dependency, - .sub_path = dirnameAllowEmpty(dep.sub_path) orelse { - dumpBadDirnameHelp(null, null, - \\dirname() attempted to traverse outside the dependency root. - \\This is not allowed. - \\ - , .{}) catch {}; - @panic("misconfigured build script"); - }, - } }, }, }; } @@ -2238,17 +2219,17 @@ pub const LazyPath = struct { /// Either returns the path or `"generated"`. pub fn getDisplayName(self: LazyPath) []const u8 { return switch (self.root) { + // TODO: display string for what used to be `dependency` case? .path, .cwd_relative => self.root.path, .generated => "generated", .generated_dirname => "generated", - .dependency => "dependency", }; } /// Adds dependencies this file source implies to the given step. pub fn addStepDependencies(self: LazyPath, other_step: *Step) void { switch (self.root) { - .path, .cwd_relative, .dependency => {}, + .path, .cwd_relative => {}, .generated => |gen| other_step.dependOn(gen.step), .generated_dirname => |gen| other_step.dependOn(gen.generated.step), } @@ -2267,7 +2248,10 @@ pub const LazyPath = struct { /// run that is asking for the path. pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 { switch (self.root) { - .path => |p| return src_builder.pathFromRoot(p), + .path => |p| { + if (self.owner != src_builder) assert(self.owner.build_root.path != null); + return self.owner.pathFromRoot(p); + }, .cwd_relative => |p| return src_builder.pathFromCwd(p), .generated => |gen| return gen.path orelse { std.debug.getStderrMutex().lock(); @@ -2308,12 +2292,6 @@ pub const LazyPath = struct { } return p; }, - .dependency => |dep| { - return dep.dependency.builder.pathJoin(&[_][]const u8{ - dep.dependency.builder.build_root.path.?, - dep.sub_path, - }); - }, } } @@ -2333,7 +2311,6 @@ pub const LazyPath = struct { .up = gen.up, }, }, - .dependency => |dep| .{ .dependency = dep }, }, }; } diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig index eac706acff6b..dc5db98768cb 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -61,7 +61,6 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader { .path => |path| path, .generated, .generated_dirname => break :default_include_path, .cwd_relative => |sub_path| sub_path, - .dependency => |dependency| dependency.sub_path, }; const basename = std.fs.path.basename(sub_path); if (std.mem.endsWith(u8, basename, ".h.in")) { From 973a12992aa3f7851f67054a313da1614a7cfb9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Mon, 8 Apr 2024 23:41:37 +0100 Subject: [PATCH 10/14] std.Build.LazyPath: pull out `path` as a top-level field This commit also renames the union fields `path` -> `build` and `cwd_relative` -> `cwd`. Now, the struct field `root` represents from whence the `path` field should be evaluated. At the moment, I haven't touched the `generated` and `generated_dirname` fields so LazyPath looks a bit awkward at the moment. The other fields will likely need a bit more work so they will go as a separate commit. --- lib/std/Build.zig | 133 ++++++++++++++-------------- lib/std/Build/Module.zig | 6 +- lib/std/Build/Step/Compile.zig | 30 +------ lib/std/Build/Step/ConfigHeader.zig | 3 +- 4 files changed, 74 insertions(+), 98 deletions(-) diff --git a/lib/std/Build.zig b/lib/std/Build.zig index ece3b0e95470..009210a1f814 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -1813,12 +1813,7 @@ pub const Dependency = struct { } pub fn path(d: *Dependency, sub_path: []const u8) LazyPath { - return .{ - .owner = d.builder, - .root = .{ - .path = sub_path, - }, - }; + return .{ .owner = d.builder, .path = sub_path, .root = .build }; } }; @@ -2086,17 +2081,16 @@ pub const GeneratedFile = struct { }; pub fn path(b: *Build, p: []const u8) LazyPath { - // TODO: absolute paths - return .{ .owner = b, .root = .{ .path = b.dupePath(p) } }; + // TODO(lacc97): absolute paths + return .{ .owner = b, .path = b.dupePath(p), .root = .build }; } pub fn pathCwd(b: *Build, p: []const u8) LazyPath { - // TODO: absolute paths? - return .{ .owner = b, .root = .{ .cwd_relative = b.dupePath(p) } }; + return .{ .owner = b, .path = b.dupePath(p), .root = .cwd }; } pub fn pathGenerated(b: *Build, g: *const GeneratedFile) LazyPath { - return .{ .owner = b, .root = .{ .generated = g } }; + return .{ .owner = b, .path = "", .root = .{ .generated = g } }; } // dirnameAllowEmpty is a variant of fs.path.dirname @@ -2132,11 +2126,22 @@ test dirnameAllowEmpty { /// A reference to an existing or future path. pub const LazyPath = struct { owner: *std.Build, + + /// A path relative to `root`. + path: []const u8, + + /// root: union(enum) { - /// A source file path relative to build root. - /// This should not be an absolute path, but in an older iteration of the zig build - /// system API, it was allowed to be absolute. Absolute paths should use `cwd_relative`. - path: []const u8, + /// The path is evaluated relative to the owner build root. + build, + + /// The path is evaluated relative to the current working directory of the build runner. + /// Only for this tag is the path allowed to be absolute. + /// This is uncommon but used for system environment paths such as `--zig-lib-dir` which + /// ignore the file system path of build.zig and instead are relative to the directory from + /// which `zig build` was invoked. + /// Use of this tag indicates a dependency on the host system. + cwd, /// A file that is generated by an interface. Those files usually are /// not available until built by a build step. @@ -2152,14 +2157,6 @@ pub const LazyPath = struct { /// 1 means the parent of that directory, and so on. up: usize, }, - - /// An absolute path or a path relative to the current working directory of - /// the build runner process. - /// This is uncommon but used for system environment paths such as `--zig-lib-dir` which - /// ignore the file system path of build.zig and instead are relative to the directory from - /// which `zig build` was invoked. - /// Use of this tag indicates a dependency on the host system. - cwd_relative: []const u8, }, pub const relative = @compileError("use std.Build.path() instead"); @@ -2174,42 +2171,48 @@ pub const LazyPath = struct { pub fn dirname(self: LazyPath) LazyPath { return .{ .owner = self.owner, - .root = switch (self.root) { - .generated => |gen| .{ .generated_dirname = .{ .generated = gen, .up = 0 } }, - .generated_dirname => |gen| .{ .generated_dirname = .{ .generated = gen.generated, .up = gen.up + 1 } }, - .path => |p| .{ - .path = dirnameAllowEmpty(p) orelse { + .path = switch (self.root) { + .generated, .generated_dirname => self.path, // TODO(lacc97): do this the right way by path manipulation + .build => dirnameAllowEmpty(self.path) orelse { + dumpBadDirnameHelp(null, null, + \\dirname() attempted to traverse outside the build root. + \\This is not allowed. + \\ + , .{}) catch {}; + @panic("misconfigured build script"); + }, + .cwd => dirnameAllowEmpty(self.path) orelse { + // If we get null, it means one of two things: + // - p was absolute, and is now root + // - p was relative, and is now "" + // In either case, the build script tried to go too far + // and we should panic. + if (fs.path.isAbsolute(self.path)) { + dumpBadDirnameHelp(null, null, + \\dirname() attempted to traverse outside the root. + \\No more directories left to go up. + \\ + , .{}) catch {}; + @panic("misconfigured build script"); + } else { dumpBadDirnameHelp(null, null, - \\dirname() attempted to traverse outside the build root. + \\dirname() attempted to traverse outside the current working directory. \\This is not allowed. \\ , .{}) catch {}; @panic("misconfigured build script"); - }, + } }, - .cwd_relative => |p| .{ - .cwd_relative = dirnameAllowEmpty(p) orelse { - // If we get null, it means one of two things: - // - p was absolute, and is now root - // - p was relative, and is now "" - // In either case, the build script tried to go too far - // and we should panic. - if (fs.path.isAbsolute(p)) { - dumpBadDirnameHelp(null, null, - \\dirname() attempted to traverse outside the root. - \\No more directories left to go up. - \\ - , .{}) catch {}; - @panic("misconfigured build script"); - } else { - dumpBadDirnameHelp(null, null, - \\dirname() attempted to traverse outside the current working directory. - \\This is not allowed. - \\ - , .{}) catch {}; - @panic("misconfigured build script"); - } - }, + }, + .root = switch (self.root) { + .build => .build, + .cwd => .cwd, + // TODO(lacc97): do this the right way by path manipulation (`root` field should not change as a result of calling `dirname`) + .generated => |gen| .{ + .generated_dirname = .{ .generated = gen, .up = 0 }, + }, + .generated_dirname => |gen| .{ + .generated_dirname = .{ .generated = gen.generated, .up = gen.up + 1 }, }, }, }; @@ -2219,8 +2222,8 @@ pub const LazyPath = struct { /// Either returns the path or `"generated"`. pub fn getDisplayName(self: LazyPath) []const u8 { return switch (self.root) { - // TODO: display string for what used to be `dependency` case? - .path, .cwd_relative => self.root.path, + // TODO: different display string for what used to be `dependency` case? + .build, .cwd => self.path, .generated => "generated", .generated_dirname => "generated", }; @@ -2229,7 +2232,7 @@ pub const LazyPath = struct { /// Adds dependencies this file source implies to the given step. pub fn addStepDependencies(self: LazyPath, other_step: *Step) void { switch (self.root) { - .path, .cwd_relative => {}, + .build, .cwd => {}, .generated => |gen| other_step.dependOn(gen.step), .generated_dirname => |gen| other_step.dependOn(gen.generated.step), } @@ -2248,23 +2251,23 @@ pub const LazyPath = struct { /// run that is asking for the path. pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 { switch (self.root) { - .path => |p| { + .build => { if (self.owner != src_builder) assert(self.owner.build_root.path != null); - return self.owner.pathFromRoot(p); + return self.owner.pathFromRoot(self.path); }, - .cwd_relative => |p| return src_builder.pathFromCwd(p), + .cwd => return src_builder.pathFromCwd(self.path), .generated => |gen| return gen.path orelse { std.debug.getStderrMutex().lock(); const stderr = std.io.getStdErr(); dumpBadGetPathHelp(gen.step, stderr, src_builder, asking_step) catch {}; @panic("misconfigured build script"); }, - .generated_dirname => |gen| { + .generated_dirname => |gen| { // TODO(lacc97): get rid of this const cache_root_path = src_builder.cache_root.path orelse (src_builder.cache_root.join(src_builder.allocator, &.{"."}) catch @panic("OOM")); const gen_step = gen.generated.step; - var p = getPath2(LazyPath{ .owner = self.owner, .root = .{ .generated = gen.generated } }, src_builder, asking_step); + var p = getPath2(LazyPath{ .owner = self.owner, .path = self.path, .root = .{ .generated = gen.generated } }, src_builder, asking_step); var i: usize = 0; while (i <= gen.up) : (i += 1) { // path is absolute. @@ -2299,11 +2302,11 @@ pub const LazyPath = struct { pub fn dupe(self: LazyPath) LazyPath { return .{ .owner = self.owner, + // TODO(lacc97): do we really need to dupe path, cwd_relative? the LazyPath should already own its path + .path = self.owner.dupePath(self.path), .root = switch (self.root) { - // TODO: do we really need to dupe path, cwd_relative? the LazyPath should - // already own its path - .path => |p| .{ .path = self.owner.dupePath(p) }, - .cwd_relative => |p| .{ .cwd_relative = self.owner.dupePath(p) }, + .build => .build, + .cwd => .cwd, .generated => |gen| .{ .generated = gen }, .generated_dirname => |gen| .{ .generated_dirname = .{ diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig index 964d46623b7e..2f1cea658029 100644 --- a/lib/std/Build/Module.zig +++ b/lib/std/Build/Module.zig @@ -574,10 +574,10 @@ pub fn addLibraryPath(m: *Module, directory_path: LazyPath) void { pub fn addRPath(m: *Module, directory_path: LazyPath) void { const b = m.owner; switch (directory_path.root) { - .path, .cwd_relative => |path| { + .build, .cwd => { // TODO: remove this check after people upgrade and stop expecting it to work - if (std.mem.startsWith(u8, path, "@executable_path") or - std.mem.startsWith(u8, path, "@loader_path")) + if (std.mem.startsWith(u8, directory_path.path, "@executable_path") or + std.mem.startsWith(u8, directory_path.path, "@loader_path")) { @panic("this function is for adding directory paths. It does not support special rpaths. use addRPathSpecial for that."); } diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 478eeb741ee6..37be2875a992 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -264,21 +264,8 @@ pub const HeaderInstallation = union(enum) { dest_rel_path: []const u8, pub fn dupe(self: File, b: *std.Build) File { - // 'path' lazy paths are relative to the build root of some step, inferred from the step - // in which they are used. This means that we can't dupe such paths, because they may - // come from dependencies with their own build roots and duping the paths as is might - // cause the build script to search for the file relative to the wrong root. - // As a temporary workaround, we convert build root-relative paths to absolute paths. - // If/when the build-root relative paths are updated to encode which build root they are - // relative to, this workaround should be removed. - // TODO(lacc97): fix - const duped_source: LazyPath = switch (self.source.root) { - .path => |root_rel| .{ .owner = self.source.owner, .root = .{ .cwd_relative = b.pathFromRoot(root_rel) } }, - else => self.source.dupe(), - }; - return .{ - .source = duped_source, + .source = self.source.dupe(), .dest_rel_path = b.dupePath(self.dest_rel_path), }; } @@ -306,21 +293,8 @@ pub const HeaderInstallation = union(enum) { }; pub fn dupe(self: Directory, b: *std.Build) Directory { - // 'path' lazy paths are relative to the build root of some step, inferred from the step - // in which they are used. This means that we can't dupe such paths, because they may - // come from dependencies with their own build roots and duping the paths as is might - // cause the build script to search for the file relative to the wrong root. - // As a temporary workaround, we convert build root-relative paths to absolute paths. - // If/when the build-root relative paths are updated to encode which build root they are - // relative to, this workaround should be removed. - // TODO(lacc97): fix - const duped_source: LazyPath = switch (self.source.root) { - .path => |root_rel| .{ .owner = self.source.owner, .root = .{ .cwd_relative = b.pathFromRoot(root_rel) } }, - else => self.source.dupe(), - }; - return .{ - .source = duped_source, + .source = self.source.dupe(), .dest_rel_path = b.dupePath(self.dest_rel_path), .options = self.options.dupe(b), }; diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig index dc5db98768cb..a853e53fe502 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -58,9 +58,8 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader { if (options.style.getPath()) |s| default_include_path: { const sub_path = switch (s.root) { - .path => |path| path, + .build, .cwd => s.path, .generated, .generated_dirname => break :default_include_path, - .cwd_relative => |sub_path| sub_path, }; const basename = std.fs.path.basename(sub_path); if (std.mem.endsWith(u8, basename, ".h.in")) { From ecbf58636cbeffed071731d0a523047c74a9e06d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Tue, 9 Apr 2024 00:21:41 +0100 Subject: [PATCH 11/14] Fix formatting --- test/standalone/build_dep/build.zig.zon | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/standalone/build_dep/build.zig.zon b/test/standalone/build_dep/build.zig.zon index 5ad97b14ec1e..e4533ddf9030 100644 --- a/test/standalone/build_dep/build.zig.zon +++ b/test/standalone/build_dep/build.zig.zon @@ -2,6 +2,5 @@ .name = "build_dep", .version = "0.0.0", .paths = .{ "build.zig", "build.zig.zon", "dep" }, - .dependencies = .{ - .dep = .{ .path = "dep" } }, + .dependencies = .{ .dep = .{ .path = "dep" } }, } From f0b258c594d3bdbaa6c03c73d21df99281702753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Tue, 9 Apr 2024 18:34:11 +0100 Subject: [PATCH 12/14] std.Build.Step.ObjCopy: use pathGenerated() function --- lib/std/Build/Step/ObjCopy.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/Build/Step/ObjCopy.zig b/lib/std/Build/Step/ObjCopy.zig index ddd56833c04b..4d5d7a2e6931 100644 --- a/lib/std/Build/Step/ObjCopy.zig +++ b/lib/std/Build/Step/ObjCopy.zig @@ -84,7 +84,7 @@ pub fn create( pub const getOutputSource = getOutput; pub fn getOutput(self: *const ObjCopy) std.Build.LazyPath { - return .{ .generated = &self.output_file }; + return self.step.owner.pathGenerated(&self.output_file); } pub fn getOutputSeparatedDebug(self: *const ObjCopy) ?std.Build.LazyPath { return if (self.output_file_debug) |*file| .{ .generated = file } else null; From f3f77e6c0e743a8c97bb74206bbcbe7735b2300e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Tue, 9 Apr 2024 18:46:09 +0100 Subject: [PATCH 13/14] std.Build.LazyPath: merge generated and generated_dirname tags This slightly simplifies the implementation. --- lib/std/Build.zig | 49 +++++++++++------------------ lib/std/Build/Step/ConfigHeader.zig | 2 +- 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 009210a1f814..53cc44470cd0 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -2090,7 +2090,7 @@ pub fn pathCwd(b: *Build, p: []const u8) LazyPath { } pub fn pathGenerated(b: *Build, g: *const GeneratedFile) LazyPath { - return .{ .owner = b, .path = "", .root = .{ .generated = g } }; + return .{ .owner = b, .path = "", .root = .{ .generated = .{ .generated = g, .up = 0 } } }; } // dirnameAllowEmpty is a variant of fs.path.dirname @@ -2143,18 +2143,14 @@ pub const LazyPath = struct { /// Use of this tag indicates a dependency on the host system. cwd, - /// A file that is generated by an interface. Those files usually are + /// A file that is generated by an interface or its parent directory. Those files usually are /// not available until built by a build step. - generated: *const GeneratedFile, - - /// One of the parent directories of a file generated by an interface. - /// The path is not available until built by a build step. - generated_dirname: struct { + generated: struct { generated: *const GeneratedFile, /// The number of parent directories to go up. - /// 0 means the directory of the generated file, - /// 1 means the parent of that directory, and so on. + /// 0 means the generated file, + /// 1 means the parent of the generated file, and so on. up: usize, }, }, @@ -2172,7 +2168,7 @@ pub const LazyPath = struct { return .{ .owner = self.owner, .path = switch (self.root) { - .generated, .generated_dirname => self.path, // TODO(lacc97): do this the right way by path manipulation + .generated => self.path, // TODO(lacc97): do this the right way by path manipulation .build => dirnameAllowEmpty(self.path) orelse { dumpBadDirnameHelp(null, null, \\dirname() attempted to traverse outside the build root. @@ -2209,10 +2205,7 @@ pub const LazyPath = struct { .cwd => .cwd, // TODO(lacc97): do this the right way by path manipulation (`root` field should not change as a result of calling `dirname`) .generated => |gen| .{ - .generated_dirname = .{ .generated = gen, .up = 0 }, - }, - .generated_dirname => |gen| .{ - .generated_dirname = .{ .generated = gen.generated, .up = gen.up + 1 }, + .generated = .{ .generated = gen.generated, .up = gen.up + 1 }, }, }, }; @@ -2225,7 +2218,6 @@ pub const LazyPath = struct { // TODO: different display string for what used to be `dependency` case? .build, .cwd => self.path, .generated => "generated", - .generated_dirname => "generated", }; } @@ -2233,8 +2225,7 @@ pub const LazyPath = struct { pub fn addStepDependencies(self: LazyPath, other_step: *Step) void { switch (self.root) { .build, .cwd => {}, - .generated => |gen| other_step.dependOn(gen.step), - .generated_dirname => |gen| other_step.dependOn(gen.generated.step), + .generated => |gen| other_step.dependOn(gen.generated.step), } } @@ -2256,20 +2247,19 @@ pub const LazyPath = struct { return self.owner.pathFromRoot(self.path); }, .cwd => return src_builder.pathFromCwd(self.path), - .generated => |gen| return gen.path orelse { - std.debug.getStderrMutex().lock(); - const stderr = std.io.getStdErr(); - dumpBadGetPathHelp(gen.step, stderr, src_builder, asking_step) catch {}; - @panic("misconfigured build script"); - }, - .generated_dirname => |gen| { // TODO(lacc97): get rid of this + .generated => |gen| { // TODO(lacc97): get rid of this const cache_root_path = src_builder.cache_root.path orelse (src_builder.cache_root.join(src_builder.allocator, &.{"."}) catch @panic("OOM")); const gen_step = gen.generated.step; - var p = getPath2(LazyPath{ .owner = self.owner, .path = self.path, .root = .{ .generated = gen.generated } }, src_builder, asking_step); + var p = gen.generated.path orelse { + std.debug.getStderrMutex().lock(); + const stderr = std.io.getStdErr(); + dumpBadGetPathHelp(gen.generated.step, stderr, src_builder, asking_step) catch {}; + @panic("misconfigured build script"); + }; var i: usize = 0; - while (i <= gen.up) : (i += 1) { + while (i < gen.up) : (i += 1) { // path is absolute. // dirname will return null only if we're at root. // Typically, we'll stop well before that at the cache root. @@ -2282,7 +2272,7 @@ pub const LazyPath = struct { @panic("misconfigured build script"); }; - if (mem.eql(u8, p, cache_root_path) and i < gen.up) { + if (mem.eql(u8, p, cache_root_path) and (i + 1) < gen.up) { // If we hit the cache root and there's still more to go, // the script attempted to go too far. dumpBadDirnameHelp(gen_step, asking_step, @@ -2307,9 +2297,8 @@ pub const LazyPath = struct { .root = switch (self.root) { .build => .build, .cwd => .cwd, - .generated => |gen| .{ .generated = gen }, - .generated_dirname => |gen| .{ - .generated_dirname = .{ + .generated => |gen| .{ + .generated = .{ .generated = gen.generated, .up = gen.up, }, diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig index a853e53fe502..784c5750128b 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -59,7 +59,7 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader { if (options.style.getPath()) |s| default_include_path: { const sub_path = switch (s.root) { .build, .cwd => s.path, - .generated, .generated_dirname => break :default_include_path, + .generated => break :default_include_path, }; const basename = std.fs.path.basename(sub_path); if (std.mem.endsWith(u8, basename, ".h.in")) { From 040112b9d6eba12ebf462516b2edc376497cc62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20C=C3=A1ceres?= Date: Tue, 9 Apr 2024 19:44:31 +0100 Subject: [PATCH 14/14] std.Build: move LazyPath helper for generated files into LazyPath itself --- lib/std/Build.zig | 8 ++++---- lib/std/Build/Step/Compile.zig | 7 +++---- lib/std/Build/Step/ConfigHeader.zig | 2 +- lib/std/Build/Step/ObjCopy.zig | 4 ++-- lib/std/Build/Step/Options.zig | 2 +- lib/std/Build/Step/Run.zig | 15 ++++++++------- lib/std/Build/Step/TranslateC.zig | 2 +- lib/std/Build/Step/WriteFile.zig | 6 +++--- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 53cc44470cd0..a8af766acd13 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -2089,10 +2089,6 @@ pub fn pathCwd(b: *Build, p: []const u8) LazyPath { return .{ .owner = b, .path = b.dupePath(p), .root = .cwd }; } -pub fn pathGenerated(b: *Build, g: *const GeneratedFile) LazyPath { - return .{ .owner = b, .path = "", .root = .{ .generated = .{ .generated = g, .up = 0 } } }; -} - // dirnameAllowEmpty is a variant of fs.path.dirname // that allows "" to refer to the root for relative paths. // @@ -2157,6 +2153,10 @@ pub const LazyPath = struct { pub const relative = @compileError("use std.Build.path() instead"); + pub fn generatedFile(g: *const GeneratedFile) LazyPath { + return .{ .owner = g.step.owner, .path = "", .root = .{ .generated = .{ .generated = g, .up = 0 } } }; + } + /// Returns a lazy path referring to the directory containing this path. /// /// The dirname is not allowed to escape the logical root for underlying path. diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 37be2875a992..72af1c489557 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -802,14 +802,13 @@ pub fn setLibCFile(self: *Compile, libc_file: ?LazyPath) void { } fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath { - if (output_file.*) |g| { - return self.step.owner.pathGenerated(g); - } + if (output_file.*) |g| return LazyPath.generatedFile(g); + const arena = self.step.owner.allocator; const generated_file = arena.create(GeneratedFile) catch @panic("OOM"); generated_file.* = .{ .step = &self.step }; output_file.* = generated_file; - return self.step.owner.pathGenerated(generated_file); + return LazyPath.generatedFile(generated_file); } /// Returns the path to the directory that contains the emitted binary file. diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig index 784c5750128b..f7398298e0ce 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -103,7 +103,7 @@ pub fn addValues(self: *ConfigHeader, values: anytype) void { } pub fn getOutput(self: *ConfigHeader) std.Build.LazyPath { - return self.step.owner.pathGenerated(&self.output_file); + return std.Build.LazyPath.generatedFile(&self.output_file); } fn addValuesInner(self: *ConfigHeader, values: anytype) !void { diff --git a/lib/std/Build/Step/ObjCopy.zig b/lib/std/Build/Step/ObjCopy.zig index 4d5d7a2e6931..d52c2edfd77f 100644 --- a/lib/std/Build/Step/ObjCopy.zig +++ b/lib/std/Build/Step/ObjCopy.zig @@ -84,10 +84,10 @@ pub fn create( pub const getOutputSource = getOutput; pub fn getOutput(self: *const ObjCopy) std.Build.LazyPath { - return self.step.owner.pathGenerated(&self.output_file); + return std.Build.LazyPath.generatedFile(&self.output_file); } pub fn getOutputSeparatedDebug(self: *const ObjCopy) ?std.Build.LazyPath { - return if (self.output_file_debug) |*file| .{ .generated = file } else null; + return if (self.output_file_debug) |*file| std.Build.LazyPath.generatedFile(file) else null; } fn make(step: *Step, prog_node: *std.Progress.Node) !void { diff --git a/lib/std/Build/Step/Options.zig b/lib/std/Build/Step/Options.zig index 3e0ce4970358..90d132836b78 100644 --- a/lib/std/Build/Step/Options.zig +++ b/lib/std/Build/Step/Options.zig @@ -407,7 +407,7 @@ pub const getSource = getOutput; /// Returns the main artifact of this Build Step which is a Zig source file /// generated from the key-value pairs of the Options. pub fn getOutput(self: *Options) LazyPath { - return self.step.owner.pathGenerated(&self.generated_file); + return LazyPath.generatedFile(&self.generated_file); } fn make(step: *Step, prog_node: *std.Progress.Node) !void { diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index 26195c20b57d..606ebb8f1f70 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -1,6 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); const Build = std.Build; +const LazyPath = Build.LazyPath; const Step = Build.Step; const fs = std.fs; const mem = std.mem; @@ -198,7 +199,7 @@ pub fn addPrefixedOutputFileArg( self: *Run, prefix: []const u8, basename: []const u8, -) std.Build.LazyPath { +) LazyPath { const b = self.step.owner; const output = b.allocator.create(Output) catch @panic("OOM"); @@ -213,7 +214,7 @@ pub fn addPrefixedOutputFileArg( self.setName(b.fmt("{s} ({s})", .{ self.step.name, basename })); } - return self.step.owner.pathGenerated(&output.generated_file); + return LazyPath.generatedFile(&output.generated_file); } /// Appends an input file to the command line arguments. @@ -299,7 +300,7 @@ pub fn addPrefixedDepFileOutputArg(self: *Run, prefix: []const u8, basename: []c self.argv.append(.{ .output = dep_file }) catch @panic("OOM"); - return self.step.pathGenerated(&dep_file.generated_file); + return LazyPath.generatedFile(&dep_file.generated_file); } pub fn addArg(self: *Run, arg: []const u8) void { @@ -414,7 +415,7 @@ pub fn addCheck(self: *Run, new_check: StdIo.Check) void { pub fn captureStdErr(self: *Run) std.Build.LazyPath { assert(self.stdio != .inherit); - if (self.captured_stderr) |output| return self.step.owner.pathGenerated(&output.generated_file); + if (self.captured_stderr) |output| return LazyPath.generatedFile(&output.generated_file); const output = self.step.owner.allocator.create(Output) catch @panic("OOM"); output.* = .{ @@ -423,13 +424,13 @@ pub fn captureStdErr(self: *Run) std.Build.LazyPath { .generated_file = .{ .step = &self.step }, }; self.captured_stderr = output; - return self.step.owner.pathGenerated(&output.generated_file); + return LazyPath.generatedFile(&output.generated_file); } pub fn captureStdOut(self: *Run) std.Build.LazyPath { assert(self.stdio != .inherit); - if (self.captured_stdout) |output| return self.step.owner.pathGenerated(&output.generated_file); + if (self.captured_stdout) |output| return LazyPath.generatedFile(&output.generated_file); const output = self.step.owner.allocator.create(Output) catch @panic("OOM"); output.* = .{ @@ -438,7 +439,7 @@ pub fn captureStdOut(self: *Run) std.Build.LazyPath { .generated_file = .{ .step = &self.step }, }; self.captured_stdout = output; - return self.step.owner.pathGenerated(&output.generated_file); + return LazyPath.generatedFile(&output.generated_file); } /// Returns whether the Run step has side effects *other than* updating the output arguments. diff --git a/lib/std/Build/Step/TranslateC.zig b/lib/std/Build/Step/TranslateC.zig index c92b5da952c7..5c9033dbad02 100644 --- a/lib/std/Build/Step/TranslateC.zig +++ b/lib/std/Build/Step/TranslateC.zig @@ -59,7 +59,7 @@ pub const AddExecutableOptions = struct { }; pub fn getOutput(self: *TranslateC) std.Build.LazyPath { - return self.step.owner.pathGenerated(&self.output_file); + return std.Build.LazyPath.generatedFile(&self.output_file); } /// Creates a step to build an executable from the translated source. diff --git a/lib/std/Build/Step/WriteFile.zig b/lib/std/Build/Step/WriteFile.zig index 2d037b24a926..451629bc82d6 100644 --- a/lib/std/Build/Step/WriteFile.zig +++ b/lib/std/Build/Step/WriteFile.zig @@ -31,7 +31,7 @@ pub const File = struct { contents: Contents, pub fn getPath(self: *File) std.Build.LazyPath { - return self.generated_file.step.owner.pathGenerated(&self.generated_file); + return std.Build.LazyPath.generatedFile(&self.generated_file); } }; @@ -58,7 +58,7 @@ pub const Directory = struct { }; pub fn getPath(self: *Directory) std.Build.LazyPath { - return self.generated_dir.step.owner.pathGenerated(&self.generated_dir); + return std.Build.LazyPath.generatedFile(&self.generated_dir); } }; @@ -181,7 +181,7 @@ pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8) /// Returns a `LazyPath` representing the base directory that contains all the /// files from this `WriteFile`. pub fn getDirectory(wf: *WriteFile) std.Build.LazyPath { - return wf.step.owner.pathGenerated(&wf.generated_directory); + return std.Build.LazyPath.generatedFile(&wf.generated_directory); } fn maybeUpdateName(wf: *WriteFile) void {