Skip to content

Commit

Permalink
Build.zig rename orgy (aka: ziglang#16353). Renames FileSource to Laz…
Browse files Browse the repository at this point in the history
…yPath and removes functions that take literal paths instead of LazyPath.
  • Loading branch information
Felix (xq) Queißner committed Jul 26, 2023
1 parent a707f38 commit 52eeae2
Show file tree
Hide file tree
Showing 55 changed files with 337 additions and 329 deletions.
35 changes: 17 additions & 18 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ pub fn build(b: *std.Build) !void {
const docgen_cmd = b.addRunArtifact(docgen_exe);
docgen_cmd.addArgs(&.{ "--zig", b.zig_exe });
if (b.zig_lib_dir) |p| {
docgen_cmd.addArgs(&.{ "--zig-lib-dir", p });
docgen_cmd.addArgs(&.{ "--zig-lib-dir", b.pathFromRoot(p) });
}
docgen_cmd.addFileSourceArg(.{ .path = "doc/langref.html.in" });
docgen_cmd.addFileArg(.{ .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) {
Expand All @@ -58,7 +58,7 @@ pub fn build(b: *std.Build) !void {
.root_source_file = .{ .path = "lib/std/std.zig" },
.target = target,
});
autodoc_test.overrideZigLibDir("lib");
autodoc_test.overrideZigLibDir(.{ .path = "lib" });
autodoc_test.emit_bin = .no_emit; // https://github.com/ziglang/zig/issues/16351
const install_std_docs = b.addInstallDirectory(.{
.source_dir = autodoc_test.getEmittedDocs(),
Expand Down Expand Up @@ -89,7 +89,7 @@ pub fn build(b: *std.Build) !void {
.root_source_file = .{ .path = "test/src/Cases.zig" },
.optimize = optimize,
});
check_case_exe.main_pkg_path = ".";
check_case_exe.setMainPkgPath(.{ .path = "." });
check_case_exe.stack_size = stack_size;
check_case_exe.single_threaded = single_threaded;

Expand Down Expand Up @@ -352,19 +352,18 @@ pub fn build(b: *std.Build) !void {
exe_options.addOption(bool, "enable_tracy_allocation", tracy_allocation);
exe_options.addOption(bool, "value_tracing", value_tracing);
if (tracy) |tracy_path| {
const client_cpp = fs.path.join(
b.allocator,
const client_cpp = b.pathJoin(
&[_][]const u8{ tracy_path, "public", "TracyClient.cpp" },
) catch unreachable;
);

// On mingw, we need to opt into windows 7+ to get some features required by tracy.
const tracy_c_flags: []const []const u8 = if (target.isWindows() and target.getAbi() == .gnu)
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" }
else
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };

exe.addIncludePath(tracy_path);
exe.addCSourceFile(client_cpp, tracy_c_flags);
exe.addIncludePath(.{ .path = tracy_path });
exe.addCSourceFile(.{ .file = .{ .path = client_cpp }, .flags = tracy_c_flags });
if (!enable_llvm) {
exe.linkSystemLibraryName("c++");
}
Expand Down Expand Up @@ -554,7 +553,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
});
run_opt.addArtifactArg(exe);
run_opt.addArg("-o");
run_opt.addFileSourceArg(.{ .path = "stage1/zig1.wasm" });
run_opt.addFileArg(.{ .path = "stage1/zig1.wasm" });

const copy_zig_h = b.addWriteFiles();
copy_zig_h.addCopyFileToSource(.{ .path = "lib/zig.h" }, "stage1/zig.h");
Expand Down Expand Up @@ -603,19 +602,19 @@ fn addCmakeCfgOptionsToExe(
// useful for package maintainers
exe.headerpad_max_install_names = true;
}
exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
exe.addObjectFile(.{ .path = b.pathJoin(&[_][]const u8{
cfg.cmake_binary_dir,
"zigcpp",
b.fmt("{s}{s}{s}", .{
cfg.cmake_static_library_prefix,
"zigcpp",
cfg.cmake_static_library_suffix,
}),
}) catch unreachable);
}) });
assert(cfg.lld_include_dir.len != 0);
exe.addIncludePath(cfg.lld_include_dir);
exe.addIncludePath(cfg.llvm_include_dir);
exe.addLibraryPath(cfg.llvm_lib_dir);
exe.addIncludePath(.{ .path = cfg.lld_include_dir });
exe.addIncludePath(.{ .path = cfg.llvm_include_dir });
exe.addLibraryPath(.{ .path = cfg.llvm_lib_dir });
addCMakeLibraryList(exe, cfg.clang_libraries);
addCMakeLibraryList(exe, cfg.lld_libraries);
addCMakeLibraryList(exe, cfg.llvm_libraries);
Expand Down Expand Up @@ -671,7 +670,7 @@ fn addCmakeCfgOptionsToExe(
}

if (cfg.dia_guids_lib.len != 0) {
exe.addObjectFile(cfg.dia_guids_lib);
exe.addObjectFile(.{ .path = cfg.dia_guids_lib });
}
}

Expand Down Expand Up @@ -732,7 +731,7 @@ fn addCxxKnownPath(
}
return error.RequiredLibraryNotFound;
}
exe.addObjectFile(path_unpadded);
exe.addObjectFile(.{ .path = path_unpadded });

// TODO a way to integrate with system c++ include files here
// c++ -E -Wp,-v -xc++ /dev/null
Expand All @@ -752,7 +751,7 @@ fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void {
} else if (exe.target.isWindows() and mem.endsWith(u8, lib, ".lib") and !fs.path.isAbsolute(lib)) {
exe.linkSystemLibrary(lib[0 .. lib.len - ".lib".len]);
} else {
exe.addObjectFile(lib);
exe.addObjectFile(.{ .path = lib });
}
}
}
Expand Down
50 changes: 26 additions & 24 deletions lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ pub fn addOptions(self: *Build) *Step.Options {

pub const ExecutableOptions = struct {
name: []const u8,
root_source_file: ?FileSource = null,
root_source_file: ?LazyPath = null,
version: ?std.SemanticVersion = null,
target: CrossTarget = .{},
optimize: std.builtin.Mode = .Debug,
Expand Down Expand Up @@ -502,7 +502,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {

pub const ObjectOptions = struct {
name: []const u8,
root_source_file: ?FileSource = null,
root_source_file: ?LazyPath = null,
target: CrossTarget,
optimize: std.builtin.Mode,
max_rss: usize = 0,
Expand All @@ -529,7 +529,7 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {

pub const SharedLibraryOptions = struct {
name: []const u8,
root_source_file: ?FileSource = null,
root_source_file: ?LazyPath = null,
version: ?std.SemanticVersion = null,
target: CrossTarget,
optimize: std.builtin.Mode,
Expand Down Expand Up @@ -559,7 +559,7 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile

pub const StaticLibraryOptions = struct {
name: []const u8,
root_source_file: ?FileSource = null,
root_source_file: ?LazyPath = null,
target: CrossTarget,
optimize: std.builtin.Mode,
version: ?std.SemanticVersion = null,
Expand Down Expand Up @@ -589,7 +589,7 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile

pub const TestOptions = struct {
name: []const u8 = "test",
root_source_file: FileSource,
root_source_file: LazyPath,
target: CrossTarget = .{},
optimize: std.builtin.Mode = .Debug,
version: ?std.SemanticVersion = null,
Expand Down Expand Up @@ -621,7 +621,7 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {

pub const AssemblyOptions = struct {
name: []const u8,
source_file: FileSource,
source_file: LazyPath,
target: CrossTarget,
optimize: std.builtin.Mode,
max_rss: usize = 0,
Expand All @@ -636,7 +636,7 @@ pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile {
.optimize = options.optimize,
.max_rss = options.max_rss,
});
obj_step.addAssemblyFileSource(options.source_file.dupe(b));
obj_step.addAssemblyLazyPath(options.source_file.dupe(b));
return obj_step;
}

Expand All @@ -655,7 +655,7 @@ pub const ModuleDependency = struct {
};

pub const CreateModuleOptions = struct {
source_file: FileSource,
source_file: LazyPath,
dependencies: []const ModuleDependency = &.{},
};

Expand Down Expand Up @@ -1284,22 +1284,22 @@ pub fn installLibFile(self: *Build, src_path: []const u8, dest_rel_path: []const
self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .lib, dest_rel_path).step);
}

pub fn addObjCopy(b: *Build, source: FileSource, options: Step.ObjCopy.Options) *Step.ObjCopy {
pub fn addObjCopy(b: *Build, source: LazyPath, options: Step.ObjCopy.Options) *Step.ObjCopy {
return Step.ObjCopy.create(b, source, options);
}

///`dest_rel_path` is relative to install prefix path
pub fn addInstallFile(self: *Build, source: FileSource, dest_rel_path: []const u8) *Step.InstallFile {
pub fn addInstallFile(self: *Build, source: LazyPath, dest_rel_path: []const u8) *Step.InstallFile {
return self.addInstallFileWithDir(source.dupe(self), .prefix, dest_rel_path);
}

///`dest_rel_path` is relative to bin path
pub fn addInstallBinFile(self: *Build, source: FileSource, dest_rel_path: []const u8) *Step.InstallFile {
pub fn addInstallBinFile(self: *Build, source: LazyPath, dest_rel_path: []const u8) *Step.InstallFile {
return self.addInstallFileWithDir(source.dupe(self), .bin, dest_rel_path);
}

///`dest_rel_path` is relative to lib path
pub fn addInstallLibFile(self: *Build, source: FileSource, dest_rel_path: []const u8) *Step.InstallFile {
pub fn addInstallLibFile(self: *Build, source: LazyPath, dest_rel_path: []const u8) *Step.InstallFile {
return self.addInstallFileWithDir(source.dupe(self), .lib, dest_rel_path);
}

Expand All @@ -1309,7 +1309,7 @@ pub fn addInstallHeaderFile(b: *Build, src_path: []const u8, dest_rel_path: []co

pub fn addInstallFileWithDir(
self: *Build,
source: FileSource,
source: LazyPath,
install_dir: InstallDir,
dest_rel_path: []const u8,
) *Step.InstallFile {
Expand All @@ -1322,7 +1322,7 @@ pub fn addInstallDirectory(self: *Build, options: InstallDirectoryOptions) *Step

pub fn addCheckFile(
b: *Build,
file_source: FileSource,
file_source: LazyPath,
options: Step.CheckFile.Options,
) *Step.CheckFile {
return Step.CheckFile.create(b, file_source, options);
Expand Down Expand Up @@ -1608,7 +1608,7 @@ pub const Module = struct {
/// This could either be a generated file, in which case the module
/// contains exactly one file, or it could be a path to the root source
/// file of directory of files which constitute the module.
source_file: FileSource,
source_file: LazyPath,
dependencies: std.StringArrayHashMap(*Module),
};

Expand All @@ -1630,8 +1630,10 @@ pub const GeneratedFile = struct {
}
};

/// A file source is a reference to an existing or future file.
pub const FileSource = union(enum) {
pub const FileSource = LazyPath; // DEPRECATED, use LazyPath now

/// A reference to an existing or future path.
pub const LazyPath = union(enum) {
/// A plain file path, relative to build root or absolute.
path: []const u8,

Expand All @@ -1641,37 +1643,37 @@ pub const FileSource = union(enum) {

/// Returns a new file source that will have a relative path to the build root guaranteed.
/// This should be preferred over setting `.path` directly as it documents that the files are in the project directory.
pub fn relative(path: []const u8) FileSource {
pub fn relative(path: []const u8) LazyPath {
std.debug.assert(!std.fs.path.isAbsolute(path));
return FileSource{ .path = path };
return LazyPath{ .path = path };
}

/// Returns a string that can be shown to represent the file source.
/// Either returns the path or `"generated"`.
pub fn getDisplayName(self: FileSource) []const u8 {
pub fn getDisplayName(self: LazyPath) []const u8 {
return switch (self) {
.path => self.path,
.generated => "generated",
};
}

/// Adds dependencies this file source implies to the given step.
pub fn addStepDependencies(self: FileSource, other_step: *Step) void {
pub fn addStepDependencies(self: LazyPath, other_step: *Step) void {
switch (self) {
.path => {},
.generated => |gen| other_step.dependOn(gen.step),
}
}

/// Should only be called during make(), returns a path relative to the build root or absolute.
pub fn getPath(self: FileSource, src_builder: *Build) []const u8 {
pub fn getPath(self: LazyPath, src_builder: *Build) []const u8 {
return getPath2(self, src_builder, null);
}

/// Should only be called during make(), returns a path relative to the build root or absolute.
/// asking_step is only used for debugging purposes; it's the step being run that is asking for
/// the path.
pub fn getPath2(self: FileSource, src_builder: *Build, asking_step: ?*Step) []const u8 {
pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 {
switch (self) {
.path => |p| return src_builder.pathFromRoot(p),
.generated => |gen| return gen.path orelse {
Expand All @@ -1684,7 +1686,7 @@ pub const FileSource = union(enum) {
}

/// Duplicates the file source for a given builder.
pub fn dupe(self: FileSource, b: *Build) FileSource {
pub fn dupe(self: LazyPath, b: *Build) LazyPath {
return switch (self) {
.path => |p| .{ .path = b.dupePath(p) },
.generated => |gen| .{ .generated = gen },
Expand Down
4 changes: 2 additions & 2 deletions lib/std/Build/Step/CheckFile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const mem = std.mem;
step: Step,
expected_matches: []const []const u8,
expected_exact: ?[]const u8,
source: std.Build.FileSource,
source: std.Build.LazyPath,
max_bytes: usize = 20 * 1024 * 1024,

pub const base_id = .check_file;
Expand All @@ -23,7 +23,7 @@ pub const Options = struct {

pub fn create(
owner: *std.Build,
source: std.Build.FileSource,
source: std.Build.LazyPath,
options: Options,
) *CheckFile {
const self = owner.allocator.create(CheckFile) catch @panic("OOM");
Expand Down
14 changes: 7 additions & 7 deletions lib/std/Build/Step/CheckObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ const Step = std.Build.Step;
pub const base_id = .check_object;

step: Step,
source: std.Build.FileSource,
source: std.Build.LazyPath,
max_bytes: usize = 20 * 1024 * 1024,
checks: std.ArrayList(Check),
obj_format: std.Target.ObjectFormat,

pub fn create(
owner: *std.Build,
source: std.Build.FileSource,
source: std.Build.LazyPath,
obj_format: std.Target.ObjectFormat,
) *CheckObject {
const gpa = owner.allocator;
Expand All @@ -44,7 +44,7 @@ pub fn create(

const SearchPhrase = struct {
string: []const u8,
file_source: ?std.Build.FileSource = null,
file_source: ?std.Build.LazyPath = null,

fn resolve(phrase: SearchPhrase, b: *std.Build, step: *Step) []const u8 {
const file_source = phrase.file_source orelse return phrase.string;
Expand Down Expand Up @@ -302,13 +302,13 @@ pub fn checkExact(self: *CheckObject, phrase: []const u8) void {
self.checkExactInner(phrase, null);
}

/// Like `checkExact()` but takes an additional argument `FileSource` which will be
/// Like `checkExact()` but takes an additional argument `LazyPath` which will be
/// resolved to a full search query in `make()`.
pub fn checkExactFileSource(self: *CheckObject, phrase: []const u8, file_source: std.Build.FileSource) void {
pub fn checkExactPath(self: *CheckObject, phrase: []const u8, file_source: std.Build.LazyPath) void {
self.checkExactInner(phrase, file_source);
}

fn checkExactInner(self: *CheckObject, phrase: []const u8, file_source: ?std.Build.FileSource) void {
fn checkExactInner(self: *CheckObject, phrase: []const u8, file_source: ?std.Build.LazyPath) void {
assert(self.checks.items.len > 0);
const last = &self.checks.items[self.checks.items.len - 1];
last.exact(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source });
Expand All @@ -321,7 +321,7 @@ pub fn checkContains(self: *CheckObject, phrase: []const u8) void {

/// Like `checkContains()` but takes an additional argument `FileSource` which will be
/// resolved to a full search query in `make()`.
pub fn checkContainsFileSource(self: *CheckObject, phrase: []const u8, file_source: std.Build.FileSource) void {
pub fn checkContainsPath(self: *CheckObject, phrase: []const u8, file_source: std.Build.LazyPath) void {
self.checkContainsInner(phrase, file_source);
}

Expand Down
Loading

0 comments on commit 52eeae2

Please sign in to comment.