Skip to content

rename std.Build.FileSource to std.Build.LazyPath #16353

Description

@andrewrk

zig/lib/std/Build.zig

Lines 1633 to 1634 in b9fc0d2

/// A file source is a reference to an existing or future file.
pubconstFileSource=union(enum) {

It's not really a "file", is it? It could be a directory:

/// Returns a `FileSource` representing the base directory that contains all the
/// files from this `WriteFile`.
pubfngetDirectorySource(wf: *WriteFile) std.Build.FileSource {
return .{ .generated=&wf.generated_directory };
}

"Source" is super confusing. Is it a source file? Not really, it could be an output artifact, or an input binary file.

The doc comment gives it away:

a reference to an existing or future file [or directory]

Therefore I propose:

-/// A file source is a reference to an existing or future file.-pub const FileSource = union(enum) {+/// A reference to an existing or future path.+pub const LazyPath = union(enum) {

As well as all functions such as getOutputSource to getOutput. For that one in particular, let's make it getEmittedBin, corresponding to -femit-bin (related: #16351). Here is a full list of suggested renames:

-std/Build/Step/Run.zig:pub fn addFileSourceArg(self: *Run, file_source: std.Build.FileSource) void {-std/Build/Step/Run.zig:pub fn addDirectorySourceArg(self: *Run, directory_source: std.Build.FileSource) void {+std/Build/Step/Run.zig:pub fn addPathArg(self: *Run, path: std.Build.LazyPath) void {-std/Build/Step/ObjCopy.zig:pub fn getOutputSource(self: *const ObjCopy) std.Build.FileSource {+std/Build/Step/ObjCopy.zig:pub fn getOutput(self: *const ObjCopy) std.Build.LazyPath {-std/Build/Step/ConfigHeader.zig: pub fn getFileSource(style: Style) ?std.Build.FileSource {+std/Build/Step/ConfigHeader.zig: pub fn getTemplate(style: Style) ?std.Build.LazyPath {-std/Build/Step/ConfigHeader.zig:pub fn getFileSource(self: *ConfigHeader) std.Build.FileSource {+std/Build/Step/ConfigHeader.zig:pub fn getOutput(self: *ConfigHeader) std.Build.LazyPath {-std/Build/Step/CheckObject.zig:pub fn checkNextFileSource(+std/Build/Step/CheckObject.zig:pub fn checkNextPath(-std/Build/Step/Options.zig:pub fn addOptionFileSource(+std/Build/Step/Options.zig:pub fn addOptionPath(-std/Build/Step/Options.zig:pub fn getSource(self: *Options) std.Build.FileSource {+std/Build/Step/Options.zig:pub fn getOutput(self: *Options) std.Build.LazyPath {-std/Build/Step/WriteFile.zig: pub fn getFileSource(self: *File) std.Build.FileSource {+std/Build/Step/WriteFile.zig: pub fn getPath(self: *File) std.Build.LazyPath {-std/Build/Step/WriteFile.zig:pub fn getDirectorySource(wf: *WriteFile) std.Build.FileSource {+std/Build/Step/WriteFile.zig:pub fn getDirectory(wf: *WriteFile) std.Build.LazyPath {-std/Build/Step/Compile.zig:pub fn addCSourceFile(self: *Compile, file: []const u8, flags: []const []const u8) void {-std/Build/Step/Compile.zig:pub fn addCSourceFileSource(self: *Compile, source: CSourceFile) void {+std/Build/Step/Compile.zig:pub fn addCSourceFile(self: *Compile, source: CSourceFile) void {-std/Build/Step/Compile.zig:pub fn getOutputSource(self: *Compile) std.Build.FileSource {+std/Build/Step/Compile.zig:pub fn getEmittedBin(self: *Compile) std.Build.LazyPath {-std/Build/Step/Compile.zig:pub fn getOutputDirectorySource(self: *Compile) std.Build.FileSource {+std/Build/Step/Compile.zig:pub fn getEmitDirectory(self: *Compile) std.Build.LazyPath {-std/Build/Step/Compile.zig:pub fn getOutputLibSource(self: *Compile) std.Build.FileSource {+std/Build/Step/Compile.zig:pub fn getEmittedImplib(self: *Compile) std.Build.LazyPath {-std/Build/Step/Compile.zig:pub fn getOutputHSource(self: *Compile) std.Build.FileSource {+std/Build/Step/Compile.zig:pub fn getEmittedH(self: *Compile) std.Build.LazyPath {-std/Build/Step/Compile.zig:pub fn getOutputPdbSource(self: *Compile) std.Build.FileSource {+std/Build/Step/Compile.zig:pub fn getEmittedPdb(self: *Compile) std.Build.LazyPath {-std/Build/Step/Compile.zig:pub fn addAssemblyFileSource(self: *Compile, source: std.Build.FileSource) void {+std/Build/Step/Compile.zig:pub fn addAssemblyFile(self: *Compile, source: std.Build.LazyPath) void {-std/Build/Step/Compile.zig:pub fn addObjectFileSource(self: *Compile, source: std.Build.FileSource) void {+std/Build/Step/Compile.zig:pub fn addObjectFile(self: *Compile, source: std.Build.LazyPath) void {-std/Build/Step/Compile.zig:pub fn addLibraryPathDirectorySource(self: *Compile, directory_source: std.Build.FileSource) void {+std/Build/Step/Compile.zig:pub fn addLibraryPath(self: *Compile, path: std.Build.LazyPath) void {-std/Build/Step/Compile.zig:pub fn addRPathDirectorySource(self: *Compile, directory_source: std.Build.FileSource) void {+std/Build/Step/Compile.zig:pub fn addRPath(self: *Compile, path: std.Build.LazyPath) void {-std/Build/Step/Compile.zig:pub fn addFrameworkPathDirectorySource(self: *Compile, directory_source: std.Build.FileSource) void {+std/Build/Step/Compile.zig:pub fn addFrameworkPath(self: *Compile, path: std.Build.LazyPath) void {

cc @MasterQ32 who originally introduced this crucial abstraction to the build system.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThis proposal is planned.breakingImplementing this issue could cause existing code to no longer compile or have different behavior.contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.zig build systemstd.Build, the build runner, `zig build` subcommand, package management

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions