Merge pull request #16446 from MasterQ32/buildsystem_rename_orgy

Build.zig rename orgy. Renames FileSource to LazyPath and others
This commit is contained in:
Andrew Kelley
2023-07-30 21:27:29 -07:00
committed by GitHub
73 changed files with 767 additions and 568 deletions

View File

@@ -36,7 +36,7 @@ pub fn build(b: *std.Build) !void {
const docgen_exe = b.addExecutable(.{
.name = "docgen",
.root_source_file = .{ .path = "doc/docgen.zig" },
.root_source_file = .{ .path = "tools/docgen.zig" },
.target = .{},
.optimize = .Debug,
});
@@ -45,9 +45,10 @@ 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.addArg("--zig-lib-dir");
docgen_cmd.addDirectoryArg(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) {
@@ -57,9 +58,8 @@ pub fn build(b: *std.Build) !void {
const autodoc_test = b.addTest(.{
.root_source_file = .{ .path = "lib/std/std.zig" },
.target = target,
.zig_lib_dir = .{ .path = "lib" },
});
autodoc_test.overrideZigLibDir("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(),
.install_dir = .prefix,
@@ -88,8 +88,8 @@ pub fn build(b: *std.Build) !void {
.name = "check-case",
.root_source_file = .{ .path = "test/src/Cases.zig" },
.optimize = optimize,
.main_pkg_path = .{ .path = "." },
});
check_case_exe.main_pkg_path = ".";
check_case_exe.stack_size = stack_size;
check_case_exe.single_threaded = single_threaded;
@@ -196,10 +196,6 @@ pub fn build(b: *std.Build) !void {
exe.pie = pie;
exe.sanitize_thread = sanitize_thread;
exe.entitlements = entitlements;
// TODO -femit-bin/-fno-emit-bin should be inferred by the build system
// based on whether or not the exe is run or installed.
// https://github.com/ziglang/zig/issues/16351
if (no_bin) exe.emit_bin = .no_emit;
exe.build_id = b.option(
std.Build.Step.Compile.BuildId,
@@ -208,7 +204,7 @@ pub fn build(b: *std.Build) !void {
);
if (!no_bin) {
const install_exe = b.addInstallArtifact(exe);
const install_exe = b.addInstallArtifact(exe, .{});
if (flat) {
install_exe.dest_dir = .prefix;
}
@@ -352,10 +348,9 @@ 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)
@@ -363,8 +358,8 @@ pub fn build(b: *std.Build) !void {
else
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
exe.addIncludePath(tracy_path);
exe.addCSourceFile(client_cpp, tracy_c_flags);
exe.addIncludePath(.{ .cwd_relative = tracy_path });
exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags });
if (!enable_llvm) {
exe.linkSystemLibraryName("c++");
}
@@ -554,7 +549,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");
@@ -603,7 +598,7 @@ fn addCmakeCfgOptionsToExe(
// useful for package maintainers
exe.headerpad_max_install_names = true;
}
exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
exe.addObjectFile(.{ .cwd_relative = b.pathJoin(&[_][]const u8{
cfg.cmake_binary_dir,
"zigcpp",
b.fmt("{s}{s}{s}", .{
@@ -611,11 +606,11 @@ fn addCmakeCfgOptionsToExe(
"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(.{ .cwd_relative = cfg.lld_include_dir });
exe.addIncludePath(.{ .cwd_relative = cfg.llvm_include_dir });
exe.addLibraryPath(.{ .cwd_relative = cfg.llvm_lib_dir });
addCMakeLibraryList(exe, cfg.clang_libraries);
addCMakeLibraryList(exe, cfg.lld_libraries);
addCMakeLibraryList(exe, cfg.llvm_libraries);
@@ -671,7 +666,7 @@ fn addCmakeCfgOptionsToExe(
}
if (cfg.dia_guids_lib.len != 0) {
exe.addObjectFile(cfg.dia_guids_lib);
exe.addObjectFile(.{ .cwd_relative = cfg.dia_guids_lib });
}
}
@@ -732,7 +727,7 @@ fn addCxxKnownPath(
}
return error.RequiredLibraryNotFound;
}
exe.addObjectFile(path_unpadded);
exe.addObjectFile(.{ .cwd_relative = path_unpadded });
// TODO a way to integrate with system c++ include files here
// c++ -E -Wp,-v -xc++ /dev/null
@@ -752,7 +747,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(.{ .cwd_relative = lib });
}
}
}

View File

@@ -188,10 +188,10 @@ pub fn main() !void {
usageAndErr(builder, false, stderr_stream);
};
} else if (mem.eql(u8, arg, "--zig-lib-dir")) {
builder.zig_lib_dir = nextArg(args, &arg_idx) orelse {
builder.zig_lib_dir = .{ .cwd_relative = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after {s}\n\n", .{arg});
usageAndErr(builder, false, stderr_stream);
};
} };
} else if (mem.eql(u8, arg, "--debug-log")) {
const next_arg = nextArg(args, &arg_idx) orelse {
std.debug.print("Expected argument after {s}\n\n", .{arg});

View File

@@ -57,6 +57,8 @@ pub const RunStep = @import("Build/Step/Run.zig");
pub const TranslateCStep = @import("Build/Step/TranslateC.zig");
/// deprecated: use `Step.WriteFile`.
pub const WriteFileStep = @import("Build/Step/WriteFile.zig");
/// deprecated: use `LazyPath`.
pub const FileSource = LazyPath;
install_tls: TopLevelStep,
uninstall_tls: TopLevelStep,
@@ -93,8 +95,7 @@ build_root: Cache.Directory,
cache_root: Cache.Directory,
global_cache_root: Cache.Directory,
cache: *Cache,
/// If non-null, overrides the default zig lib dir.
zig_lib_dir: ?[]const u8,
zig_lib_dir: ?LazyPath,
vcpkg_root: VcpkgRoot = .unattempted,
pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null,
args: ?[][]const u8 = null,
@@ -471,7 +472,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,
@@ -481,6 +482,8 @@ pub const ExecutableOptions = struct {
single_threaded: ?bool = null,
use_llvm: ?bool = null,
use_lld: ?bool = null,
zig_lib_dir: ?LazyPath = null,
main_pkg_path: ?LazyPath = null,
};
pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
@@ -497,12 +500,14 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
.single_threaded = options.single_threaded,
.use_llvm = options.use_llvm,
.use_lld = options.use_lld,
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
.main_pkg_path = options.main_pkg_path,
});
}
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,
@@ -510,6 +515,8 @@ pub const ObjectOptions = struct {
single_threaded: ?bool = null,
use_llvm: ?bool = null,
use_lld: ?bool = null,
zig_lib_dir: ?LazyPath = null,
main_pkg_path: ?LazyPath = null,
};
pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
@@ -524,12 +531,14 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
.single_threaded = options.single_threaded,
.use_llvm = options.use_llvm,
.use_lld = options.use_lld,
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
.main_pkg_path = options.main_pkg_path,
});
}
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,
@@ -538,6 +547,8 @@ pub const SharedLibraryOptions = struct {
single_threaded: ?bool = null,
use_llvm: ?bool = null,
use_lld: ?bool = null,
zig_lib_dir: ?LazyPath = null,
main_pkg_path: ?LazyPath = null,
};
pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile {
@@ -554,12 +565,14 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile
.single_threaded = options.single_threaded,
.use_llvm = options.use_llvm,
.use_lld = options.use_lld,
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
.main_pkg_path = options.main_pkg_path,
});
}
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,
@@ -568,6 +581,8 @@ pub const StaticLibraryOptions = struct {
single_threaded: ?bool = null,
use_llvm: ?bool = null,
use_lld: ?bool = null,
zig_lib_dir: ?LazyPath = null,
main_pkg_path: ?LazyPath = null,
};
pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile {
@@ -584,12 +599,14 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile
.single_threaded = options.single_threaded,
.use_llvm = options.use_llvm,
.use_lld = options.use_lld,
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
.main_pkg_path = options.main_pkg_path,
});
}
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,
@@ -600,6 +617,8 @@ pub const TestOptions = struct {
single_threaded: ?bool = null,
use_llvm: ?bool = null,
use_lld: ?bool = null,
zig_lib_dir: ?LazyPath = null,
main_pkg_path: ?LazyPath = null,
};
pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
@@ -616,15 +635,18 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
.single_threaded = options.single_threaded,
.use_llvm = options.use_llvm,
.use_lld = options.use_lld,
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
.main_pkg_path = options.main_pkg_path,
});
}
pub const AssemblyOptions = struct {
name: []const u8,
source_file: FileSource,
source_file: LazyPath,
target: CrossTarget,
optimize: std.builtin.Mode,
max_rss: usize = 0,
zig_lib_dir: ?LazyPath = null,
};
pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile {
@@ -635,8 +657,9 @@ pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile {
.target = options.target,
.optimize = options.optimize,
.max_rss = options.max_rss,
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
});
obj_step.addAssemblyFileSource(options.source_file.dupe(b));
obj_step.addAssemblyLazyPath(options.source_file.dupe(b));
return obj_step;
}
@@ -655,7 +678,7 @@ pub const ModuleDependency = struct {
};
pub const CreateModuleOptions = struct {
source_file: FileSource,
source_file: LazyPath,
dependencies: []const ModuleDependency = &.{},
};
@@ -1257,12 +1280,21 @@ fn printCmd(ally: Allocator, cwd: ?[]const u8, argv: []const []const u8) void {
std.debug.print("{s}\n", .{text});
}
/// This creates the install step and adds it to the dependencies of the
/// top-level install step, using all the default options.
/// See `addInstallArtifact` for a more flexible function.
pub fn installArtifact(self: *Build, artifact: *Step.Compile) void {
self.getInstallStep().dependOn(&self.addInstallArtifact(artifact).step);
self.getInstallStep().dependOn(&self.addInstallArtifact(artifact, .{}).step);
}
pub fn addInstallArtifact(self: *Build, artifact: *Step.Compile) *Step.InstallArtifact {
return Step.InstallArtifact.create(self, artifact);
/// This merely creates the step; it does not add it to the dependencies of the
/// top-level install step.
pub fn addInstallArtifact(
self: *Build,
artifact: *Step.Compile,
options: Step.InstallArtifact.Options,
) *Step.InstallArtifact {
return Step.InstallArtifact.create(self, artifact, options);
}
///`dest_rel_path` is relative to prefix path
@@ -1284,22 +1316,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);
}
@@ -1309,7 +1341,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 {
@@ -1322,12 +1354,13 @@ 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);
}
/// deprecated: https://github.com/ziglang/zig/issues/14943
pub fn pushInstalledFile(self: *Build, dir: InstallDir, dest_rel_path: []const u8) void {
const file = InstalledFile{
.dir = dir,
@@ -1357,6 +1390,11 @@ pub fn pathFromRoot(b: *Build, p: []const u8) []u8 {
return fs.path.resolve(b.allocator, &.{ b.build_root.path orelse ".", p }) catch @panic("OOM");
}
fn pathFromCwd(b: *Build, p: []const u8) []u8 {
const cwd = process.getCwdAlloc(b.allocator) catch @panic("OOM");
return fs.path.resolve(b.allocator, &.{ cwd, p }) catch @panic("OOM");
}
pub fn pathJoin(self: *Build, paths: []const []const u8) []u8 {
return fs.path.join(self.allocator, paths) catch @panic("OOM");
}
@@ -1608,7 +1646,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),
};
@@ -1630,50 +1668,64 @@ pub const GeneratedFile = struct {
}
};
/// A file source is a reference to an existing or future file.
pub const FileSource = union(enum) {
/// A plain file path, relative to build root or absolute.
/// A reference to an existing or future path.
pub const LazyPath = union(enum) {
/// A source file path relative to build root.
/// This should not be an absolute path, but in an older iteration of the zig build
/// system API, it was allowed to be absolute. Absolute paths should use `cwd_relative`.
path: []const u8,
/// A file that is generated by an interface. Those files usually are
/// not available until built by a build step.
generated: *const GeneratedFile,
/// An absolute path or a path relative to the current working directory of
/// the build runner process.
/// This is uncommon but used for system environment paths such as `--zig-lib-dir` which
/// ignore the file system path of build.zig and instead are relative to the directory from
/// which `zig build` was invoked.
/// Use of this tag indicates a dependency on the host system.
cwd_relative: []const u8,
/// 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 {
/// Asserts the parameter is not an absolute path.
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,
.path, .cwd_relative => 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 => {},
.path, .cwd_relative => {},
.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 {
/// Returns an absolute path.
/// Intended to be used during the make phase only.
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 {
/// Returns an absolute path.
/// Intended to be used during the make phase only.
///
/// `asking_step` is only used for debugging purposes; it's the step being
/// run that is asking for the path.
pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 {
switch (self) {
.path => |p| return src_builder.pathFromRoot(p),
.cwd_relative => |p| return src_builder.pathFromCwd(p),
.generated => |gen| return gen.path orelse {
std.debug.getStderrMutex().lock();
const stderr = std.io.getStdErr();
@@ -1684,16 +1736,17 @@ 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) },
.cwd_relative => |p| .{ .cwd_relative = b.dupePath(p) },
.generated => |gen| .{ .generated = gen },
};
}
};
/// In this function the stderr mutex has already been locked.
fn dumpBadGetPathHelp(
pub fn dumpBadGetPathHelp(
s: *Step,
stderr: fs.File,
src_builder: *Build,

View File

@@ -423,12 +423,7 @@ pub fn evalZigProcess(
});
}
if (s.cast(Compile)) |compile| if (compile.emit_bin == .no_emit) return result;
return result orelse return s.fail(
"the following command failed to communicate the compilation result:\n{s}",
.{try allocPrintCmd(arena, null, argv)},
);
return result;
}
fn sendMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag) !void {

View File

@@ -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;
@@ -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");

View File

@@ -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;
@@ -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;
@@ -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 });
@@ -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);
}

View File

@@ -11,7 +11,7 @@ const Allocator = mem.Allocator;
const Step = std.Build.Step;
const CrossTarget = std.zig.CrossTarget;
const NativeTargetInfo = std.zig.system.NativeTargetInfo;
const FileSource = std.Build.FileSource;
const LazyPath = std.Build.LazyPath;
const PkgConfigPkg = std.Build.PkgConfigPkg;
const PkgConfigError = std.Build.PkgConfigError;
const ExecError = std.Build.ExecError;
@@ -28,7 +28,7 @@ name: []const u8,
target: CrossTarget,
target_info: NativeTargetInfo,
optimize: std.builtin.Mode,
linker_script: ?FileSource = null,
linker_script: ?LazyPath = null,
version_script: ?[]const u8 = null,
out_filename: []const u8,
linkage: ?Linkage = null,
@@ -40,20 +40,12 @@ strip: ?bool,
unwind_tables: ?bool,
// keep in sync with src/link.zig:CompressDebugSections
compress_debug_sections: enum { none, zlib } = .none,
lib_paths: ArrayList(FileSource),
rpaths: ArrayList(FileSource),
framework_dirs: ArrayList(FileSource),
lib_paths: ArrayList(LazyPath),
rpaths: ArrayList(LazyPath),
framework_dirs: ArrayList(LazyPath),
frameworks: StringHashMap(FrameworkLinkInfo),
verbose_link: bool,
verbose_cc: bool,
emit_asm: EmitOption = .default,
emit_bin: EmitOption = .default,
emit_implib: EmitOption = .default,
emit_llvm_bc: EmitOption = .default,
emit_llvm_ir: EmitOption = .default,
// Lots of things depend on emit_h having a consistent path,
// so it is not an EmitOption for now.
emit_h: bool = false,
bundle_compiler_rt: ?bool = null,
single_threaded: ?bool,
stack_protector: ?bool = null,
@@ -74,8 +66,10 @@ max_memory: ?u64 = null,
shared_memory: bool = false,
global_base: ?u64 = null,
c_std: std.Build.CStd,
zig_lib_dir: ?[]const u8,
main_pkg_path: ?[]const u8,
/// Set via options; intended to be read-only after that.
zig_lib_dir: ?LazyPath,
/// Set via options; intended to be read-only after that.
main_pkg_path: ?LazyPath,
exec_cmd_args: ?[]const ?[]const u8,
filter: ?[]const u8,
test_evented_io: bool = false,
@@ -85,10 +79,8 @@ wasi_exec_model: ?std.builtin.WasiExecModel = null,
/// Symbols to be exported when compiling to wasm
export_symbol_names: []const []const u8 = &.{},
root_src: ?FileSource,
out_h_filename: []const u8,
root_src: ?LazyPath,
out_lib_filename: []const u8,
out_pdb_filename: []const u8,
modules: std.StringArrayHashMap(*Module),
link_objects: ArrayList(LinkObject),
@@ -99,14 +91,12 @@ is_linking_libc: bool,
is_linking_libcpp: bool,
vcpkg_bin_path: ?[]const u8 = null,
/// This may be set in order to override the default install directory
override_dest_dir: ?InstallDir,
installed_path: ?[]const u8,
/// Base address for an executable image.
image_base: ?u64 = null,
libc_file: ?FileSource = null,
libc_file: ?LazyPath = null,
valgrind_support: ?bool = null,
each_lib_rpath: ?bool = null,
@@ -210,35 +200,40 @@ use_lld: ?bool,
/// otherwise.
expect_errors: []const []const u8 = &.{},
output_path_source: GeneratedFile,
output_lib_path_source: GeneratedFile,
output_h_path_source: GeneratedFile,
output_pdb_path_source: GeneratedFile,
output_dirname_source: GeneratedFile,
emit_directory: ?*GeneratedFile,
generated_docs: ?*GeneratedFile,
generated_asm: ?*GeneratedFile,
generated_bin: ?*GeneratedFile,
generated_pdb: ?*GeneratedFile,
generated_implib: ?*GeneratedFile,
generated_llvm_bc: ?*GeneratedFile,
generated_llvm_ir: ?*GeneratedFile,
generated_h: ?*GeneratedFile,
pub const CSourceFiles = struct {
/// Relative to the build root.
files: []const []const u8,
flags: []const []const u8,
};
pub const CSourceFile = struct {
source: FileSource,
args: []const []const u8,
file: LazyPath,
flags: []const []const u8,
pub fn dupe(self: CSourceFile, b: *std.Build) CSourceFile {
return .{
.source = self.source.dupe(b),
.args = b.dupeStrings(self.args),
.file = self.file.dupe(b),
.flags = b.dupeStrings(self.flags),
};
}
};
pub const LinkObject = union(enum) {
static_path: FileSource,
static_path: LazyPath,
other_step: *Compile,
system_lib: SystemLib,
assembly_file: FileSource,
assembly_file: LazyPath,
c_source_file: *CSourceFile,
c_source_files: *CSourceFiles,
};
@@ -265,15 +260,15 @@ const FrameworkLinkInfo = struct {
};
pub const IncludeDir = union(enum) {
raw_path: []const u8,
raw_path_system: []const u8,
path: LazyPath,
path_system: LazyPath,
other_step: *Compile,
config_header_step: *Step.ConfigHeader,
};
pub const Options = struct {
name: []const u8,
root_source_file: ?FileSource = null,
root_source_file: ?LazyPath = null,
target: CrossTarget,
optimize: std.builtin.Mode,
kind: Kind,
@@ -286,6 +281,8 @@ pub const Options = struct {
single_threaded: ?bool = null,
use_llvm: ?bool = null,
use_lld: ?bool = null,
zig_lib_dir: ?LazyPath = null,
main_pkg_path: ?LazyPath = null,
};
pub const BuildId = union(enum) {
@@ -373,25 +370,9 @@ pub const Kind = enum {
pub const Linkage = enum { dynamic, static };
pub const EmitOption = union(enum) {
default: void,
no_emit: void,
emit: void,
emit_to: []const u8,
fn getArg(self: @This(), b: *std.Build, arg_name: []const u8) ?[]const u8 {
return switch (self) {
.no_emit => b.fmt("-fno-{s}", .{arg_name}),
.default => null,
.emit => b.fmt("-f{s}", .{arg_name}),
.emit_to => |path| b.fmt("-f{s}={s}", .{ arg_name, path }),
};
}
};
pub fn create(owner: *std.Build, options: Options) *Compile {
const name = owner.dupe(options.name);
const root_src: ?FileSource = if (options.root_source_file) |rsrc| rsrc.dupe(owner) else null;
const root_src: ?LazyPath = if (options.root_source_file) |rsrc| rsrc.dupe(owner) else null;
if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) {
panic("invalid name: '{s}'. It looks like a file path, but it is supposed to be the library or application name.", .{name});
}
@@ -453,18 +434,16 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
}),
.version = options.version,
.out_filename = out_filename,
.out_h_filename = owner.fmt("{s}.h", .{name}),
.out_lib_filename = undefined,
.out_pdb_filename = owner.fmt("{s}.pdb", .{name}),
.major_only_filename = null,
.name_only_filename = null,
.modules = std.StringArrayHashMap(*Module).init(owner.allocator),
.include_dirs = ArrayList(IncludeDir).init(owner.allocator),
.link_objects = ArrayList(LinkObject).init(owner.allocator),
.c_macros = ArrayList([]const u8).init(owner.allocator),
.lib_paths = ArrayList(FileSource).init(owner.allocator),
.rpaths = ArrayList(FileSource).init(owner.allocator),
.framework_dirs = ArrayList(FileSource).init(owner.allocator),
.lib_paths = ArrayList(LazyPath).init(owner.allocator),
.rpaths = ArrayList(LazyPath).init(owner.allocator),
.framework_dirs = ArrayList(LazyPath).init(owner.allocator),
.installed_headers = ArrayList(*Step).init(owner.allocator),
.c_std = std.Build.CStd.C99,
.zig_lib_dir = null,
@@ -476,16 +455,18 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
.disable_sanitize_c = false,
.sanitize_thread = false,
.rdynamic = false,
.override_dest_dir = null,
.installed_path = null,
.force_undefined_symbols = StringHashMap(void).init(owner.allocator),
.output_path_source = GeneratedFile{ .step = &self.step },
.output_lib_path_source = GeneratedFile{ .step = &self.step },
.output_h_path_source = GeneratedFile{ .step = &self.step },
.output_pdb_path_source = GeneratedFile{ .step = &self.step },
.output_dirname_source = GeneratedFile{ .step = &self.step },
.emit_directory = null,
.generated_docs = null,
.generated_asm = null,
.generated_bin = null,
.generated_pdb = null,
.generated_implib = null,
.generated_llvm_bc = null,
.generated_llvm_ir = null,
.generated_h = null,
.target_info = target_info,
@@ -496,6 +477,16 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
.use_lld = options.use_lld,
};
if (options.zig_lib_dir) |lp| {
self.zig_lib_dir = lp.dupe(self.step.owner);
lp.addStepDependencies(&self.step);
}
if (options.main_pkg_path) |lp| {
self.main_pkg_path = lp.dupe(self.step.owner);
lp.addStepDependencies(&self.step);
}
if (self.kind == .lib) {
if (self.linkage != null and self.linkage.? == .static) {
self.out_lib_filename = self.out_filename;
@@ -614,7 +605,7 @@ pub fn addObjCopy(cs: *Compile, options: Step.ObjCopy.Options) *Step.ObjCopy {
copy.basename = cs.name;
}
}
return b.addObjCopy(cs.getOutputSource(), copy);
return b.addObjCopy(cs.getEmittedBin(), copy);
}
/// This function would run in the context of the package that created the executable,
@@ -626,10 +617,13 @@ pub const run = @compileError("deprecated; use std.Build.addRunArtifact");
pub const install = @compileError("deprecated; use std.Build.installArtifact");
pub fn checkObject(self: *Compile) *Step.CheckObject {
return Step.CheckObject.create(self.step.owner, self.getOutputSource(), self.target_info.target.ofmt);
return Step.CheckObject.create(self.step.owner, self.getEmittedBin(), self.target_info.target.ofmt);
}
pub fn setLinkerScriptPath(self: *Compile, source: FileSource) void {
/// deprecated: use `setLinkerScript`
pub const setLinkerScriptPath = setLinkerScript;
pub fn setLinkerScript(self: *Compile, source: LazyPath) void {
const b = self.step.owner;
self.linker_script = source.dupe(b);
source.addStepDependencies(&self.step);
@@ -690,12 +684,18 @@ pub fn isStaticLibrary(self: *Compile) bool {
}
pub fn producesPdbFile(self: *Compile) bool {
// TODO: Is this right? Isn't PDB for *any* PE/COFF file?
// TODO: just share this logic with the compiler, silly!
if (!self.target.isWindows() and !self.target.isUefi()) return false;
if (self.target.getObjectFormat() == .c) return false;
if (self.strip == true or (self.strip == null and self.optimize == .ReleaseSmall)) return false;
return self.isDynamicLibrary() or self.kind == .exe or self.kind == .@"test";
}
pub fn producesImplib(self: *Compile) bool {
return self.isDynamicLibrary() and self.target.isWindows();
}
pub fn linkLibC(self: *Compile) void {
self.is_linking_libc = true;
}
@@ -935,19 +935,12 @@ pub fn addCSourceFiles(self: *Compile, files: []const []const u8, flags: []const
self.link_objects.append(.{ .c_source_files = c_source_files }) catch @panic("OOM");
}
pub fn addCSourceFile(self: *Compile, file: []const u8, flags: []const []const u8) void {
self.addCSourceFileSource(.{
.args = flags,
.source = .{ .path = file },
});
}
pub fn addCSourceFileSource(self: *Compile, source: CSourceFile) void {
pub fn addCSourceFile(self: *Compile, source: CSourceFile) void {
const b = self.step.owner;
const c_source_file = b.allocator.create(CSourceFile) catch @panic("OOM");
c_source_file.* = source.dupe(b);
self.link_objects.append(.{ .c_source_file = c_source_file }) catch @panic("OOM");
source.source.addStepDependencies(&self.step);
source.file.addStepDependencies(&self.step);
}
pub fn setVerboseLink(self: *Compile, value: bool) void {
@@ -958,80 +951,99 @@ pub fn setVerboseCC(self: *Compile, value: bool) void {
self.verbose_cc = value;
}
pub fn overrideZigLibDir(self: *Compile, dir_path: []const u8) void {
const b = self.step.owner;
self.zig_lib_dir = b.dupePath(dir_path);
}
pub fn setMainPkgPath(self: *Compile, dir_path: []const u8) void {
const b = self.step.owner;
self.main_pkg_path = b.dupePath(dir_path);
}
pub fn setLibCFile(self: *Compile, libc_file: ?FileSource) void {
pub fn setLibCFile(self: *Compile, libc_file: ?LazyPath) void {
const b = self.step.owner;
self.libc_file = if (libc_file) |f| f.dupe(b) else null;
}
/// Returns the generated executable, library or object file.
/// To run an executable built with zig build, use `run`, or create an install step and invoke it.
pub fn getOutputSource(self: *Compile) FileSource {
return .{ .generated = &self.output_path_source };
}
pub fn getOutputDirectorySource(self: *Compile) FileSource {
return .{ .generated = &self.output_dirname_source };
}
/// Returns the generated import library. This function can only be called for libraries.
pub fn getOutputLibSource(self: *Compile) FileSource {
assert(self.kind == .lib);
return .{ .generated = &self.output_lib_path_source };
}
/// Returns the generated header file.
/// This function can only be called for libraries or object files which have `emit_h` set.
pub fn getOutputHSource(self: *Compile) FileSource {
assert(self.kind != .exe and self.kind != .@"test");
assert(self.emit_h);
return .{ .generated = &self.output_h_path_source };
}
/// Returns the generated PDB file. This function can only be called for Windows and UEFI.
pub fn getOutputPdbSource(self: *Compile) FileSource {
// TODO: Is this right? Isn't PDB for *any* PE/COFF file?
assert(self.target.isWindows() or self.target.isUefi());
return .{ .generated = &self.output_pdb_path_source };
}
pub fn getEmittedDocs(self: *Compile) FileSource {
if (self.generated_docs) |g| return .{ .generated = g };
fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath {
if (output_file.*) |g| {
return .{ .generated = g };
}
const arena = self.step.owner.allocator;
const generated_file = arena.create(GeneratedFile) catch @panic("OOM");
generated_file.* = .{ .step = &self.step };
self.generated_docs = generated_file;
output_file.* = generated_file;
return .{ .generated = generated_file };
}
pub fn addAssemblyFile(self: *Compile, path: []const u8) void {
const b = self.step.owner;
self.link_objects.append(.{
.assembly_file = .{ .path = b.dupe(path) },
}) catch @panic("OOM");
/// deprecated: use `getEmittedBinDirectory`
pub const getOutputDirectorySource = getEmittedBinDirectory;
/// Returns the path to the directory that contains the emitted binary file.
pub fn getEmittedBinDirectory(self: *Compile) LazyPath {
_ = self.getEmittedBin();
return self.getEmittedFileGeneric(&self.emit_directory);
}
pub fn addAssemblyFileSource(self: *Compile, source: FileSource) void {
/// deprecated: use `getEmittedBin`
pub const getOutputSource = getEmittedBin;
/// Returns the path to the generated executable, library or object file.
/// To run an executable built with zig build, use `run`, or create an install step and invoke it.
pub fn getEmittedBin(self: *Compile) LazyPath {
return self.getEmittedFileGeneric(&self.generated_bin);
}
/// deprecated: use `getEmittedImplib`
pub const getOutputLibSource = getEmittedImplib;
/// Returns the path to the generated import library.
/// This function can only be called for libraries.
pub fn getEmittedImplib(self: *Compile) LazyPath {
assert(self.kind == .lib);
return self.getEmittedFileGeneric(&self.generated_implib);
}
/// deprecated: use `getEmittedH`
pub const getOutputHSource = getEmittedH;
/// Returns the path to the generated header file.
/// This function can only be called for libraries or objects.
pub fn getEmittedH(self: *Compile) LazyPath {
assert(self.kind != .exe and self.kind != .@"test");
return self.getEmittedFileGeneric(&self.generated_h);
}
/// deprecated: use `getEmittedPdb`.
pub const getOutputPdbSource = getEmittedPdb;
/// Returns the generated PDB file.
/// If the compilation does not produce a PDB file, this causes a FileNotFound error
/// at build time.
pub fn getEmittedPdb(self: *Compile) LazyPath {
_ = self.getEmittedBin();
return self.getEmittedFileGeneric(&self.generated_pdb);
}
/// Returns the path to the generated documentation directory.
pub fn getEmittedDocs(self: *Compile) LazyPath {
return self.getEmittedFileGeneric(&self.generated_docs);
}
/// Returns the path to the generated assembly code.
pub fn getEmittedAsm(self: *Compile) LazyPath {
return self.getEmittedFileGeneric(&self.generated_asm);
}
/// Returns the path to the generated LLVM IR.
pub fn getEmittedLlvmIr(self: *Compile) LazyPath {
return self.getEmittedFileGeneric(&self.generated_llvm_ir);
}
/// Returns the path to the generated LLVM BC.
pub fn getEmittedLlvmBc(self: *Compile) LazyPath {
return self.getEmittedFileGeneric(&self.generated_llvm_bc);
}
pub fn addAssemblyFile(self: *Compile, source: LazyPath) void {
const b = self.step.owner;
const source_duped = source.dupe(b);
self.link_objects.append(.{ .assembly_file = source_duped }) catch @panic("OOM");
source_duped.addStepDependencies(&self.step);
}
pub fn addObjectFile(self: *Compile, source_file: []const u8) void {
self.addObjectFileSource(.{ .path = source_file });
}
pub fn addObjectFileSource(self: *Compile, source: FileSource) void {
pub fn addObjectFile(self: *Compile, source: LazyPath) void {
const b = self.step.owner;
self.link_objects.append(.{ .static_path = source.dupe(b) }) catch @panic("OOM");
source.addStepDependencies(&self.step);
@@ -1042,14 +1054,16 @@ pub fn addObject(self: *Compile, obj: *Compile) void {
self.linkLibraryOrObject(obj);
}
pub fn addSystemIncludePath(self: *Compile, path: []const u8) void {
pub fn addSystemIncludePath(self: *Compile, path: LazyPath) void {
const b = self.step.owner;
self.include_dirs.append(IncludeDir{ .raw_path_system = b.dupe(path) }) catch @panic("OOM");
self.include_dirs.append(IncludeDir{ .path_system = path.dupe(b) }) catch @panic("OOM");
path.addStepDependencies(&self.step);
}
pub fn addIncludePath(self: *Compile, path: []const u8) void {
pub fn addIncludePath(self: *Compile, path: LazyPath) void {
const b = self.step.owner;
self.include_dirs.append(IncludeDir{ .raw_path = b.dupe(path) }) catch @panic("OOM");
self.include_dirs.append(IncludeDir{ .path = path.dupe(b) }) catch @panic("OOM");
path.addStepDependencies(&self.step);
}
pub fn addConfigHeader(self: *Compile, config_header: *Step.ConfigHeader) void {
@@ -1057,32 +1071,17 @@ pub fn addConfigHeader(self: *Compile, config_header: *Step.ConfigHeader) void {
self.include_dirs.append(.{ .config_header_step = config_header }) catch @panic("OOM");
}
pub fn addLibraryPath(self: *Compile, path: []const u8) void {
const b = self.step.owner;
self.lib_paths.append(.{ .path = b.dupe(path) }) catch @panic("OOM");
}
pub fn addLibraryPathDirectorySource(self: *Compile, directory_source: FileSource) void {
pub fn addLibraryPath(self: *Compile, directory_source: LazyPath) void {
self.lib_paths.append(directory_source) catch @panic("OOM");
directory_source.addStepDependencies(&self.step);
}
pub fn addRPath(self: *Compile, path: []const u8) void {
const b = self.step.owner;
self.rpaths.append(.{ .path = b.dupe(path) }) catch @panic("OOM");
}
pub fn addRPathDirectorySource(self: *Compile, directory_source: FileSource) void {
pub fn addRPath(self: *Compile, directory_source: LazyPath) void {
self.rpaths.append(directory_source) catch @panic("OOM");
directory_source.addStepDependencies(&self.step);
}
pub fn addFrameworkPath(self: *Compile, dir_path: []const u8) void {
const b = self.step.owner;
self.framework_dirs.append(.{ .path = b.dupe(dir_path) }) catch @panic("OOM");
}
pub fn addFrameworkPathDirectorySource(self: *Compile, directory_source: FileSource) void {
pub fn addFrameworkPath(self: *Compile, directory_source: LazyPath) void {
self.framework_dirs.append(directory_source) catch @panic("OOM");
directory_source.addStepDependencies(&self.step);
}
@@ -1168,7 +1167,11 @@ pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void {
}
fn linkLibraryOrObject(self: *Compile, other: *Compile) void {
self.step.dependOn(&other.step);
other.getEmittedBin().addStepDependencies(&self.step);
if (other.target.isWindows() and other.isDynamicLibrary()) {
other.getEmittedImplib().addStepDependencies(&self.step);
}
self.link_objects.append(.{ .other_step = other }) catch @panic("OOM");
self.include_dirs.append(.{ .other_step = other }) catch @panic("OOM");
@@ -1287,6 +1290,30 @@ fn constructDepString(
}
}
fn getGeneratedFilePath(self: *Compile, comptime tag_name: []const u8, asking_step: ?*Step) []const u8 {
const maybe_path: ?*GeneratedFile = @field(self, tag_name);
const generated_file = maybe_path orelse {
std.debug.getStderrMutex().lock();
const stderr = std.io.getStdErr();
std.Build.dumpBadGetPathHelp(&self.step, stderr, self.step.owner, asking_step) catch {};
@panic("missing emit option for " ++ tag_name);
};
const path = generated_file.path orelse {
std.debug.getStderrMutex().lock();
const stderr = std.io.getStdErr();
std.Build.dumpBadGetPathHelp(&self.step, stderr, self.step.owner, asking_step) catch {};
@panic(tag_name ++ " is null. Is there a missing step dependency?");
};
return path;
}
fn make(step: *Step, prog_node: *std.Progress.Node) !void {
const b = step.owner;
const self = @fieldParentPtr(Compile, "step", step);
@@ -1364,7 +1391,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
.exe => @panic("Cannot link with an executable build artifact"),
.@"test" => @panic("Cannot link with a test"),
.obj => {
try zig_args.append(other.getOutputSource().getPath(b));
try zig_args.append(other.getEmittedBin().getPath(b));
},
.lib => l: {
if (self.isStaticLibrary() and other.isStaticLibrary()) {
@@ -1372,7 +1399,12 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
break :l;
}
const full_path_lib = other.getOutputLibSource().getPath(b);
// For DLLs, we gotta link against the implib. For
// everything else, we directly link against the library file.
const full_path_lib = if (other.producesImplib())
other.getGeneratedFilePath("generated_implib", &self.step)
else
other.getGeneratedFilePath("generated_bin", &self.step);
try zig_args.append(full_path_lib);
if (other.linkage == Linkage.dynamic and !self.target.isWindows()) {
@@ -1432,7 +1464,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
},
.c_source_file => |c_source_file| {
if (c_source_file.args.len == 0) {
if (c_source_file.flags.len == 0) {
if (prev_has_cflags) {
try zig_args.append("-cflags");
try zig_args.append("--");
@@ -1440,13 +1472,13 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
}
} else {
try zig_args.append("-cflags");
for (c_source_file.args) |arg| {
for (c_source_file.flags) |arg| {
try zig_args.append(arg);
}
try zig_args.append("--");
prev_has_cflags = true;
}
try zig_args.append(c_source_file.source.getPath(b));
try zig_args.append(c_source_file.file.getPath(b));
},
.c_source_files => |c_source_files| {
@@ -1515,14 +1547,13 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
if (b.verbose_cc or self.verbose_cc) try zig_args.append("--verbose-cc");
if (b.verbose_llvm_cpu_features) try zig_args.append("--verbose-llvm-cpu-features");
if (self.emit_asm.getArg(b, "emit-asm")) |arg| try zig_args.append(arg);
if (self.emit_bin.getArg(b, "emit-bin")) |arg| try zig_args.append(arg);
if (self.generated_asm != null) try zig_args.append("-femit-asm");
if (self.generated_bin == null) try zig_args.append("-fno-emit-bin");
if (self.generated_docs != null) try zig_args.append("-femit-docs");
if (self.emit_implib.getArg(b, "emit-implib")) |arg| try zig_args.append(arg);
if (self.emit_llvm_bc.getArg(b, "emit-llvm-bc")) |arg| try zig_args.append(arg);
if (self.emit_llvm_ir.getArg(b, "emit-llvm-ir")) |arg| try zig_args.append(arg);
if (self.emit_h) try zig_args.append("-femit-h");
if (self.generated_implib != null) try zig_args.append("-femit-implib");
if (self.generated_llvm_bc != null) try zig_args.append("-femit-llvm-bc");
if (self.generated_llvm_ir != null) try zig_args.append("-femit-llvm-ir");
if (self.generated_h != null) try zig_args.append("-femit-h");
try addFlag(&zig_args, "strip", self.strip);
try addFlag(&zig_args, "unwind-tables", self.unwind_tables);
@@ -1746,18 +1777,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
for (self.include_dirs.items) |include_dir| {
switch (include_dir) {
.raw_path => |include_path| {
.path => |include_path| {
try zig_args.append("-I");
try zig_args.append(b.pathFromRoot(include_path));
try zig_args.append(include_path.getPath(b));
},
.raw_path_system => |include_path| {
.path_system => |include_path| {
if (b.sysroot != null) {
try zig_args.append("-iwithsysroot");
} else {
try zig_args.append("-isystem");
}
const resolved_include_path = b.pathFromRoot(include_path);
const resolved_include_path = include_path.getPath(b);
const common_include_path = if (builtin.os.tag == .windows and b.sysroot != null and fs.path.isAbsolute(resolved_include_path)) blk: {
// We need to check for disk designator and strip it out from dir path so
@@ -1774,10 +1805,9 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
try zig_args.append(common_include_path);
},
.other_step => |other| {
if (other.emit_h) {
const h_path = other.getOutputHSource().getPath(b);
if (other.generated_h) |header| {
try zig_args.append("-isystem");
try zig_args.append(fs.path.dirname(h_path).?);
try zig_args.append(fs.path.dirname(header.path.?).?);
}
if (other.installed_headers.items.len > 0) {
try zig_args.append("-I");
@@ -1810,7 +1840,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
zig_args.appendAssumeCapacity("-rpath");
if (self.target_info.target.isDarwin()) switch (rpath) {
.path => |path| {
.path, .cwd_relative => |path| {
// On Darwin, we should not try to expand special runtime paths such as
// * @executable_path
// * @loader_path
@@ -1907,15 +1937,12 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
if (self.zig_lib_dir) |dir| {
try zig_args.append("--zig-lib-dir");
try zig_args.append(b.pathFromRoot(dir));
} else if (b.zig_lib_dir) |dir| {
try zig_args.append("--zig-lib-dir");
try zig_args.append(dir);
try zig_args.append(dir.getPath(b));
}
if (self.main_pkg_path) |dir| {
try zig_args.append("--main-pkg-path");
try zig_args.append(b.pathFromRoot(dir));
try zig_args.append(dir.getPath(b));
}
try addFlag(&zig_args, "PIC", self.force_pic);
@@ -2008,33 +2035,51 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
if (maybe_output_bin_path) |output_bin_path| {
const output_dir = fs.path.dirname(output_bin_path).?;
self.output_dirname_source.path = output_dir;
self.output_path_source.path = b.pathJoin(
&.{ output_dir, self.out_filename },
);
if (self.kind == .lib) {
self.output_lib_path_source.path = b.pathJoin(
&.{ output_dir, self.out_lib_filename },
);
if (self.emit_directory) |lp| {
lp.path = output_dir;
}
if (self.emit_h) {
self.output_h_path_source.path = b.pathJoin(
&.{ output_dir, self.out_h_filename },
);
// -femit-bin[=path] (default) Output machine code
if (self.generated_bin) |bin| {
bin.path = b.pathJoin(&.{ output_dir, self.out_filename });
}
if (self.target.isWindows() or self.target.isUefi()) {
self.output_pdb_path_source.path = b.pathJoin(
&.{ output_dir, self.out_pdb_filename },
);
const sep = std.fs.path.sep;
// output PDB if someone requested it
if (self.generated_pdb) |pdb| {
pdb.path = b.fmt("{s}{c}{s}.pdb", .{ output_dir, sep, self.name });
}
// -femit-implib[=path] (default) Produce an import .lib when building a Windows DLL
if (self.generated_implib) |implib| {
implib.path = b.fmt("{s}{c}{s}.lib", .{ output_dir, sep, self.name });
}
// -femit-h[=path] Generate a C header file (.h)
if (self.generated_h) |lp| {
lp.path = b.fmt("{s}{c}{s}.h", .{ output_dir, sep, self.name });
}
// -femit-docs[=path] Create a docs/ dir with html documentation
if (self.generated_docs) |generated_docs| {
generated_docs.path = b.pathJoin(&.{ output_dir, "docs" });
}
// -femit-asm[=path] Output .s (assembly code)
if (self.generated_asm) |lp| {
lp.path = b.fmt("{s}{c}{s}.s", .{ output_dir, sep, self.name });
}
// -femit-llvm-ir[=path] Produce a .ll file with optimized LLVM IR (requires LLVM extensions)
if (self.generated_llvm_ir) |lp| {
lp.path = b.fmt("{s}{c}{s}.ll", .{ output_dir, sep, self.name });
}
// -femit-llvm-bc[=path] Produce an optimized LLVM module as a .bc file (requires LLVM extensions)
if (self.generated_llvm_bc) |lp| {
lp.path = b.fmt("{s}{c}{s}.bc", .{ output_dir, sep, self.name });
}
}
if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and
@@ -2042,7 +2087,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
{
try doAtomicSymLinks(
step,
self.getOutputSource().getPath(b),
self.getEmittedBin().getPath(b),
self.major_only_filename.?,
self.name_only_filename.?,
);

View File

@@ -6,16 +6,19 @@ const Allocator = std.mem.Allocator;
pub const Style = union(enum) {
/// The configure format supported by autotools. It uses `#undef foo` to
/// mark lines that can be substituted with different values.
autoconf: std.Build.FileSource,
autoconf: std.Build.LazyPath,
/// The configure format supported by CMake. It uses `@@FOO@@` and
/// `#cmakedefine` for template substitution.
cmake: std.Build.FileSource,
cmake: std.Build.LazyPath,
/// Instead of starting with an input file, start with nothing.
blank,
/// Start with nothing, like blank, and output a nasm .asm file.
nasm,
pub fn getFileSource(style: Style) ?std.Build.FileSource {
/// deprecated: use `getPath`
pub const getFileSource = getPath;
pub fn getPath(style: Style) ?std.Build.LazyPath {
switch (style) {
.autoconf, .cmake => |s| return s,
.blank, .nasm => return null,
@@ -54,7 +57,7 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader {
var include_path: []const u8 = "config.h";
if (options.style.getFileSource()) |s| switch (s) {
if (options.style.getPath()) |s| switch (s) {
.path => |p| {
const basename = std.fs.path.basename(p);
if (std.mem.endsWith(u8, basename, ".h.in")) {
@@ -68,7 +71,7 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader {
include_path = p;
}
const name = if (options.style.getFileSource()) |s|
const name = if (options.style.getPath()) |s|
owner.fmt("configure {s} header {s} to {s}", .{
@tagName(options.style), s.getDisplayName(), include_path,
})
@@ -98,7 +101,10 @@ pub fn addValues(self: *ConfigHeader, values: anytype) void {
return addValuesInner(self, values) catch @panic("OOM");
}
pub fn getFileSource(self: *ConfigHeader) std.Build.FileSource {
/// deprecated: use `getOutput`
pub const getFileSource = getOutput;
pub fn getOutput(self: *ConfigHeader) std.Build.LazyPath {
return .{ .generated = &self.output_file };
}

View File

@@ -3,100 +3,150 @@ const Step = std.Build.Step;
const InstallDir = std.Build.InstallDir;
const InstallArtifact = @This();
const fs = std.fs;
const LazyPath = std.Build.LazyPath;
step: Step,
dest_dir: ?InstallDir,
dest_sub_path: []const u8,
emitted_bin: ?LazyPath,
implib_dir: ?InstallDir,
emitted_implib: ?LazyPath,
pdb_dir: ?InstallDir,
emitted_pdb: ?LazyPath,
h_dir: ?InstallDir,
emitted_h: ?LazyPath,
dylib_symlinks: ?DylibSymlinkInfo,
artifact: *Step.Compile,
const DylibSymlinkInfo = struct {
major_only_filename: []const u8,
name_only_filename: []const u8,
};
pub const base_id = .install_artifact;
step: Step,
artifact: *Step.Compile,
dest_dir: InstallDir,
pdb_dir: ?InstallDir,
h_dir: ?InstallDir,
/// If non-null, adds additional path components relative to dest_dir, and
/// overrides the basename of the Compile step.
dest_sub_path: ?[]const u8,
pub const Options = struct {
/// Which installation directory to put the main output file into.
dest_dir: Dir = .default,
pdb_dir: Dir = .default,
h_dir: Dir = .default,
implib_dir: Dir = .default,
pub fn create(owner: *std.Build, artifact: *Step.Compile) *InstallArtifact {
/// Whether to install symlinks along with dynamic libraries.
dylib_symlinks: ?bool = null,
/// If non-null, adds additional path components relative to bin dir, and
/// overrides the basename of the Compile step for installation purposes.
dest_sub_path: ?[]const u8 = null,
pub const Dir = union(enum) {
disabled,
default,
override: InstallDir,
};
};
pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *InstallArtifact {
const self = owner.allocator.create(InstallArtifact) catch @panic("OOM");
self.* = InstallArtifact{
const dest_dir: ?InstallDir = switch (options.dest_dir) {
.disabled => null,
.default => switch (artifact.kind) {
.obj => @panic("object files have no standard installation procedure"),
.exe, .@"test" => InstallDir{ .bin = {} },
.lib => InstallDir{ .lib = {} },
},
.override => |o| o,
};
self.* = .{
.step = Step.init(.{
.id = base_id,
.name = owner.fmt("install {s}", .{artifact.name}),
.owner = owner,
.makeFn = make,
}),
.artifact = artifact,
.dest_dir = artifact.override_dest_dir orelse switch (artifact.kind) {
.obj => @panic("Cannot install a .obj build artifact."),
.exe, .@"test" => InstallDir{ .bin = {} },
.lib => InstallDir{ .lib = {} },
.dest_dir = dest_dir,
.pdb_dir = switch (options.pdb_dir) {
.disabled => null,
.default => if (artifact.producesPdbFile()) dest_dir else null,
.override => |o| o,
},
.pdb_dir = if (artifact.producesPdbFile()) blk: {
if (artifact.kind == .exe or artifact.kind == .@"test") {
break :blk InstallDir{ .bin = {} };
} else {
break :blk InstallDir{ .lib = {} };
}
.h_dir = switch (options.h_dir) {
.disabled => null,
// https://github.com/ziglang/zig/issues/9698
.default => null,
//.default => switch (artifact.kind) {
// .lib => .header,
// else => null,
//},
.override => |o| o,
},
.implib_dir = switch (options.implib_dir) {
.disabled => null,
.default => if (artifact.producesImplib()) dest_dir else null,
.override => |o| o,
},
.dylib_symlinks = if (options.dylib_symlinks orelse (dest_dir != null and
artifact.isDynamicLibrary() and
artifact.version != null and
artifact.target.wantSharedLibSymLinks())) .{
.major_only_filename = artifact.major_only_filename.?,
.name_only_filename = artifact.name_only_filename.?,
} else null,
.h_dir = if (artifact.kind == .lib and artifact.emit_h) .header else null,
.dest_sub_path = null,
.dest_sub_path = options.dest_sub_path orelse artifact.out_filename,
.emitted_bin = null,
.emitted_pdb = null,
.emitted_h = null,
.emitted_implib = null,
.artifact = artifact,
};
self.step.dependOn(&artifact.step);
owner.pushInstalledFile(self.dest_dir, artifact.out_filename);
if (self.artifact.isDynamicLibrary()) {
if (artifact.major_only_filename) |name| {
owner.pushInstalledFile(.lib, name);
}
if (artifact.name_only_filename) |name| {
owner.pushInstalledFile(.lib, name);
}
if (self.artifact.target.isWindows()) {
owner.pushInstalledFile(.lib, artifact.out_lib_filename);
}
}
if (self.pdb_dir) |pdb_dir| {
owner.pushInstalledFile(pdb_dir, artifact.out_pdb_filename);
}
if (self.h_dir) |h_dir| {
owner.pushInstalledFile(h_dir, artifact.out_h_filename);
}
if (self.dest_dir != null) self.emitted_bin = artifact.getEmittedBin();
if (self.pdb_dir != null) self.emitted_pdb = artifact.getEmittedPdb();
if (self.h_dir != null) self.emitted_h = artifact.getEmittedH();
if (self.implib_dir != null) self.emitted_implib = artifact.getEmittedImplib();
return self;
}
fn make(step: *Step, prog_node: *std.Progress.Node) !void {
_ = prog_node;
const self = @fieldParentPtr(InstallArtifact, "step", step);
const src_builder = self.artifact.step.owner;
const dest_builder = step.owner;
const dest_sub_path = if (self.dest_sub_path) |sub_path| sub_path else self.artifact.out_filename;
const full_dest_path = dest_builder.getInstallPath(self.dest_dir, dest_sub_path);
const cwd = fs.cwd();
var all_cached = true;
{
const full_src_path = self.artifact.getOutputSource().getPath(src_builder);
if (self.dest_dir) |dest_dir| {
const full_dest_path = dest_builder.getInstallPath(dest_dir, self.dest_sub_path);
const full_src_path = self.emitted_bin.?.getPath2(step.owner, step);
const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_dest_path, .{}) catch |err| {
return step.fail("unable to update file from '{s}' to '{s}': {s}", .{
full_src_path, full_dest_path, @errorName(err),
});
};
all_cached = all_cached and p == .fresh;
if (self.dylib_symlinks) |dls| {
try Step.Compile.doAtomicSymLinks(step, full_dest_path, dls.major_only_filename, dls.name_only_filename);
}
self.artifact.installed_path = full_dest_path;
}
if (self.artifact.isDynamicLibrary() and
self.artifact.version != null and
self.artifact.target.wantSharedLibSymLinks())
{
try Step.Compile.doAtomicSymLinks(step, full_dest_path, self.artifact.major_only_filename.?, self.artifact.name_only_filename.?);
}
if (self.artifact.isDynamicLibrary() and
self.artifact.target.isWindows() and
self.artifact.emit_implib != .no_emit)
{
const full_src_path = self.artifact.getOutputLibSource().getPath(src_builder);
const full_implib_path = dest_builder.getInstallPath(self.dest_dir, self.artifact.out_lib_filename);
if (self.implib_dir) |implib_dir| {
const full_src_path = self.emitted_implib.?.getPath2(step.owner, step);
const full_implib_path = dest_builder.getInstallPath(implib_dir, fs.path.basename(full_src_path));
const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_implib_path, .{}) catch |err| {
return step.fail("unable to update file from '{s}' to '{s}': {s}", .{
full_src_path, full_implib_path, @errorName(err),
@@ -104,9 +154,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
};
all_cached = all_cached and p == .fresh;
}
if (self.pdb_dir) |pdb_dir| {
const full_src_path = self.artifact.getOutputPdbSource().getPath(src_builder);
const full_pdb_path = dest_builder.getInstallPath(pdb_dir, self.artifact.out_pdb_filename);
const full_src_path = self.emitted_pdb.?.getPath2(step.owner, step);
const full_pdb_path = dest_builder.getInstallPath(pdb_dir, fs.path.basename(full_src_path));
const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_pdb_path, .{}) catch |err| {
return step.fail("unable to update file from '{s}' to '{s}': {s}", .{
full_src_path, full_pdb_path, @errorName(err),
@@ -114,9 +165,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
};
all_cached = all_cached and p == .fresh;
}
if (self.h_dir) |h_dir| {
const full_src_path = self.artifact.getOutputHSource().getPath(src_builder);
const full_h_path = dest_builder.getInstallPath(h_dir, self.artifact.out_h_filename);
const full_src_path = self.emitted_h.?.getPath2(step.owner, step);
const full_h_path = dest_builder.getInstallPath(h_dir, fs.path.basename(full_src_path));
const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_h_path, .{}) catch |err| {
return step.fail("unable to update file from '{s}' to '{s}': {s}", .{
full_src_path, full_h_path, @errorName(err),
@@ -124,6 +176,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
};
all_cached = all_cached and p == .fresh;
}
self.artifact.installed_path = full_dest_path;
step.result_cached = all_cached;
}

View File

@@ -2,7 +2,7 @@ const std = @import("std");
const mem = std.mem;
const fs = std.fs;
const Step = std.Build.Step;
const FileSource = std.Build.FileSource;
const LazyPath = std.Build.LazyPath;
const InstallDir = std.Build.InstallDir;
const InstallDirStep = @This();
@@ -15,7 +15,7 @@ dest_builder: *std.Build,
pub const base_id = .install_dir;
pub const Options = struct {
source_dir: FileSource,
source_dir: LazyPath,
install_dir: InstallDir,
install_subdir: []const u8,
/// File paths which end in any of these suffixes will be excluded

View File

@@ -1,6 +1,6 @@
const std = @import("std");
const Step = std.Build.Step;
const FileSource = std.Build.FileSource;
const LazyPath = std.Build.LazyPath;
const InstallDir = std.Build.InstallDir;
const InstallFile = @This();
const assert = std.debug.assert;
@@ -8,7 +8,7 @@ const assert = std.debug.assert;
pub const base_id = .install_file;
step: Step,
source: FileSource,
source: LazyPath,
dir: InstallDir,
dest_rel_path: []const u8,
/// This is used by the build system when a file being installed comes from one
@@ -17,7 +17,7 @@ dest_builder: *std.Build,
pub fn create(
owner: *std.Build,
source: FileSource,
source: LazyPath,
dir: InstallDir,
dest_rel_path: []const u8,
) *InstallFile {

View File

@@ -20,7 +20,7 @@ pub const RawFormat = enum {
};
step: Step,
file_source: std.Build.FileSource,
input_file: std.Build.LazyPath,
basename: []const u8,
output_file: std.Build.GeneratedFile,
@@ -37,30 +37,33 @@ pub const Options = struct {
pub fn create(
owner: *std.Build,
file_source: std.Build.FileSource,
input_file: std.Build.LazyPath,
options: Options,
) *ObjCopy {
const self = owner.allocator.create(ObjCopy) catch @panic("OOM");
self.* = ObjCopy{
.step = Step.init(.{
.id = base_id,
.name = owner.fmt("objcopy {s}", .{file_source.getDisplayName()}),
.name = owner.fmt("objcopy {s}", .{input_file.getDisplayName()}),
.owner = owner,
.makeFn = make,
}),
.file_source = file_source,
.basename = options.basename orelse file_source.getDisplayName(),
.input_file = input_file,
.basename = options.basename orelse input_file.getDisplayName(),
.output_file = std.Build.GeneratedFile{ .step = &self.step },
.format = options.format,
.only_section = options.only_section,
.pad_to = options.pad_to,
};
file_source.addStepDependencies(&self.step);
input_file.addStepDependencies(&self.step);
return self;
}
pub fn getOutputSource(self: *const ObjCopy) std.Build.FileSource {
/// deprecated: use getOutput
pub const getOutputSource = getOutput;
pub fn getOutput(self: *const ObjCopy) std.Build.LazyPath {
return .{ .generated = &self.output_file };
}
@@ -75,7 +78,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
// bytes when ObjCopy implementation is modified incompatibly.
man.hash.add(@as(u32, 0xe18b7baf));
const full_src_path = self.file_source.getPath(b);
const full_src_path = self.input_file.getPath(b);
_ = try man.addFile(full_src_path, null);
man.hash.addOptionalBytes(self.only_section);
man.hash.addOptional(self.pad_to);

View File

@@ -3,7 +3,7 @@ const builtin = @import("builtin");
const fs = std.fs;
const Step = std.Build.Step;
const GeneratedFile = std.Build.GeneratedFile;
const FileSource = std.Build.FileSource;
const LazyPath = std.Build.LazyPath;
const Options = @This();
@@ -13,8 +13,7 @@ step: Step,
generated_file: GeneratedFile,
contents: std.ArrayList(u8),
artifact_args: std.ArrayList(OptionArtifactArg),
file_source_args: std.ArrayList(OptionFileSourceArg),
args: std.ArrayList(Arg),
pub fn create(owner: *std.Build) *Options {
const self = owner.allocator.create(Options) catch @panic("OOM");
@@ -27,8 +26,7 @@ pub fn create(owner: *std.Build) *Options {
}),
.generated_file = undefined,
.contents = std.ArrayList(u8).init(owner.allocator),
.artifact_args = std.ArrayList(OptionArtifactArg).init(owner.allocator),
.file_source_args = std.ArrayList(OptionFileSourceArg).init(owner.allocator),
.args = std.ArrayList(Arg).init(owner.allocator),
};
self.generated_file = .{ .step = &self.step };
@@ -168,35 +166,39 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void {
}
}
/// The value is the path in the cache dir.
/// Adds a dependency automatically.
pub fn addOptionFileSource(
self: *Options,
name: []const u8,
source: FileSource,
) void {
self.file_source_args.append(.{
.name = name,
.source = source.dupe(self.step.owner),
}) catch @panic("OOM");
source.addStepDependencies(&self.step);
}
/// deprecated: use `addOptionPath`
pub const addOptionFileSource = addOptionPath;
/// The value is the path in the cache dir.
/// Adds a dependency automatically.
pub fn addOptionPath(
self: *Options,
name: []const u8,
path: LazyPath,
) void {
self.args.append(.{
.name = self.step.owner.dupe(name),
.path = path.dupe(self.step.owner),
}) catch @panic("OOM");
path.addStepDependencies(&self.step);
}
/// Deprecated: use `addOptionPath(options, name, artifact.getEmittedBin())` instead.
pub fn addOptionArtifact(self: *Options, name: []const u8, artifact: *Step.Compile) void {
self.artifact_args.append(.{ .name = self.step.owner.dupe(name), .artifact = artifact }) catch @panic("OOM");
self.step.dependOn(&artifact.step);
return addOptionPath(self, name, artifact.getEmittedBin());
}
pub fn createModule(self: *Options) *std.Build.Module {
return self.step.owner.createModule(.{
.source_file = self.getSource(),
.source_file = self.getOutput(),
.dependencies = &.{},
});
}
pub fn getSource(self: *Options) FileSource {
/// deprecated: use `getOutput`
pub const getSource = getOutput;
pub fn getOutput(self: *Options) LazyPath {
return .{ .generated = &self.generated_file };
}
@@ -207,19 +209,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
const b = step.owner;
const self = @fieldParentPtr(Options, "step", step);
for (self.artifact_args.items) |item| {
for (self.args.items) |item| {
self.addOption(
[]const u8,
item.name,
b.pathFromRoot(item.artifact.getOutputSource().getPath(b)),
);
}
for (self.file_source_args.items) |item| {
self.addOption(
[]const u8,
item.name,
item.source.getPath(b),
item.path.getPath(b),
);
}
@@ -229,7 +223,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
var hash = b.cache.hash;
// Random bytes to make unique. Refresh this with new random bytes when
// implementation is modified in a non-backwards-compatible way.
hash.add(@as(u32, 0x38845ef8));
hash.add(@as(u32, 0xad95e922));
hash.addBytes(self.contents.items);
const sub_path = "c" ++ fs.path.sep_str ++ hash.final() ++ fs.path.sep_str ++ basename;
@@ -294,14 +288,9 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
}
}
const OptionArtifactArg = struct {
const Arg = struct {
name: []const u8,
artifact: *Step.Compile,
};
const OptionFileSourceArg = struct {
name: []const u8,
source: FileSource,
path: LazyPath,
};
test Options {

View File

@@ -82,7 +82,7 @@ has_side_effects: bool = false,
pub const StdIn = union(enum) {
none,
bytes: []const u8,
file_source: std.Build.FileSource,
lazy_path: std.Build.LazyPath,
};
pub const StdIo = union(enum) {
@@ -120,15 +120,15 @@ pub const StdIo = union(enum) {
pub const Arg = union(enum) {
artifact: *Step.Compile,
file_source: PrefixedFileSource,
directory_source: PrefixedFileSource,
lazy_path: PrefixedLazyPath,
directory_source: PrefixedLazyPath,
bytes: []u8,
output: *Output,
};
pub const PrefixedFileSource = struct {
pub const PrefixedLazyPath = struct {
prefix: []const u8,
file_source: std.Build.FileSource,
lazy_path: std.Build.LazyPath,
};
pub const Output = struct {
@@ -164,14 +164,15 @@ pub fn enableTestRunnerMode(self: *Run) void {
}
pub fn addArtifactArg(self: *Run, artifact: *Step.Compile) void {
const bin_file = artifact.getEmittedBin();
bin_file.addStepDependencies(&self.step);
self.argv.append(Arg{ .artifact = artifact }) catch @panic("OOM");
self.step.dependOn(&artifact.step);
}
/// This provides file path as a command line argument to the command being
/// run, and returns a FileSource which can be used as inputs to other APIs
/// run, and returns a LazyPath which can be used as inputs to other APIs
/// throughout the build system.
pub fn addOutputFileArg(self: *Run, basename: []const u8) std.Build.FileSource {
pub fn addOutputFileArg(self: *Run, basename: []const u8) std.Build.LazyPath {
return self.addPrefixedOutputFileArg("", basename);
}
@@ -179,7 +180,7 @@ pub fn addPrefixedOutputFileArg(
self: *Run,
prefix: []const u8,
basename: []const u8,
) std.Build.FileSource {
) std.Build.LazyPath {
const b = self.step.owner;
const output = b.allocator.create(Output) catch @panic("OOM");
@@ -197,31 +198,43 @@ pub fn addPrefixedOutputFileArg(
return .{ .generated = &output.generated_file };
}
pub fn addFileSourceArg(self: *Run, file_source: std.Build.FileSource) void {
self.addPrefixedFileSourceArg("", file_source);
/// deprecated: use `addFileArg`
pub const addFileSourceArg = addFileArg;
pub fn addFileArg(self: *Run, lp: std.Build.LazyPath) void {
self.addPrefixedFileArg("", lp);
}
pub fn addPrefixedFileSourceArg(self: *Run, prefix: []const u8, file_source: std.Build.FileSource) void {
// deprecated: use `addPrefixedFileArg`
pub const addPrefixedFileSourceArg = addPrefixedFileArg;
pub fn addPrefixedFileArg(self: *Run, prefix: []const u8, lp: std.Build.LazyPath) void {
const b = self.step.owner;
const prefixed_file_source: PrefixedFileSource = .{
const prefixed_file_source: PrefixedLazyPath = .{
.prefix = b.dupe(prefix),
.file_source = file_source.dupe(b),
.lazy_path = lp.dupe(b),
};
self.argv.append(.{ .file_source = prefixed_file_source }) catch @panic("OOM");
file_source.addStepDependencies(&self.step);
self.argv.append(.{ .lazy_path = prefixed_file_source }) catch @panic("OOM");
lp.addStepDependencies(&self.step);
}
pub fn addDirectorySourceArg(self: *Run, directory_source: std.Build.FileSource) void {
self.addPrefixedDirectorySourceArg("", directory_source);
/// deprecated: use `addDirectoryArg`
pub const addDirectorySourceArg = addDirectoryArg;
pub fn addDirectoryArg(self: *Run, directory_source: std.Build.LazyPath) void {
self.addPrefixedDirectoryArg("", directory_source);
}
pub fn addPrefixedDirectorySourceArg(self: *Run, prefix: []const u8, directory_source: std.Build.FileSource) void {
// deprecated: use `addPrefixedDirectoryArg`
pub const addPrefixedDirectorySourceArg = addPrefixedDirectoryArg;
pub fn addPrefixedDirectoryArg(self: *Run, prefix: []const u8, directory_source: std.Build.LazyPath) void {
const b = self.step.owner;
const prefixed_directory_source: PrefixedFileSource = .{
const prefixed_directory_source: PrefixedLazyPath = .{
.prefix = b.dupe(prefix),
.file_source = directory_source.dupe(b),
.lazy_path = directory_source.dupe(b),
};
self.argv.append(.{ .directory_source = prefixed_directory_source }) catch @panic("OOM");
directory_source.addStepDependencies(&self.step);
@@ -239,7 +252,7 @@ pub fn addArgs(self: *Run, args: []const []const u8) void {
pub fn setStdIn(self: *Run, stdin: StdIn) void {
switch (stdin) {
.file_source => |file_source| file_source.addStepDependencies(&self.step),
.lazy_path => |lazy_path| lazy_path.addStepDependencies(&self.step),
.bytes, .none => {},
}
self.stdin = stdin;
@@ -331,7 +344,7 @@ pub fn addCheck(self: *Run, new_check: StdIo.Check) void {
}
}
pub fn captureStdErr(self: *Run) std.Build.FileSource {
pub fn captureStdErr(self: *Run) std.Build.LazyPath {
assert(self.stdio != .inherit);
if (self.captured_stderr) |output| return .{ .generated = &output.generated_file };
@@ -346,7 +359,7 @@ pub fn captureStdErr(self: *Run) std.Build.FileSource {
return .{ .generated = &output.generated_file };
}
pub fn captureStdOut(self: *Run) std.Build.FileSource {
pub fn captureStdOut(self: *Run) std.Build.LazyPath {
assert(self.stdio != .inherit);
if (self.captured_stdout) |output| return .{ .generated = &output.generated_file };
@@ -431,14 +444,14 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
try argv_list.append(bytes);
man.hash.addBytes(bytes);
},
.file_source => |file| {
const file_path = file.file_source.getPath(b);
.lazy_path => |file| {
const file_path = file.lazy_path.getPath(b);
try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path }));
man.hash.addBytes(file.prefix);
_ = try man.addFile(file_path, null);
},
.directory_source => |file| {
const file_path = file.file_source.getPath(b);
const file_path = file.lazy_path.getPath(b);
try argv_list.append(b.fmt("{s}{s}", .{ file.prefix, file_path }));
man.hash.addBytes(file.prefix);
man.hash.addBytes(file_path);
@@ -448,8 +461,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
// On Windows we don't have rpaths so we have to add .dll search paths to PATH
self.addPathForDynLibs(artifact);
}
const file_path = artifact.installed_path orelse
artifact.getOutputSource().getPath(b);
const file_path = artifact.installed_path orelse artifact.generated_bin.?.path.?; // the path is guaranteed to be set
try argv_list.append(file_path);
@@ -474,8 +486,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
.bytes => |bytes| {
man.hash.addBytes(bytes);
},
.file_source => |file_source| {
const file_path = file_source.getPath(b);
.lazy_path => |lazy_path| {
const file_path = lazy_path.getPath(b);
_ = try man.addFile(file_path, null);
},
.none => {},
@@ -1174,8 +1186,8 @@ fn evalGeneric(self: *Run, child: *std.process.Child) !StdIoResult {
child.stdin.?.close();
child.stdin = null;
},
.file_source => |file_source| {
const path = file_source.getPath(self.step.owner);
.lazy_path => |lazy_path| {
const path = lazy_path.getPath(self.step.owner);
const file = self.step.owner.build_root.handle.openFile(path, .{}) catch |err| {
return self.step.fail("unable to open stdin file: {s}", .{@errorName(err)});
};
@@ -1241,7 +1253,7 @@ fn addPathForDynLibs(self: *Run, artifact: *Step.Compile) void {
switch (link_object) {
.other_step => |other| {
if (other.target.isWindows() and other.isDynamicLibrary()) {
addPathDir(self, fs.path.dirname(other.getOutputSource().getPath(b)).?);
addPathDir(self, fs.path.dirname(other.getEmittedBin().getPath(b)).?);
addPathForDynLibs(self, other);
}
},

View File

@@ -9,7 +9,7 @@ const TranslateC = @This();
pub const base_id = .translate_c;
step: Step,
source: std.Build.FileSource,
source: std.Build.LazyPath,
include_dirs: std.ArrayList([]const u8),
c_macros: std.ArrayList([]const u8),
out_basename: []const u8,
@@ -18,7 +18,7 @@ optimize: std.builtin.OptimizeMode,
output_file: std.Build.GeneratedFile,
pub const Options = struct {
source_file: std.Build.FileSource,
source_file: std.Build.LazyPath,
target: CrossTarget,
optimize: std.builtin.OptimizeMode,
};
@@ -53,10 +53,14 @@ pub const AddExecutableOptions = struct {
linkage: ?Step.Compile.Linkage = null,
};
pub fn getOutput(self: *TranslateC) std.Build.LazyPath {
return .{ .generated = &self.output_file };
}
/// Creates a step to build an executable from the translated source.
pub fn addExecutable(self: *TranslateC, options: AddExecutableOptions) *Step.Compile {
return self.step.owner.addExecutable(.{
.root_source_file = .{ .generated = &self.output_file },
.root_source_file = self.getOutput(),
.name = options.name orelse "translated_c",
.version = options.version,
.target = options.target orelse self.target,
@@ -70,7 +74,7 @@ pub fn addExecutable(self: *TranslateC, options: AddExecutableOptions) *Step.Com
/// `createModule` can be used instead to create a private module.
pub fn addModule(self: *TranslateC, name: []const u8) *std.Build.Module {
return self.step.owner.addModule(name, .{
.source_file = .{ .generated = &self.output_file },
.source_file = self.getOutput(),
});
}
@@ -83,7 +87,7 @@ pub fn createModule(self: *TranslateC) *std.Build.Module {
module.* = .{
.builder = b,
.source_file = .{ .generated = &self.output_file },
.source_file = self.getOutput(),
.dependencies = std.StringArrayHashMap(*std.Build.Module).init(b.allocator),
};
return module;
@@ -96,7 +100,7 @@ pub fn addIncludeDir(self: *TranslateC, include_dir: []const u8) void {
pub fn addCheckFile(self: *TranslateC, expected_matches: []const []const u8) *Step.CheckFile {
return Step.CheckFile.create(
self.step.owner,
.{ .generated = &self.output_file },
self.getOutput(),
.{ .expected_matches = expected_matches },
);
}

View File

@@ -28,7 +28,10 @@ pub const File = struct {
sub_path: []const u8,
contents: Contents,
pub fn getFileSource(self: *File) std.Build.FileSource {
/// deprecated: use `getPath`
pub const getFileSource = getPath;
pub fn getPath(self: *File) std.Build.LazyPath {
return .{ .generated = &self.generated_file };
}
};
@@ -40,7 +43,7 @@ pub const OutputSourceFile = struct {
pub const Contents = union(enum) {
bytes: []const u8,
copy: std.Build.FileSource,
copy: std.Build.LazyPath,
};
pub fn create(owner: *std.Build) *WriteFile {
@@ -59,7 +62,7 @@ pub fn create(owner: *std.Build) *WriteFile {
return wf;
}
pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) std.Build.FileSource {
pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) std.Build.LazyPath {
const b = wf.step.owner;
const gpa = b.allocator;
const file = gpa.create(File) catch @panic("OOM");
@@ -70,7 +73,7 @@ pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) std.Build.Fi
};
wf.files.append(gpa, file) catch @panic("OOM");
wf.maybeUpdateName();
return file.getFileSource();
return file.getPath();
}
/// Place the file into the generated directory within the local cache,
@@ -80,7 +83,7 @@ pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) std.Build.Fi
/// include sub-directories, in which case this step will ensure the
/// required sub-path exists.
/// This is the option expected to be used most commonly with `addCopyFile`.
pub fn addCopyFile(wf: *WriteFile, source: std.Build.FileSource, sub_path: []const u8) std.Build.FileSource {
pub fn addCopyFile(wf: *WriteFile, source: std.Build.LazyPath, sub_path: []const u8) std.Build.LazyPath {
const b = wf.step.owner;
const gpa = b.allocator;
const file = gpa.create(File) catch @panic("OOM");
@@ -93,7 +96,7 @@ pub fn addCopyFile(wf: *WriteFile, source: std.Build.FileSource, sub_path: []con
wf.maybeUpdateName();
source.addStepDependencies(&wf.step);
return file.getFileSource();
return file.getLazyPath();
}
/// A path relative to the package root.
@@ -101,7 +104,7 @@ pub fn addCopyFile(wf: *WriteFile, source: std.Build.FileSource, sub_path: []con
/// used as part of the normal build process, but as a utility occasionally
/// run by a developer with intent to modify source files and then commit
/// those changes to version control.
pub fn addCopyFileToSource(wf: *WriteFile, source: std.Build.FileSource, sub_path: []const u8) void {
pub fn addCopyFileToSource(wf: *WriteFile, source: std.Build.LazyPath, sub_path: []const u8) void {
const b = wf.step.owner;
wf.output_source_files.append(b.allocator, .{
.contents = .{ .copy = source },
@@ -123,11 +126,13 @@ pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8)
}) catch @panic("OOM");
}
pub const getFileSource = @compileError("Deprecated; use the return value from add()/addCopyFile(), or use files[i].getFileSource()");
pub const getFileSource = @compileError("Deprecated; use the return value from add()/addCopyFile(), or use files[i].getPath()");
/// Returns a `FileSource` representing the base directory that contains all the
pub const getDirectorySource = getDirectory;
/// Returns a `LazyPath` representing the base directory that contains all the
/// files from this `WriteFile`.
pub fn getDirectorySource(wf: *WriteFile) std.Build.FileSource {
pub fn getDirectory(wf: *WriteFile) std.Build.LazyPath {
return .{ .generated = &wf.generated_directory };
}

View File

@@ -966,6 +966,8 @@ pub const File = struct {
}
pub fn linkAsArchive(base: *File, comp: *Compilation, prog_node: *std.Progress.Node) FlushError!void {
const emit = base.options.emit orelse return;
const tracy = trace(@src());
defer tracy.end();
@@ -973,8 +975,8 @@ pub const File = struct {
defer arena_allocator.deinit();
const arena = arena_allocator.allocator();
const directory = base.options.emit.?.directory; // Just an alias to make it shorter to type.
const full_out_path = try directory.join(arena, &[_][]const u8{base.options.emit.?.sub_path});
const directory = emit.directory; // Just an alias to make it shorter to type.
const full_out_path = try directory.join(arena, &[_][]const u8{emit.sub_path});
const full_out_path_z = try arena.dupeZ(u8, full_out_path);
// If there is no Zig code to compile, then we should skip flushing the output file

View File

@@ -1452,6 +1452,8 @@ pub fn updateDeclExports(
if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
}
if (self.base.options.emit == null) return;
const gpa = self.base.allocator;
const decl = mod.declPtr(decl_index);

View File

@@ -2865,6 +2865,8 @@ pub fn updateDeclExports(
if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
}
if (self.base.options.emit == null) return;
const tracy = trace(@src());
defer tracy.end();

View File

@@ -2386,6 +2386,8 @@ pub fn updateDeclExports(
return llvm_object.updateDeclExports(mod, decl_index, exports);
}
if (self.base.options.emit == null) return;
const tracy = trace(@src());
defer tracy.end();

View File

@@ -106,10 +106,11 @@ pub fn flushModule(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.No
if (build_options.skip_non_native) {
@panic("Attempted to compile for architecture that was disabled by build configuration");
}
const outfile = comp.bin_file.options.emit orelse return;
const tracy = trace(@src());
defer tracy.end();
const outfile = comp.bin_file.options.emit.?;
// We modify 'comp' before passing it to LLVM, but restore value afterwards.
// We tell LLVM to not try to build a .o, only an "assembly" file.
// This is required by the LLVM PTX backend.

View File

@@ -1712,6 +1712,8 @@ pub fn updateDeclExports(
if (wasm.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports);
}
if (wasm.base.options.emit == null) return;
const decl = mod.declPtr(decl_index);
const atom_index = try wasm.getOrCreateAtomForDecl(decl_index);
const atom = wasm.getAtom(atom_index);

View File

@@ -4,7 +4,7 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Test");
b.default_step = test_step;
inline for (.{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| {
for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| {
const exe = b.addExecutable(.{
.name = t,
.root_source_file = .{ .path = "main.c" },
@@ -13,6 +13,8 @@ pub fn build(b: *std.Build) void {
) catch unreachable,
});
exe.linkLibC();
// TODO: actually test the output
_ = exe.getEmittedBin();
test_step.dependOn(&exe.step);
}
}

View File

@@ -16,16 +16,16 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = .{},
});
lib_a.addCSourceFile("a.c", &[_][]const u8{});
lib_a.addIncludePath(".");
lib_a.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &[_][]const u8{} });
lib_a.addIncludePath(.{ .path = "." });
const lib_b = b.addStaticLibrary(.{
.name = "b",
.optimize = optimize,
.target = .{},
});
lib_b.addCSourceFile("b.c", &[_][]const u8{});
lib_b.addIncludePath(".");
lib_b.addCSourceFile(.{ .file = .{ .path = "b.c" }, .flags = &[_][]const u8{} });
lib_b.addIncludePath(.{ .path = "." });
const test_exe = b.addTest(.{
.root_source_file = .{ .path = "main.zig" },
@@ -33,7 +33,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
});
test_exe.linkLibrary(lib_a);
test_exe.linkLibrary(lib_b);
test_exe.addIncludePath(".");
test_exe.addIncludePath(.{ .path = "." });
test_step.dependOn(&b.addRunArtifact(test_exe).step);
}

View File

@@ -23,13 +23,13 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.name = "test",
.optimize = optimize,
});
exe.addSystemIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include" }) catch unreachable);
exe.addIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include/c++/v1" }) catch unreachable);
exe.addCSourceFile("test.cpp", &.{
exe.addSystemIncludePath(.{ .path = b.pathJoin(&.{ sdk.path, "/usr/include" }) });
exe.addIncludePath(.{ .path = b.pathJoin(&.{ sdk.path, "/usr/include/c++/v1" }) });
exe.addCSourceFile(.{ .file = .{ .path = "test.cpp" }, .flags = &.{
"-nostdlib++",
"-nostdinc++",
});
exe.addObjectFile(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/lib/libc++.tbd" }) catch unreachable);
} });
exe.addObjectFile(.{ .path = b.pathJoin(&.{ sdk.path, "/usr/lib/libc++.tbd" }) });
const run_cmd = b.addRunArtifact(exe);
run_cmd.expectStdErrEqual("x: 5\n");

View File

@@ -52,7 +52,7 @@ fn createScenario(
.optimize = optimize,
.target = target,
});
exe.addCSourceFile("main.c", &[0][]const u8{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
exe.linkLibC();
return exe;
}

View File

@@ -53,7 +53,7 @@ fn createScenario(
.name = name,
.optimize = optimize,
});
exe.addCSourceFile("main.c", &[0][]const u8{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
exe.linkLibC();
exe.linkFramework("Cocoa");
return exe;

View File

@@ -21,7 +21,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = target,
});
dylib.addCSourceFile("a.c", &.{});
dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
dylib.linkLibC();
const check_dylib = dylib.checkObject();
@@ -39,10 +39,10 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = target,
});
exe.addCSourceFile("main.c", &.{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
exe.linkSystemLibrary("a");
exe.addLibraryPathDirectorySource(dylib.getOutputDirectorySource());
exe.addRPathDirectorySource(dylib.getOutputDirectorySource());
exe.addLibraryPath(dylib.getEmittedBinDirectory());
exe.addRPath(dylib.getEmittedBinDirectory());
exe.linkLibC();
const check_exe = exe.checkObject();
@@ -55,7 +55,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
check_exe.checkStart();
check_exe.checkExact("cmd RPATH");
check_exe.checkExactFileSource("path", dylib.getOutputDirectorySource());
check_exe.checkExactPath("path", dylib.getOutputDirectorySource());
test_step.dependOn(&check_exe.step);
const run = b.addRunArtifact(exe);

View File

@@ -20,8 +20,8 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = target,
});
exe.addCSourceFile("main.c", &[0][]const u8{});
exe.addCSourceFile("empty.c", &[0][]const u8{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
exe.addCSourceFile(.{ .file = .{ .path = "empty.c" }, .flags = &[0][]const u8{} });
exe.linkLibC();
const run_cmd = b.addRunArtifact(exe);

View File

@@ -18,7 +18,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = .{ .os_tag = .macos },
});
exe.addCSourceFile("main.c", &.{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
exe.linkLibC();
exe.entry_symbol_name = "_non_main";

View File

@@ -18,7 +18,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = .{ .os_tag = .macos },
});
lib.addCSourceFile("main.c", &.{});
lib.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
lib.linkLibC();
const exe = b.addExecutable(.{

View File

@@ -18,7 +18,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = .{ .os_tag = .macos },
});
lib.addCSourceFile("bootstrap.c", &.{});
lib.addCSourceFile(.{ .file = .{ .path = "bootstrap.c" }, .flags = &.{} });
lib.linkLibC();
lib.linker_allow_shlib_undefined = true;
@@ -27,7 +27,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = .{ .os_tag = .macos },
});
exe.addCSourceFile("main.c", &.{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
exe.linkLibrary(lib);
exe.linkLibC();
exe.entry_symbol_name = "_bootstrap";

View File

@@ -113,7 +113,7 @@ fn simpleExe(
.name = name,
.optimize = optimize,
});
exe.addCSourceFile("main.c", &.{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
exe.linkLibC();
exe.linkFramework("CoreFoundation");
exe.linkFramework("Foundation");

View File

@@ -20,7 +20,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.name = "test",
.optimize = optimize,
});
exe.addCSourceFile("main.c", &[0][]const u8{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
exe.linkLibC();
exe.linkFrameworkNeeded("Cocoa");
exe.dead_strip_dylibs = true;

View File

@@ -21,7 +21,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = target,
});
dylib.addCSourceFile("a.c", &.{});
dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
dylib.linkLibC();
// -dead_strip_dylibs
@@ -31,11 +31,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = target,
});
exe.addCSourceFile("main.c", &[0][]const u8{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
exe.linkLibC();
exe.linkSystemLibraryNeeded("a");
exe.addLibraryPathDirectorySource(dylib.getOutputDirectorySource());
exe.addRPathDirectorySource(dylib.getOutputDirectorySource());
exe.addLibraryPath(dylib.getEmittedBinDirectory());
exe.addRPath(dylib.getEmittedBinDirectory());
exe.dead_strip_dylibs = true;
const check = exe.checkObject();

View File

@@ -18,9 +18,9 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.name = "test",
.optimize = optimize,
});
exe.addIncludePath(".");
exe.addCSourceFile("Foo.m", &[0][]const u8{});
exe.addCSourceFile("test.m", &[0][]const u8{});
exe.addIncludePath(.{ .path = "." });
exe.addCSourceFile(.{ .file = .{ .path = "Foo.m" }, .flags = &[0][]const u8{} });
exe.addCSourceFile(.{ .file = .{ .path = "test.m" }, .flags = &[0][]const u8{} });
exe.linkLibC();
// TODO when we figure out how to ship framework stubs for cross-compilation,
// populate paths to the sysroot here.

View File

@@ -19,9 +19,9 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
});
b.default_step.dependOn(&exe.step);
exe.addIncludePath(".");
exe.addCSourceFile("Foo.mm", &[0][]const u8{});
exe.addCSourceFile("test.mm", &[0][]const u8{});
exe.addIncludePath(.{ .path = "." });
exe.addCSourceFile(.{ .file = .{ .path = "Foo.mm" }, .flags = &[0][]const u8{} });
exe.addCSourceFile(.{ .file = .{ .path = "test.mm" }, .flags = &[0][]const u8{} });
exe.linkLibCpp();
// TODO when we figure out how to ship framework stubs for cross-compilation,
// populate paths to the sysroot here.

View File

@@ -15,7 +15,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.target = target,
});
exe.addCSourceFile("main.c", &.{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
exe.linkLibC();
exe.pagezero_size = 0x4000;
@@ -39,7 +39,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.target = target,
});
exe.addCSourceFile("main.c", &.{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
exe.linkLibC();
exe.pagezero_size = 0;

View File

@@ -55,11 +55,8 @@ fn createScenario(
.optimize = optimize,
.target = target,
});
static.addCSourceFile("a.c", &.{});
static.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
static.linkLibC();
static.override_dest_dir = std.Build.InstallDir{
.custom = "static",
};
const dylib = b.addSharedLibrary(.{
.name = name,
@@ -67,22 +64,19 @@ fn createScenario(
.optimize = optimize,
.target = target,
});
dylib.addCSourceFile("a.c", &.{});
dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
dylib.linkLibC();
dylib.override_dest_dir = std.Build.InstallDir{
.custom = "dynamic",
};
const exe = b.addExecutable(.{
.name = name,
.optimize = optimize,
.target = target,
});
exe.addCSourceFile("main.c", &.{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
exe.linkSystemLibraryName(name);
exe.linkLibC();
exe.addLibraryPathDirectorySource(static.getOutputDirectorySource());
exe.addLibraryPathDirectorySource(dylib.getOutputDirectorySource());
exe.addRPathDirectorySource(dylib.getOutputDirectorySource());
exe.addLibraryPath(static.getEmittedBinDirectory());
exe.addLibraryPath(dylib.getEmittedBinDirectory());
exe.addRPath(dylib.getEmittedBinDirectory());
return exe;
}

View File

@@ -20,7 +20,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = target,
});
exe.addCSourceFile("main.c", &.{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
exe.linkLibC();
exe.stack_size = 0x100000000;

View File

@@ -23,7 +23,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = target,
});
lib.addCSourceFile("a.c", &.{});
lib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
lib.linkLibC();
const tbd_file = b.addWriteFile("liba.tbd",
@@ -43,10 +43,10 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = target,
});
exe.addCSourceFile("main.c", &[0][]const u8{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
exe.linkSystemLibrary("a");
exe.addLibraryPathDirectorySource(tbd_file.getDirectorySource());
exe.addRPathDirectorySource(lib.getOutputDirectorySource());
exe.addLibraryPath(tbd_file.getDirectory());
exe.addRPath(lib.getEmittedBinDirectory());
exe.linkLibC();
const run = b.addRunArtifact(exe);

View File

@@ -21,7 +21,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = target,
});
lib.addCSourceFile("a.c", &.{});
lib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
lib.linkLibC();
const test_exe = b.addTest(.{

View File

@@ -75,7 +75,7 @@ fn createScenario(
.target = target,
});
b.default_step.dependOn(&exe.step);
exe.addIncludePath(".");
exe.addIncludePath(.{ .path = "." });
exe.addCSourceFiles(&[_][]const u8{
"main.cpp",
"simple_string.cpp",

View File

@@ -18,7 +18,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.name = "test",
.optimize = optimize,
});
exe.addCSourceFile("main.c", &[0][]const u8{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
exe.linkLibC();
exe.linkFrameworkWeak("Cocoa");

View File

@@ -21,7 +21,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.target = target,
.optimize = optimize,
});
dylib.addCSourceFile("a.c", &.{});
dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
dylib.linkLibC();
b.installArtifact(dylib);
@@ -30,11 +30,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.target = target,
.optimize = optimize,
});
exe.addCSourceFile("main.c", &[0][]const u8{});
exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
exe.linkLibC();
exe.linkSystemLibraryWeak("a");
exe.addLibraryPathDirectorySource(dylib.getOutputDirectorySource());
exe.addRPathDirectorySource(dylib.getOutputDirectorySource());
exe.addLibraryPath(dylib.getEmittedBinDirectory());
exe.addRPath(dylib.getEmittedBinDirectory());
const check = exe.checkObject();
check.checkStart();

View File

@@ -2,7 +2,7 @@ const std = @import("std");
const builtin = @import("builtin");
const Build = std.Build;
const FileSource = Build.FileSource;
const LazyPath = Build.LazyPath;
const Step = Build.Step;
const Run = Step.Run;
const WriteFile = Step.WriteFile;
@@ -14,7 +14,7 @@ pub fn build(b: *Build) void {
b.default_step = test_step;
// generate c files
const files = b.allocator.alloc(std.Build.FileSource, nb_files) catch unreachable;
const files = b.allocator.alloc(LazyPath, nb_files) catch unreachable;
defer b.allocator.free(files);
{
for (files[0 .. nb_files - 1], 1..nb_files) |*file, i| {
@@ -47,7 +47,7 @@ pub fn build(b: *Build) void {
add(b, test_step, files, .ReleaseFast);
}
fn add(b: *Build, test_step: *Step, files: []const std.Build.FileSource, optimize: std.builtin.OptimizeMode) void {
fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.builtin.OptimizeMode) void {
const flags = [_][]const u8{
"-Wall",
"-std=c11",
@@ -63,7 +63,7 @@ fn add(b: *Build, test_step: *Step, files: []const std.Build.FileSource, optimiz
});
for (files) |file| {
exe.addCSourceFileSource(.{ .source = file, .args = &flags });
exe.addCSourceFile(.{ .file = file, .flags = &flags });
}
const run_cmd = b.addRunArtifact(exe);
@@ -88,7 +88,7 @@ fn add(b: *Build, test_step: *Step, files: []const std.Build.FileSource, optimiz
for (files, 1..) |file, i| {
const lib = if (i & 1 == 0) lib_a else lib_b;
lib.addCSourceFileSource(.{ .source = file, .args = &flags });
lib.addCSourceFile(.{ .file = file, .flags = &flags });
}
const exe = b.addExecutable(.{
@@ -125,7 +125,7 @@ fn add(b: *Build, test_step: *Step, files: []const std.Build.FileSource, optimiz
.target = .{},
.optimize = optimize,
});
obj.addCSourceFileSource(.{ .source = file, .args = &flags });
obj.addCSourceFile(.{ .file = file, .flags = &flags });
const lib = if (i & 1 == 0) lib_a else lib_b;
lib.addObject(obj);

View File

@@ -19,7 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = .{ .cpu_arch = .wasm32, .os_tag = .wasi },
});
exe.addCSourceFile("foo.c", &.{});
exe.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &.{} });
exe.use_llvm = false;
exe.use_lld = false;

View File

@@ -13,7 +13,7 @@ pub fn build(b: *std.Build) void {
.os_tag = .freestanding,
},
});
c_obj.addCSourceFile("foo.c", &.{});
c_obj.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &.{} });
// Wasm library that doesn't have any features specified. This will
// infer its featureset from other linked object files.

View File

@@ -518,12 +518,12 @@ pub fn lowerToBuildSteps(
}
const writefiles = b.addWriteFiles();
var file_sources = std.StringHashMap(std.Build.FileSource).init(b.allocator);
var file_sources = std.StringHashMap(std.Build.LazyPath).init(b.allocator);
defer file_sources.deinit();
for (update.files.items) |file| {
file_sources.put(file.path, writefiles.add(file.path, file.src)) catch @panic("OOM");
}
const root_source_file = writefiles.files.items[0].getFileSource();
const root_source_file = writefiles.files.items[0].getPath();
const artifact = if (case.is_test) b.addTest(.{
.root_source_file = root_source_file,
@@ -551,8 +551,6 @@ pub fn lowerToBuildSteps(
}),
};
artifact.emit_bin = if (case.emit_bin) .default else .no_emit;
if (case.link_libc) artifact.linkLibC();
switch (case.backend) {
@@ -577,7 +575,7 @@ pub fn lowerToBuildSteps(
parent_step.dependOn(&artifact.step);
},
.CompareObjectFile => |expected_output| {
const check = b.addCheckFile(artifact.getOutputSource(), .{
const check = b.addCheckFile(artifact.getEmittedBin(), .{
.expected_exact = expected_output,
});

View File

@@ -99,7 +99,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void {
.target = .{},
.optimize = .Debug,
});
exe.addAssemblyFileSource(write_src.files.items[0].getFileSource());
exe.addAssemblyFile(write_src.files.items[0].getPath());
const run = b.addRunArtifact(exe);
run.setName(annotated_case_name);
@@ -119,7 +119,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void {
const exe = b.addExecutable(.{
.name = "test",
.root_source_file = write_src.files.items[0].getFileSource(),
.root_source_file = write_src.files.items[0].getPath(),
.optimize = optimize,
.target = .{},
});
@@ -145,7 +145,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void {
const exe = b.addExecutable(.{
.name = "test",
.root_source_file = write_src.files.items[0].getFileSource(),
.root_source_file = write_src.files.items[0].getPath(),
.target = .{},
.optimize = .Debug,
});

View File

@@ -75,7 +75,7 @@ fn addExpect(
const write_src = b.addWriteFile("source.zig", source);
const exe = b.addExecutable(.{
.name = "test",
.root_source_file = write_src.files.items[0].getFileSource(),
.root_source_file = write_src.files.items[0].getPath(),
.optimize = optimize_mode,
.target = .{},
});
@@ -88,7 +88,7 @@ fn addExpect(
const check_run = b.addRunArtifact(self.check_exe);
check_run.setName(annotated_case_name);
check_run.addFileSourceArg(run.captureStdErr());
check_run.addFileArg(run.captureStdErr());
check_run.addArgs(&.{
@tagName(optimize_mode),
});

View File

@@ -85,7 +85,7 @@ pub const RunTranslatedCContext = struct {
_ = write_src.add(src_file.filename, src_file.source);
}
const translate_c = b.addTranslateC(.{
.source_file = write_src.files.items[0].getFileSource(),
.source_file = write_src.files.items[0].getPath(),
.target = .{},
.optimize = .Debug,
});

View File

@@ -108,7 +108,7 @@ pub const TranslateCContext = struct {
}
const translate_c = b.addTranslateC(.{
.source_file = write_src.files.items[0].getFileSource(),
.source_file = write_src.files.items[0].getPath(),
.target = case.target,
.optimize = .Debug,
});

View File

@@ -19,7 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.optimize = optimize,
.target = target,
});
exe_c.addCSourceFile("test.c", &[0][]const u8{});
exe_c.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &[0][]const u8{} });
exe_c.linkLibC();
const exe_cpp = b.addExecutable(.{
@@ -28,7 +28,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.target = target,
});
b.default_step.dependOn(&exe_cpp.step);
exe_cpp.addCSourceFile("test.cpp", &[0][]const u8{});
exe_cpp.addCSourceFile(.{ .file = .{ .path = "test.cpp" }, .flags = &[0][]const u8{} });
exe_cpp.linkLibCpp();
switch (target.getOsTag()) {

View File

@@ -23,7 +23,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.target = target,
});
lib.addCSourceFile("shared_lib.c", &.{"-gdwarf"});
lib.addCSourceFile(.{ .file = .{ .path = "shared_lib.c" }, .flags = &.{"-gdwarf"} });
lib.linkLibC();
exe.linkLibrary(lib);

View File

@@ -16,7 +16,10 @@ pub fn build(b: *std.Build) void {
.target = target,
});
exe.linkLibC();
exe.addCSourceFile("main.c", &.{});
exe.addCSourceFile(.{
.file = .{ .path = "main.c" },
.flags = &.{},
});
exe.link_gc_sections = false;
exe.bundle_compiler_rt = true;

View File

@@ -19,8 +19,11 @@ pub fn build(b: *std.Build) void {
.optimize = .Debug,
});
exe.addAnonymousModule("bootloader.elf", .{
.source_file = bootloader.getOutputSource(),
.source_file = bootloader.getEmittedBin(),
});
// TODO: actually check the output
_ = exe.getEmittedBin();
test_step.dependOn(&exe.step);
}

View File

@@ -8,8 +8,9 @@ pub fn build(b: *std.Build) void {
.root_source_file = .{ .path = "main.zig" },
.optimize = b.standardOptimizeOption(.{}),
});
main.emit_asm = .{ .emit_to = b.pathFromRoot("main.s") };
main.emit_bin = .{ .emit_to = b.pathFromRoot("main") };
// TODO: actually check these two artifacts for correctness
_ = main.getEmittedBin();
_ = main.getEmittedAsm();
test_step.dependOn(&b.addRunArtifact(main).step);
}

View File

@@ -13,9 +13,8 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.target = target,
});
obj.emit_llvm_ir = .{ .emit_to = b.pathFromRoot("main.ll") };
obj.emit_llvm_bc = .{ .emit_to = b.pathFromRoot("main.bc") };
obj.emit_bin = .no_emit;
_ = obj.getEmittedLlvmIr();
_ = obj.getEmittedLlvmBc();
b.default_step.dependOn(&obj.step);
test_step.dependOn(&obj.step);

View File

@@ -14,5 +14,8 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});
// TODO: actually check the output
_ = obj.getEmittedBin();
test_step.dependOn(&obj.step);
}

View File

@@ -27,5 +27,8 @@ pub fn build(b: *std.Build) void {
exe.linkSystemLibrary("ntdll");
exe.addObject(obj);
// TODO: actually check the output
_ = exe.getEmittedBin();
test_step.dependOn(&exe.step);
}

View File

@@ -7,7 +7,10 @@ pub fn build(b: *std.Build) void {
const test_artifact = b.addTest(.{
.root_source_file = .{ .path = "main.zig" },
});
test_artifact.addIncludePath("a_directory");
test_artifact.addIncludePath(.{ .path = "a_directory" });
// TODO: actually check the output
_ = test_artifact.getEmittedBin();
test_step.dependOn(&test_artifact.step);
}

View File

@@ -19,8 +19,8 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize,
.target = target,
});
kernel.addObjectFile("./boot.S");
kernel.setLinkerScriptPath(.{ .path = "./linker.ld" });
kernel.addObjectFile(.{ .path = "./boot.S" });
kernel.setLinkerScript(.{ .path = "./linker.ld" });
b.installArtifact(kernel);
test_step.dependOn(&kernel.step);

View File

@@ -6,8 +6,8 @@ pub fn build(b: *std.Build) void {
const test_exe = b.addTest(.{
.root_source_file = .{ .path = "a/test.zig" },
.main_pkg_path = .{ .path = "." },
});
test_exe.setMainPkgPath(".");
test_step.dependOn(&b.addRunArtifact(test_exe).step);
}

View File

@@ -21,7 +21,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
.root_source_file = .{ .path = "main.zig" },
.optimize = optimize,
});
exe.addCSourceFile("test.c", &[_][]const u8{"-std=c11"});
exe.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &[_][]const u8{"-std=c11"} });
exe.linkLibC();
const run_cmd = b.addRunArtifact(exe);

View File

@@ -19,7 +19,10 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.target = target,
});
exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
exe.addCSourceFile(.{
.file = .{ .path = "test.c" },
.flags = &[_][]const u8{"-std=c99"},
});
exe.addObject(obj);
exe.linkSystemLibrary("c");

View File

@@ -19,7 +19,10 @@ pub fn build(b: *std.Build) void {
.target = target,
.optimize = optimize,
});
exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
exe.addCSourceFile(.{
.file = .{ .path = "test.c" },
.flags = &[_][]const u8{"-std=c99"},
});
exe.linkLibrary(lib);
exe.linkSystemLibrary("c");

View File

@@ -74,7 +74,10 @@ pub fn build(b: *std.Build) void {
if (target.isWindows()) c_shared_lib.defineCMacro("LIB_API", "__declspec(dllexport)");
c_shared_lib.strip = false;
c_shared_lib.addCSourceFile("shared_lib.c", &.{"-fomit-frame-pointer"});
c_shared_lib.addCSourceFile(.{
.file = .{ .path = "shared_lib.c" },
.flags = &.{"-fomit-frame-pointer"},
});
c_shared_lib.linkLibC();
const exe = b.addExecutable(.{

View File

@@ -11,15 +11,15 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.target = .{},
});
foo.addCSourceFile("foo.c", &[_][]const u8{});
foo.addIncludePath(".");
foo.addCSourceFile(.{ .file = .{ .path = "foo.c" }, .flags = &[_][]const u8{} });
foo.addIncludePath(.{ .path = "." });
const test_exe = b.addTest(.{
.root_source_file = .{ .path = "foo.zig" },
.optimize = optimize,
});
test_exe.linkLibrary(foo);
test_exe.addIncludePath(".");
test_exe.addIncludePath(.{ .path = "." });
test_step.dependOn(&b.addRunArtifact(test_exe).step);
}

View File

@@ -14,5 +14,9 @@ pub fn build(b: *std.Build) void {
.target = target,
});
main.strip = true;
// TODO: actually check the output
_ = main.getEmittedBin();
test_step.dependOn(&main.step);
}

View File

@@ -10,7 +10,7 @@ pub fn build(b: *std.Build) void {
.root_source_file = .{ .path = "main.zig" },
.optimize = optimize,
});
main.addIncludePath(".");
main.addIncludePath(.{ .path = "." });
test_step.dependOn(&b.addRunArtifact(main).step);
}

View File

@@ -588,6 +588,8 @@ pub fn addStandaloneTests(
});
if (case.link_libc) exe.linkLibC();
_ = exe.getEmittedBin();
step.dependOn(&exe.step);
}
@@ -759,7 +761,7 @@ pub fn addCliTests(b: *std.Build) *Step {
"-fno-emit-bin", "-fno-emit-h",
"-fstrip", "-OReleaseFast",
});
run.addFileSourceArg(writefile.files.items[0].getFileSource());
run.addFileArg(writefile.files.items[0].getPath());
const example_s = run.addPrefixedOutputFileArg("-femit-asm=", "example.s");
const checkfile = b.addCheckFile(example_s, .{
@@ -1006,6 +1008,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
.single_threaded = test_target.single_threaded,
.use_llvm = test_target.use_llvm,
.use_lld = test_target.use_lld,
.zig_lib_dir = .{ .path = "lib" },
});
const single_threaded_suffix = if (test_target.single_threaded == true) "-single" else "";
const backend_suffix = if (test_target.use_llvm == true)
@@ -1017,8 +1020,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
else
"";
these_tests.overrideZigLibDir("lib");
these_tests.addIncludePath("test");
these_tests.addIncludePath(.{ .path = "test" });
const qualified_name = b.fmt("{s}-{s}-{s}{s}{s}{s}", .{
options.name,
@@ -1037,11 +1039,11 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
.name = qualified_name,
.link_libc = test_target.link_libc,
.target = altered_target,
.zig_lib_dir = .{ .path = "lib" },
});
compile_c.overrideZigLibDir("lib");
compile_c.addCSourceFileSource(.{
.source = these_tests.getOutputSource(),
.args = &.{
compile_c.addCSourceFile(.{
.file = these_tests.getEmittedBin(),
.flags = &.{
// TODO output -std=c89 compatible C code
"-std=c99",
"-pedantic",
@@ -1058,7 +1060,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
"-Wno-absolute-value",
},
});
compile_c.addIncludePath("lib"); // for zig.h
compile_c.addIncludePath(.{ .path = "lib" }); // for zig.h
if (test_target.target.getOsTag() == .windows) {
if (true) {
// Unfortunately this requires about 8G of RAM for clang to compile
@@ -1131,7 +1133,10 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S
test_step.target_info.dynamic_linker.max_byte = null;
}
test_step.linkLibC();
test_step.addCSourceFile("test/c_abi/cfuncs.c", &.{"-std=c99"});
test_step.addCSourceFile(.{
.file = .{ .path = "test/c_abi/cfuncs.c" },
.flags = &.{"-std=c99"},
});
// This test is intentionally trying to check if the external ABI is
// done properly. LTO would be a hindrance to this.

View File

@@ -64,7 +64,9 @@ pub fn main() !void {
}
} else if (mem.eql(u8, arg, "--zig-lib-dir")) {
if (args_it.next()) |param| {
opt_zig_lib_dir = param;
// Convert relative to absolute because this will be passed
// to a child process with a different cwd.
opt_zig_lib_dir = try fs.realpathAlloc(allocator, param);
} else {
fatal("expected parameter after --zig-lib-dir", .{});
}