Skip to content

Commit b30ad74

Browse files
committed
remove deprecated LazyPath.path union tag
1 parent 3d16520 commit b30ad74

File tree

69 files changed

+175
-223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+175
-223
lines changed

build.zig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn build(b: *std.Build) !void {
3434

3535
const docgen_exe = b.addExecutable(.{
3636
.name = "docgen",
37-
.root_source_file = .{ .path = "tools/docgen.zig" },
37+
.root_source_file = b.path("tools/docgen.zig"),
3838
.target = b.host,
3939
.optimize = .Debug,
4040
.single_threaded = single_threaded,
@@ -46,7 +46,7 @@ pub fn build(b: *std.Build) !void {
4646
docgen_cmd.addArg("--zig-lib-dir");
4747
docgen_cmd.addDirectoryArg(p);
4848
}
49-
docgen_cmd.addFileArg(.{ .path = "doc/langref.html.in" });
49+
docgen_cmd.addFileArg(b.path("doc/langref.html.in"));
5050
const langref_file = docgen_cmd.addOutputFileArg("langref.html");
5151
const install_langref = b.addInstallFileWithDir(langref_file, .prefix, "doc/langref.html");
5252
if (!skip_install_langref) {
@@ -55,9 +55,9 @@ pub fn build(b: *std.Build) !void {
5555

5656
const autodoc_test = b.addObject(.{
5757
.name = "std",
58-
.root_source_file = .{ .path = "lib/std/std.zig" },
58+
.root_source_file = b.path("lib/std/std.zig"),
5959
.target = target,
60-
.zig_lib_dir = .{ .path = "lib" },
60+
.zig_lib_dir = b.path("lib"),
6161
.optimize = .Debug,
6262
});
6363
const install_std_docs = b.addInstallDirectory(.{
@@ -86,7 +86,7 @@ pub fn build(b: *std.Build) !void {
8686

8787
const check_case_exe = b.addExecutable(.{
8888
.name = "check-case",
89-
.root_source_file = .{ .path = "test/src/Cases.zig" },
89+
.root_source_file = b.path("test/src/Cases.zig"),
9090
.target = b.host,
9191
.optimize = optimize,
9292
.single_threaded = single_threaded,
@@ -135,7 +135,7 @@ pub fn build(b: *std.Build) !void {
135135

136136
if (!skip_install_lib_files) {
137137
b.installDirectory(.{
138-
.source_dir = .{ .path = "lib" },
138+
.source_dir = b.path("lib"),
139139
.install_dir = if (flat) .prefix else .lib,
140140
.install_subdir = if (flat) "lib" else "zig",
141141
.exclude_extensions = &[_][]const u8{
@@ -552,10 +552,10 @@ pub fn build(b: *std.Build) !void {
552552
const update_mingw_exe = b.addExecutable(.{
553553
.name = "update_mingw",
554554
.target = b.host,
555-
.root_source_file = .{ .path = "tools/update_mingw.zig" },
555+
.root_source_file = b.path("tools/update_mingw.zig"),
556556
});
557557
const update_mingw_run = b.addRunArtifact(update_mingw_exe);
558-
update_mingw_run.addDirectoryArg(.{ .path = "lib" });
558+
update_mingw_run.addDirectoryArg(b.path("lib"));
559559
if (opt_mingw_src_path) |mingw_src_path| {
560560
update_mingw_run.addDirectoryArg(.{ .cwd_relative = mingw_src_path });
561561
} else {
@@ -606,10 +606,10 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
606606
});
607607
run_opt.addArtifactArg(exe);
608608
run_opt.addArg("-o");
609-
run_opt.addFileArg(.{ .path = "stage1/zig1.wasm" });
609+
run_opt.addFileArg(b.path("stage1/zig1.wasm"));
610610

611611
const copy_zig_h = b.addWriteFiles();
612-
copy_zig_h.addCopyFileToSource(.{ .path = "lib/zig.h" }, "stage1/zig.h");
612+
copy_zig_h.addCopyFileToSource(b.path("lib/zig.h"), "stage1/zig.h");
613613

614614
const update_zig1_step = b.step("update-zig1", "Update stage1/zig1.wasm");
615615
update_zig1_step.dependOn(&run_opt.step);
@@ -627,7 +627,7 @@ const AddCompilerStepOptions = struct {
627627
fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.Step.Compile {
628628
const exe = b.addExecutable(.{
629629
.name = "zig",
630-
.root_source_file = .{ .path = "src/main.zig" },
630+
.root_source_file = b.path("src/main.zig"),
631631
.target = options.target,
632632
.optimize = options.optimize,
633633
.max_rss = 7_000_000_000,
@@ -638,11 +638,11 @@ fn addCompilerStep(b: *std.Build, options: AddCompilerStepOptions) *std.Build.St
638638
exe.stack_size = stack_size;
639639

640640
const aro_module = b.createModule(.{
641-
.root_source_file = .{ .path = "lib/compiler/aro/aro.zig" },
641+
.root_source_file = b.path("lib/compiler/aro/aro.zig"),
642642
});
643643

644644
const aro_translate_c_module = b.createModule(.{
645-
.root_source_file = .{ .path = "lib/compiler/aro_translate_c.zig" },
645+
.root_source_file = b.path("lib/compiler/aro_translate_c.zig"),
646646
.imports = &.{
647647
.{
648648
.name = "aro",

lib/std/Build.zig

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,22 +1546,22 @@ pub fn addInstallArtifact(
15461546
}
15471547

15481548
///`dest_rel_path` is relative to prefix path
1549-
pub fn installFile(self: *Build, src_path: []const u8, dest_rel_path: []const u8) void {
1550-
self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .prefix, dest_rel_path).step);
1549+
pub fn installFile(b: *Build, src_path: []const u8, dest_rel_path: []const u8) void {
1550+
b.getInstallStep().dependOn(&b.addInstallFileWithDir(b.path(src_path), .prefix, dest_rel_path).step);
15511551
}
15521552

1553-
pub fn installDirectory(self: *Build, options: Step.InstallDir.Options) void {
1554-
self.getInstallStep().dependOn(&self.addInstallDirectory(options).step);
1553+
pub fn installDirectory(b: *Build, options: Step.InstallDir.Options) void {
1554+
b.getInstallStep().dependOn(&b.addInstallDirectory(options).step);
15551555
}
15561556

15571557
///`dest_rel_path` is relative to bin path
1558-
pub fn installBinFile(self: *Build, src_path: []const u8, dest_rel_path: []const u8) void {
1559-
self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .bin, dest_rel_path).step);
1558+
pub fn installBinFile(b: *Build, src_path: []const u8, dest_rel_path: []const u8) void {
1559+
b.getInstallStep().dependOn(&b.addInstallFileWithDir(b.path(src_path), .bin, dest_rel_path).step);
15601560
}
15611561

15621562
///`dest_rel_path` is relative to lib path
1563-
pub fn installLibFile(self: *Build, src_path: []const u8, dest_rel_path: []const u8) void {
1564-
self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .lib, dest_rel_path).step);
1563+
pub fn installLibFile(b: *Build, src_path: []const u8, dest_rel_path: []const u8) void {
1564+
b.getInstallStep().dependOn(&b.addInstallFileWithDir(b.path(src_path), .lib, dest_rel_path).step);
15651565
}
15661566

15671567
pub fn addObjCopy(b: *Build, source: LazyPath, options: Step.ObjCopy.Options) *Step.ObjCopy {
@@ -1637,7 +1637,11 @@ pub fn truncateFile(self: *Build, dest_path: []const u8) !void {
16371637

16381638
/// References a file or directory relative to the source root.
16391639
pub fn path(b: *Build, sub_path: []const u8) LazyPath {
1640-
assert(!fs.path.isAbsolute(sub_path));
1640+
if (fs.path.isAbsolute(sub_path)) {
1641+
std.debug.panic("sub_path is expected to be relative to the build root, but was this absolute path: '{s}'. It is best avoid absolute paths, but if you must, it is supported by LazyPath.cwd_relative", .{
1642+
sub_path,
1643+
});
1644+
}
16411645
return .{ .src_path = .{
16421646
.owner = b,
16431647
.sub_path = sub_path,
@@ -2127,9 +2131,6 @@ test dirnameAllowEmpty {
21272131

21282132
/// A reference to an existing or future path.
21292133
pub const LazyPath = union(enum) {
2130-
/// Deprecated; use the `path` function instead.
2131-
path: []const u8,
2132-
21332134
/// A source file path relative to build root.
21342135
src_path: struct {
21352136
owner: *std.Build,
@@ -2164,12 +2165,6 @@ pub const LazyPath = union(enum) {
21642165
sub_path: []const u8,
21652166
},
21662167

2167-
/// Deprecated. Call `path` instead.
2168-
pub fn relative(p: []const u8) LazyPath {
2169-
std.log.warn("deprecated. call std.Build.path instead", .{});
2170-
return .{ .path = p };
2171-
}
2172-
21732168
/// Returns a lazy path referring to the directory containing this path.
21742169
///
21752170
/// The dirname is not allowed to escape the logical root for underlying path.
@@ -2188,12 +2183,6 @@ pub const LazyPath = union(enum) {
21882183
@panic("misconfigured build script");
21892184
},
21902185
} },
2191-
.path => |p| .{
2192-
.path = dirnameAllowEmpty(p) orelse {
2193-
dumpBadDirnameHelp(null, null, "dirname() attempted to traverse outside the build root\n", .{}) catch {};
2194-
@panic("misconfigured build script");
2195-
},
2196-
},
21972186
.cwd_relative => |p| .{
21982187
.cwd_relative = dirnameAllowEmpty(p) orelse {
21992188
// If we get null, it means one of two things:
@@ -2235,7 +2224,7 @@ pub const LazyPath = union(enum) {
22352224
pub fn getDisplayName(self: LazyPath) []const u8 {
22362225
return switch (self) {
22372226
.src_path => |sp| sp.sub_path,
2238-
.path, .cwd_relative => |p| p,
2227+
.cwd_relative => |p| p,
22392228
.generated => "generated",
22402229
.generated_dirname => "generated",
22412230
.dependency => "dependency",
@@ -2245,7 +2234,7 @@ pub const LazyPath = union(enum) {
22452234
/// Adds dependencies this file source implies to the given step.
22462235
pub fn addStepDependencies(self: LazyPath, other_step: *Step) void {
22472236
switch (self) {
2248-
.src_path, .path, .cwd_relative, .dependency => {},
2237+
.src_path, .cwd_relative, .dependency => {},
22492238
.generated => |gen| other_step.dependOn(gen.step),
22502239
.generated_dirname => |gen| other_step.dependOn(gen.generated.step),
22512240
}
@@ -2264,7 +2253,6 @@ pub const LazyPath = union(enum) {
22642253
/// run that is asking for the path.
22652254
pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 {
22662255
switch (self) {
2267-
.path => |p| return src_builder.pathFromRoot(p),
22682256
.src_path => |sp| return sp.owner.pathFromRoot(sp.sub_path),
22692257
.cwd_relative => |p| return src_builder.pathFromCwd(p),
22702258
.generated => |gen| return gen.path orelse {
@@ -2315,14 +2303,16 @@ pub const LazyPath = union(enum) {
23152303
}
23162304
}
23172305

2318-
/// Duplicates the file source for a given builder.
2306+
/// Copies the internal strings.
2307+
///
2308+
/// The `b` parameter is only used for its allocator. All *Build instances
2309+
/// share the same allocator.
23192310
pub fn dupe(self: LazyPath, b: *Build) LazyPath {
23202311
return switch (self) {
23212312
.src_path => |sp| .{ .src_path = .{
23222313
.owner = sp.owner,
2323-
.sub_path = b.dupePath(sp.sub_path),
2314+
.sub_path = sp.owner.dupePath(sp.sub_path),
23242315
} },
2325-
.path => |p| .{ .path = b.dupePath(p) },
23262316
.cwd_relative => |p| .{ .cwd_relative = b.dupePath(p) },
23272317
.generated => |gen| .{ .generated = gen },
23282318
.generated_dirname => |gen| .{

lib/std/Build/Module.zig

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ pub fn linkFramework(m: *Module, name: []const u8, options: LinkFrameworkOptions
451451
pub const AddCSourceFilesOptions = struct {
452452
/// When provided, `files` are relative to `root` rather than the
453453
/// package that owns the `Compile` step.
454-
root: LazyPath = .{ .path = "" },
454+
root: ?LazyPath = null,
455455
files: []const []const u8,
456456
flags: []const []const u8 = &.{},
457457
};
@@ -472,7 +472,7 @@ pub fn addCSourceFiles(m: *Module, options: AddCSourceFilesOptions) void {
472472

473473
const c_source_files = allocator.create(CSourceFiles) catch @panic("OOM");
474474
c_source_files.* = .{
475-
.root = options.root,
475+
.root = options.root orelse b.path(""),
476476
.files = b.dupeStrings(options.files),
477477
.flags = b.dupeStrings(options.flags),
478478
};
@@ -573,17 +573,6 @@ pub fn addLibraryPath(m: *Module, directory_path: LazyPath) void {
573573

574574
pub fn addRPath(m: *Module, directory_path: LazyPath) void {
575575
const b = m.owner;
576-
switch (directory_path) {
577-
.path, .cwd_relative => |path| {
578-
// TODO: remove this check after people upgrade and stop expecting it to work
579-
if (std.mem.startsWith(u8, path, "@executable_path") or
580-
std.mem.startsWith(u8, path, "@loader_path"))
581-
{
582-
@panic("this function is for adding directory paths. It does not support special rpaths. use addRPathSpecial for that.");
583-
}
584-
},
585-
else => {},
586-
}
587576
m.rpaths.append(b.allocator, .{ .lazy_path = directory_path.dupe(b) }) catch @panic("OOM");
588577
addLazyPathDependenciesOnly(m, directory_path);
589578
}

lib/std/Build/Step/Compile.zig

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,8 @@ pub const HeaderInstallation = union(enum) {
264264
dest_rel_path: []const u8,
265265

266266
pub fn dupe(self: File, b: *std.Build) File {
267-
// 'path' lazy paths are relative to the build root of some step, inferred from the step
268-
// in which they are used. This means that we can't dupe such paths, because they may
269-
// come from dependencies with their own build roots and duping the paths as is might
270-
// cause the build script to search for the file relative to the wrong root.
271-
// As a temporary workaround, we convert build root-relative paths to absolute paths.
272-
// If/when the build-root relative paths are updated to encode which build root they are
273-
// relative to, this workaround should be removed.
274-
const duped_source: LazyPath = switch (self.source) {
275-
.path => |root_rel| .{ .cwd_relative = b.pathFromRoot(root_rel) },
276-
else => self.source.dupe(b),
277-
};
278-
279267
return .{
280-
.source = duped_source,
268+
.source = self.source.dupe(b),
281269
.dest_rel_path = b.dupePath(self.dest_rel_path),
282270
};
283271
}
@@ -305,20 +293,8 @@ pub const HeaderInstallation = union(enum) {
305293
};
306294

307295
pub fn dupe(self: Directory, b: *std.Build) Directory {
308-
// 'path' lazy paths are relative to the build root of some step, inferred from the step
309-
// in which they are used. This means that we can't dupe such paths, because they may
310-
// come from dependencies with their own build roots and duping the paths as is might
311-
// cause the build script to search for the file relative to the wrong root.
312-
// As a temporary workaround, we convert build root-relative paths to absolute paths.
313-
// If/when the build-root relative paths are updated to encode which build root they are
314-
// relative to, this workaround should be removed.
315-
const duped_source: LazyPath = switch (self.source) {
316-
.path => |root_rel| .{ .cwd_relative = b.pathFromRoot(root_rel) },
317-
else => self.source.dupe(b),
318-
};
319-
320296
return .{
321-
.source = duped_source,
297+
.source = self.source.dupe(b),
322298
.dest_rel_path = b.dupePath(self.dest_rel_path),
323299
.options = self.options.dupe(b),
324300
};

lib/std/Build/Step/ConfigHeader.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader {
5959
if (options.style.getPath()) |s| default_include_path: {
6060
const sub_path = switch (s) {
6161
.src_path => |sp| sp.sub_path,
62-
.path => |path| path,
6362
.generated, .generated_dirname => break :default_include_path,
6463
.cwd_relative => |sub_path| sub_path,
6564
.dependency => |dependency| dependency.sub_path,

test/link/bss/build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn build(b: *std.Build) void {
66

77
const exe = b.addExecutable(.{
88
.name = "bss",
9-
.root_source_file = .{ .path = "main.zig" },
9+
.root_source_file = b.path("main.zig"),
1010
.target = b.host,
1111
.optimize = .Debug,
1212
});

test/link/common_symbols/build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2222
});
2323

2424
const test_exe = b.addTest(.{
25-
.root_source_file = .{ .path = "main.zig" },
25+
.root_source_file = b.path("main.zig"),
2626
.optimize = optimize,
2727
});
2828
test_exe.linkLibrary(lib_a);

test/link/common_symbols_alignment/build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2222
});
2323

2424
const test_exe = b.addTest(.{
25-
.root_source_file = .{ .path = "main.zig" },
25+
.root_source_file = b.path("main.zig"),
2626
.optimize = optimize,
2727
});
2828
test_exe.linkLibrary(lib_a);

test/link/glibc_compat/build.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn build(b: *std.Build) void {
2121
.{ .arch_os_abi = t },
2222
) catch unreachable),
2323
});
24-
exe.addCSourceFile(.{ .file = .{ .path = "main.c" } });
24+
exe.addCSourceFile(.{ .file = b.path("main.c") });
2525
exe.linkLibC();
2626
// TODO: actually test the output
2727
_ = exe.getEmittedBin();
@@ -45,7 +45,7 @@ pub fn build(b: *std.Build) void {
4545

4646
const exe = b.addExecutable(.{
4747
.name = t,
48-
.root_source_file = .{ .path = "glibc_runtime_check.zig" },
48+
.root_source_file = b.path("glibc_runtime_check.zig"),
4949
.target = target,
5050
});
5151
exe.linkLibC();

test/link/interdependent_static_c_libs/build.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
1616
.optimize = optimize,
1717
.target = b.host,
1818
});
19-
lib_a.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &[_][]const u8{} });
20-
lib_a.addIncludePath(.{ .path = "." });
19+
lib_a.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} });
20+
lib_a.addIncludePath(b.path("."));
2121

2222
const lib_b = b.addStaticLibrary(.{
2323
.name = "b",
2424
.optimize = optimize,
2525
.target = b.host,
2626
});
27-
lib_b.addCSourceFile(.{ .file = .{ .path = "b.c" }, .flags = &[_][]const u8{} });
28-
lib_b.addIncludePath(.{ .path = "." });
27+
lib_b.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} });
28+
lib_b.addIncludePath(b.path("."));
2929

3030
const test_exe = b.addTest(.{
31-
.root_source_file = .{ .path = "main.zig" },
31+
.root_source_file = b.path("main.zig"),
3232
.optimize = optimize,
3333
});
3434
test_exe.linkLibrary(lib_a);
3535
test_exe.linkLibrary(lib_b);
36-
test_exe.addIncludePath(.{ .path = "." });
36+
test_exe.addIncludePath(b.path("."));
3737

3838
test_step.dependOn(&b.addRunArtifact(test_exe).step);
3939
}

test/link/macho.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,9 @@ fn testLinkDirectlyCppTbd(b: *Build, opts: Options) *Step {
836836
,
837837
.cpp_source_flags = &.{ "-nostdlib++", "-nostdinc++" },
838838
});
839-
exe.root_module.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include" }) });
840-
exe.root_module.addIncludePath(.{ .path = b.pathJoin(&.{ sdk, "/usr/include/c++/v1" }) });
841-
exe.root_module.addObjectFile(.{ .path = b.pathJoin(&.{ sdk, "/usr/lib/libc++.tbd" }) });
839+
exe.root_module.addSystemIncludePath(b.path(b.pathJoin(&.{ sdk, "/usr/include" })));
840+
exe.root_module.addIncludePath(b.path(b.pathJoin(&.{ sdk, "/usr/include/c++/v1" })));
841+
exe.root_module.addObjectFile(b.path(b.pathJoin(&.{ sdk, "/usr/lib/libc++.tbd" })));
842842

843843
const check = exe.checkObject();
844844
check.checkInSymtab();

0 commit comments

Comments
 (0)