Skip to content

Commit

Permalink
Document added/updated functions
Browse files Browse the repository at this point in the history
Also renames `addHeaders` to `addHeadersDirectory` for clarity.
  • Loading branch information
castholm committed Mar 12, 2024
1 parent 45f7d19 commit bc52cd1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1560,21 +1560,22 @@ pub fn addObjCopy(b: *Build, source: LazyPath, options: Step.ObjCopy.Options) *S
return Step.ObjCopy.create(b, source, options);
}

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

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

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

/// `dest_rel_path` is relative to header path
pub fn addInstallHeaderFile(b: *Build, source: LazyPath, dest_rel_path: []const u8) *Step.InstallFile {
return b.addInstallFileWithDir(source, .header, dest_rel_path);
}
Expand Down
14 changes: 13 additions & 1 deletion lib/std/Build/Step/Compile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
return self;
}

/// Marks the specified header for installation alongside this artifact.
/// When a module links with this artifact, all headers marked for installation are added to that
/// module's include search path.
pub fn installHeader(cs: *Compile, source: LazyPath, dest_rel_path: []const u8) void {
const b = cs.step.owner;
const installation: HeaderInstallation = .{ .file = .{
Expand All @@ -454,7 +457,10 @@ pub fn installHeader(cs: *Compile, source: LazyPath, dest_rel_path: []const u8)
installation.getSource().addStepDependencies(&cs.step);
}

pub fn installHeaders(
/// Marks headers from the specified directory for installation alongside this artifact.
/// When a module links with this artifact, all headers marked for installation are added to that
/// module's include search path.
pub fn installHeadersDirectory(
cs: *Compile,
source: LazyPath,
dest_rel_path: []const u8,
Expand All @@ -471,10 +477,16 @@ pub fn installHeaders(
installation.getSource().addStepDependencies(&cs.step);
}

/// Marks the specified config header for installation alongside this artifact.
/// When a module links with this artifact, all headers marked for installation are added to that
/// module's include search path.
pub fn installConfigHeader(cs: *Compile, config_header: *Step.ConfigHeader) void {
cs.installHeader(config_header.getOutput(), config_header.include_path);
}

/// Forwards all headers marked for installation from `lib` to this artifact.
/// When a module links with this artifact, all headers marked for installation are added to that
/// module's include search path.
pub fn installLibraryHeaders(cs: *Compile, lib: *Compile) void {
assert(lib.kind == .lib);
const b = cs.step.owner;
Expand Down
3 changes: 3 additions & 0 deletions lib/std/Build/Step/WriteFile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ pub fn addCopyFile(wf: *WriteFile, source: std.Build.LazyPath, sub_path: []const
return file.getPath();
}

/// Copy files matching the specified exclude/include patterns to the specified subdirectory
/// relative to this step's generated directory.
/// The returned value is a lazy path to the generated subdirectory.
pub fn addCopyDirectory(
wf: *WriteFile,
source: std.Build.LazyPath,
Expand Down
2 changes: 1 addition & 1 deletion test/standalone/install_headers/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn build(b: *std.Build) void {
\\}
) });

libfoo.installHeaders(.{ .path = "include" }, "foo", .{ .exclude_extensions = &.{".ignore_me.h"} });
libfoo.installHeadersDirectory(.{ .path = "include" }, "foo", .{ .exclude_extensions = &.{".ignore_me.h"} });
libfoo.installHeader(b.addWriteFiles().add("d.h",
\\#define FOO_D "D"
\\
Expand Down

0 comments on commit bc52cd1

Please sign in to comment.