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 2c644ce4b031..a8af766acd13 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 { @@ -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, @@ -1813,12 +1813,7 @@ pub const Dependency = struct { } pub fn path(d: *Dependency, sub_path: []const u8) LazyPath { - return .{ - .dependency = .{ - .dependency = d, - .sub_path = sub_path, - }, - }; + return .{ .owner = d.builder, .path = sub_path, .root = .build }; } }; @@ -2085,6 +2080,15 @@ pub const GeneratedFile = struct { } }; +pub fn path(b: *Build, p: []const u8) LazyPath { + // TODO(lacc97): absolute paths + return .{ .owner = b, .path = b.dupePath(p), .root = .build }; +} + +pub fn pathCwd(b: *Build, p: []const u8) LazyPath { + return .{ .owner = b, .path = b.dupePath(p), .root = .cwd }; +} + // dirnameAllowEmpty is a variant of fs.path.dirname // that allows "" to refer to the root for relative paths. // @@ -2093,9 +2097,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 ""; }; @@ -2116,45 +2120,41 @@ 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, +pub const LazyPath = struct { + owner: *std.Build, - /// 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 { - generated: *const GeneratedFile, + /// A path relative to `root`. + path: []const u8, - /// 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, + /// + root: union(enum) { + /// 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 or its parent directory. Those files usually are + /// not available until built by a build step. + generated: struct { + generated: *const GeneratedFile, + + /// The number of parent directories to go up. + /// 0 means the generated file, + /// 1 means the parent of the generated file, 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, - }, + pub const relative = @compileError("use std.Build.path() instead"); - /// 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 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. @@ -2165,11 +2165,11 @@ 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 { + return .{ + .owner = self.owner, + .path = switch (self.root) { + .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. \\This is not allowed. @@ -2177,15 +2177,13 @@ pub const LazyPath = union(enum) { , .{}) catch {}; @panic("misconfigured build script"); }, - }, - .cwd_relative => |p| .{ - .cwd_relative = dirnameAllowEmpty(p) orelse { + .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(p)) { + if (fs.path.isAbsolute(self.path)) { dumpBadDirnameHelp(null, null, \\dirname() attempted to traverse outside the root. \\No more directories left to go up. @@ -2202,37 +2200,32 @@ pub const LazyPath = union(enum) { } }, }, - .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"); + .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 = .{ .generated = gen.generated, .up = gen.up + 1 }, }, - } }, + }, }; } /// 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) { + // TODO: different display string for what used to be `dependency` case? + .build, .cwd => self.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) { - .path, .cwd_relative, .dependency => {}, - .generated => |gen| other_step.dependOn(gen.step), - .generated_dirname => |gen| other_step.dependOn(gen.generated.step), + switch (self.root) { + .build, .cwd => {}, + .generated => |gen| other_step.dependOn(gen.generated.step), } } @@ -2248,27 +2241,29 @@ 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) { - .path => |p| return src_builder.pathFromRoot(p), - .cwd_relative => |p| return src_builder.pathFromCwd(p), - .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"); + switch (self.root) { + .build => { + if (self.owner != src_builder) assert(self.owner.build_root.path != null); + return self.owner.pathFromRoot(self.path); }, - .generated_dirname => |gen| { + .cwd => return src_builder.pathFromCwd(self.path), + .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 path = getPath2(LazyPath{ .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. - 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 +2272,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 + 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, @@ -2288,30 +2283,27 @@ pub const LazyPath = union(enum) { @panic("misconfigured build script"); } } - return path; - }, - .dependency => |dep| { - return dep.dependency.builder.pathJoin(&[_][]const u8{ - dep.dependency.builder.build_root.path.?, - dep.sub_path, - }); + return p; }, } } - /// Duplicates the file source for a given builder. - pub fn dupe(self: LazyPath, b: *Build) LazyPath { - return switch (self) { - .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, + // 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) { + .build => .build, + .cwd => .cwd, + .generated => |gen| .{ + .generated = .{ + .generated = gen.generated, + .up = gen.up, + }, }, }, - .dependency => |dep| .{ .dependency = dep }, }; } }; diff --git a/lib/std/Build/Module.zig b/lib/std/Build/Module.zig index 02386de4308f..2f1cea658029 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, @@ -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), }; @@ -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,38 +553,38 @@ 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); } pub fn addRPath(m: *Module, directory_path: LazyPath) void { const b = m.owner; - switch (directory_path) { - .path, .cwd_relative => |path| { + switch (directory_path.root) { + .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."); } }, 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 4a5364176aab..72af1c489557 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -264,20 +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. - const duped_source: LazyPath = switch (self.source) { - .path => |root_rel| .{ .cwd_relative = b.pathFromRoot(root_rel) }, - else => self.source.dupe(b), - }; - return .{ - .source = duped_source, + .source = self.source.dupe(), .dest_rel_path = b.dupePath(self.dest_rel_path), }; } @@ -305,20 +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. - const duped_source: LazyPath = switch (self.source) { - .path => |root_rel| .{ .cwd_relative = b.pathFromRoot(root_rel) }, - else => self.source.dupe(b), - }; - return .{ - .source = duped_source, + .source = self.source.dupe(), .dest_rel_path = b.dupePath(self.dest_rel_path), .options = self.options.dupe(b), }; @@ -425,7 +401,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); } @@ -433,7 +409,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); } } @@ -476,7 +452,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"); @@ -495,7 +471,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), } }; @@ -580,14 +556,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); } @@ -824,19 +798,17 @@ 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 { - if (output_file.*) |g| { - return .{ .generated = 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 .{ .generated = 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 46631cac24a4..f7398298e0ce 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -57,11 +57,9 @@ 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) { - .path => |path| path, - .generated, .generated_dirname => break :default_include_path, - .cwd_relative => |sub_path| sub_path, - .dependency => |dependency| dependency.sub_path, + const sub_path = switch (s.root) { + .build, .cwd => s.path, + .generated => break :default_include_path, }; const basename = std.fs.path.basename(sub_path); if (std.mem.endsWith(u8, basename, ".h.in")) { @@ -105,7 +103,7 @@ pub fn addValues(self: *ConfigHeader, values: anytype) void { } pub fn getOutput(self: *ConfigHeader) std.Build.LazyPath { - return .{ .generated = &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/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/ObjCopy.zig b/lib/std/Build/Step/ObjCopy.zig index ddd56833c04b..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 .{ .generated = &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 178e2c3b96f3..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 .{ .generated = &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 b3550624fc6d..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 .{ .generated = &output.generated_file }; + return LazyPath.generatedFile(&output.generated_file); } /// Appends an input file to the command line arguments. @@ -246,7 +247,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 +268,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); @@ -299,7 +300,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 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 .{ .generated = &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 .{ .generated = &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 .{ .generated = &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 .{ .generated = &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 ac421a67cad5..5c9033dbad02 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, @@ -59,7 +59,7 @@ pub const AddExecutableOptions = struct { }; pub fn getOutput(self: *TranslateC) std.Build.LazyPath { - return .{ .generated = &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 310decdfe757..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 .{ .generated = &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 .{ .generated = &self.generated_dir }; + return std.Build.LazyPath.generatedFile(&self.generated_dir); } }; @@ -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 }, @@ -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 std.Build.LazyPath.generatedFile(&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/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..e4533ddf9030 --- /dev/null +++ b/test/standalone/build_dep/build.zig.zon @@ -0,0 +1,6 @@ +.{ + .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(); +} 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);