Document added/updated functions

Also renames `addHeaders` to `addHeadersDirectory` for clarity.
This commit is contained in:
Carl Åstholm 2024-03-10 12:17:33 +01:00
parent 5af4e91e00
commit d99e44a157
4 changed files with 21 additions and 5 deletions

View file

@ -1583,6 +1583,7 @@ pub fn addInstallLibFile(b: *Build, source: LazyPath, dest_rel_path: []const u8)
return b.addInstallFileWithDir(source, .lib, dest_rel_path); 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 { pub fn addInstallHeaderFile(b: *Build, source: LazyPath, dest_rel_path: []const u8) *Step.InstallFile {
return b.addInstallFileWithDir(source, .header, dest_rel_path); return b.addInstallFileWithDir(source, .header, dest_rel_path);
} }

View file

@ -446,6 +446,9 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
return self; 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 { pub fn installHeader(cs: *Compile, source: LazyPath, dest_rel_path: []const u8) void {
const b = cs.step.owner; const b = cs.step.owner;
const installation: HeaderInstallation = .{ .file = .{ const installation: HeaderInstallation = .{ .file = .{
@ -457,7 +460,10 @@ pub fn installHeader(cs: *Compile, source: LazyPath, dest_rel_path: []const u8)
installation.getSource().addStepDependencies(&cs.step); 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, cs: *Compile,
source: LazyPath, source: LazyPath,
dest_rel_path: []const u8, dest_rel_path: []const u8,
@ -474,10 +480,16 @@ pub fn installHeaders(
installation.getSource().addStepDependencies(&cs.step); 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 { pub fn installConfigHeader(cs: *Compile, config_header: *Step.ConfigHeader) void {
cs.installHeader(config_header.getOutput(), config_header.include_path); 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 { pub fn installLibraryHeaders(cs: *Compile, lib: *Compile) void {
assert(lib.kind == .lib); assert(lib.kind == .lib);
const b = cs.step.owner; const b = cs.step.owner;

View file

@ -126,6 +126,9 @@ pub fn addCopyFile(wf: *WriteFile, source: std.Build.LazyPath, sub_path: []const
return file.getPath(); 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( pub fn addCopyDirectory(
wf: *WriteFile, wf: *WriteFile,
source: std.Build.LazyPath, source: std.Build.LazyPath,

View file

@ -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", libfoo.installHeader(b.addWriteFiles().add("d.h",
\\#define FOO_D "D" \\#define FOO_D "D"
\\ \\