feature. See also
. The project being documented here (as the example) is the Zig library itself.
Compile.create
pub fn create(owner: *std.Build, options: Options) *Compile
File
Code
pub fn create(owner: *std.Build, options: Options) *Compile {
const graph = owner.graph;
const arena = graph.arena;
const name = owner.dupe(options.name);
if (mem.find(u8, name, "/") != null or mem.find(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});
}
const resolved_target = options.root_module.resolved_target orelse
@panic("the root Module of a Compile step must be created with a known 'target' field");
const target = &resolved_target.result;
const step_name = owner.fmt("compile {s} {s} {s}", .{
if (options.kind.isTest() and mem.eql(u8, name, "test"))
@tagName(options.kind)
else
owner.fmt("{t} {s}", .{ options.kind, name }),
@tagName(options.root_module.optimize orelse .debug),
resolved_target.query.zigTriple(arena) catch @panic("OOM"),
});
const out_filename = std.zig.binNameAlloc(arena, .{
.root_name = name,
.cpu_arch = target.cpu.arch,
.os_tag = target.os.tag,
.ofmt = target.ofmt,
.abi = target.abi,
.output_mode = switch (options.kind) {
.lib => .Lib,
.obj, .test_obj => .Obj,
.exe, .@"test" => .Exe,
},
.link_mode = options.linkage,
.version = options.version,
}) catch @panic("OOM");
const compile = arena.create(Compile) catch @panic("OOM");
compile.* = .{
.root_module = options.root_module,
.verbose_link = false,
.verbose_cc = false,
.linkage = options.linkage,
.kind = options.kind,
.name = name,
.step = .init(.{
.tag = base_tag,
.name = step_name,
.owner = owner,
.max_rss = options.max_rss,
}),
.version = options.version,
.out_filename = out_filename,
.installed_headers = .empty,
.zig_lib_dir = null,
.filters = options.filters,
.test_runner = null,
.rdynamic = false,
.force_undefined_symbols = .empty,
.use_llvm = options.use_llvm,
.use_lld = options.use_lld,
.use_new_linker = null,
};
if (options.zig_lib_dir) |lp| {
compile.zig_lib_dir = lp.dupe(graph);
lp.addStepDependencies(&compile.step);
}
if (options.test_runner) |runner| {
compile.test_runner = .{
.path = runner.path.dupe(graph),
.mode = runner.mode,
};
runner.path.addStepDependencies(&compile.step);
}
// gets embedded, so for any other target the manifest file is just ignored.
if (target.ofmt == .coff) {
if (options.win32_manifest) |lp| {
compile.win32_manifest = lp.dupe(graph);
lp.addStepDependencies(&compile.step);
}
if (compile.kind == .lib and compile.linkage != null and compile.linkage.? == .dynamic) {
if (options.win32_module_definition) |lp| {
compile.win32_module_definition = lp.dupe(graph);
lp.addStepDependencies(&compile.step);
}
}
}
if (options.entitlements) |lp| {
compile.entitlements = lp.dupe(graph);
lp.addStepDependencies(&compile.step);
}
return compile;
}