Fields
step: Step
source: std.Build.LazyPath
include_dirs: std.ArrayList(std.Build.Module.IncludeDir) = .empty
system_libs: std.ArrayList(std.Build.Module.SystemLib) = .empty
cc_argv: std.ArrayList(Configuration.String) = .empty
target: std.Build.ResolvedTarget
optimize: std.builtin.Optimize
output_file: Configuration.GeneratedFileIndex
link_libc: bool
TranslateCstdfsmemStepLazyPathConfigurationbase_tagOptionscreateAddExecutableOptionsgetOutputaddModulecreateModulesetUpModuleaddAfterIncludePathaddSystemIncludePathaddIncludePathaddConfigHeaderaddSystemFrameworkPathaddFrameworkPathaddCheckFiledefineCMacrodefineCMacroRawaddCFlagslinkSystemLibrary
std.Build.Step.TranslateC.addAfterIncludePath
function
pub fn addAfterIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void
Parameters
translate_c: *TranslateC
lazy_path: LazyPath
std.Build.Step.TranslateC.addCFlags
function
Append arbitrary C compiler CLI arguments to the translation unit.
pub fn addCFlags(translate_c: *TranslateC, args: []const []const u8) void
Parameters
translate_c: *TranslateC
args: []const []const u8
std.Build.Step.TranslateC.addCheckFile
function
pub fn addCheckFile(translate_c: *TranslateC, expected_matches: []const []const u8) *Step.CheckFile
Parameters
translate_c: *TranslateC
expected_matches: []const []const u8
std.Build.Step.TranslateC.addConfigHeader
function
pub fn addConfigHeader(translate_c: *TranslateC, config_header: *Step.ConfigHeader) void
Parameters
translate_c: *TranslateC
config_header: *Step.ConfigHeader
std.Build.Step.TranslateC.AddExecutableOptions
container
Fields
std.Build.Step.TranslateC.addFrameworkPath
function
pub fn addFrameworkPath(translate_c: *TranslateC, directory_path: LazyPath) void
Parameters
translate_c: *TranslateC
directory_path: LazyPath
std.Build.Step.TranslateC.addIncludePath
function
pub fn addIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void
Parameters
translate_c: *TranslateC
lazy_path: LazyPath
std.Build.Step.TranslateC.addModule
function
Creates a module from the translated source and adds it to the package's
module set making it available to other packages which depend on this one.
createModule can be used instead to create a private module.
pub fn addModule(translate_c: *TranslateC, name: []const u8) *std.Build.Module
Parameters
translate_c: *TranslateC
name: []const u8
std.Build.Step.TranslateC.addSystemFrameworkPath
function
pub fn addSystemFrameworkPath(translate_c: *TranslateC, directory_path: LazyPath) void
Parameters
translate_c: *TranslateC
directory_path: LazyPath
std.Build.Step.TranslateC.addSystemIncludePath
function
pub fn addSystemIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void
Parameters
translate_c: *TranslateC
lazy_path: LazyPath
std.Build.Step.TranslateC.base_tag
constant
Step.Tag
std.Build.Step.TranslateC.Configuration
alias
Alias of std.Build.Configuration
std.Build.Step.TranslateC.create
function
pub fn create(owner: *std.Build, options: Options) *TranslateC
Parameters
std.Build.Step.TranslateC.createModule
function
Creates a private module from the translated source to be used by the
current package, but not exposed to other packages depending on this one.
addModule can be used instead to create a public module.
pub fn createModule(translate_c: *TranslateC) *std.Build.Module
Parameters
translate_c: *TranslateC
std.Build.Step.TranslateC.defineCMacro
function
If the value is omitted, it is set to 1.
name and value need not live longer than the function call.
pub fn defineCMacro(translate_c: *TranslateC, name: []const u8, value: ?[]const u8) void
Parameters
std.Build.Step.TranslateC.defineCMacroRaw
function
name_and_value looks like [name]=[value].
pub fn defineCMacroRaw(translate_c: *TranslateC, name_and_value: []const u8) void
Parameters
translate_c: *TranslateC
name_and_value: []const u8
std.Build.Step.TranslateC.fs
alias
Alias of std.fs
std.Build.Step.TranslateC.getOutput
function
pub fn getOutput(translate_c: *TranslateC) std.Build.LazyPath
Parameters
translate_c: *TranslateC
std.Build.Step.TranslateC.LazyPath
alias
Alias of std.Build.LazyPath
std.Build.Step.TranslateC.linkSystemLibrary
function
pub fn linkSystemLibrary( translate_c: *TranslateC, name: []const u8, options: std.Build.Module.LinkSystemLibraryOptions, ) void
Parameters
std.Build.Step.TranslateC.mem
alias
Alias of std.mem
std.Build.Step.TranslateC.Options
container
Fields
std.Build.Step.TranslateC.setUpModule
function
fn setUpModule(translate_c: *TranslateC, module: *std.Build.Module) *std.Build.Module
Parameters
translate_c: *TranslateC
module: *std.Build.Module
std.Build.Step.TranslateC.std
alias
Alias of std
std.Build.Step.TranslateC.Step
alias
Alias of std.Build.Step
std.Build.Step.TranslateC.TranslateC
alias
Alias of std.Build.Step.TranslateC
Source code
std/Build/Step/TranslateC.zig
const TranslateC = @This();
const std = @import("std");
const fs = std.fs;
const mem = std.mem;
const Step = std.Build.Step;
const LazyPath = std.Build.LazyPath;
const Configuration = std.Build.Configuration;
step: Step,
source: std.Build.LazyPath,
include_dirs: std.ArrayList(std.Build.Module.IncludeDir) = .empty,
system_libs: std.ArrayList(std.Build.Module.SystemLib) = .empty,
cc_argv: std.ArrayList(Configuration.String) = .empty,
target: std.Build.ResolvedTarget,
optimize: std.builtin.Optimize,
output_file: Configuration.GeneratedFileIndex,
link_libc: bool,
pub const base_tag: Step.Tag = .translate_c;
pub const Options = struct {
root_source_file: std.Build.LazyPath,
target: std.Build.ResolvedTarget,
optimize: std.builtin.Optimize,
link_libc: bool = true,
};
pub fn create(owner: *std.Build, options: Options) *TranslateC {
const graph = owner.graph;
const translate_c = graph.create(TranslateC);
const source = options.root_source_file.dupe(graph);
translate_c.* = .{
.step = .init(.{
.tag = base_tag,
.name = "translate-c",
.owner = owner,
}),
.source = source,
.target = options.target,
.optimize = options.optimize,
.output_file = graph.addGeneratedFile(&translate_c.step),
.link_libc = options.link_libc,
};
source.addStepDependencies(&translate_c.step);
return translate_c;
}
pub const AddExecutableOptions = struct {
name: ?[]const u8 = null,
version: ?std.SemanticVersion = null,
target: ?std.Build.ResolvedTarget = null,
optimize: ?std.builtin.Optimize = null,
linkage: ?std.builtin.LinkMode = null,
};
pub fn getOutput(translate_c: *TranslateC) std.Build.LazyPath {
return .{ .generated = .{ .index = translate_c.output_file } };
}
/// Creates a module from the translated source and adds it to the package's
/// module set making it available to other packages which depend on this one.
/// `createModule` can be used instead to create a private module.
pub fn addModule(translate_c: *TranslateC, name: []const u8) *std.Build.Module {
return setUpModule(translate_c, translate_c.step.owner.addModule(name, .{
.root_source_file = translate_c.getOutput(),
.target = translate_c.target,
.optimize = translate_c.optimize,
.link_libc = translate_c.link_libc,
}));
}
/// Creates a private module from the translated source to be used by the
/// current package, but not exposed to other packages depending on this one.
/// `addModule` can be used instead to create a public module.
pub fn createModule(translate_c: *TranslateC) *std.Build.Module {
return setUpModule(translate_c, translate_c.step.owner.createModule(.{
.root_source_file = translate_c.getOutput(),
.target = translate_c.target,
.optimize = translate_c.optimize,
.link_libc = translate_c.link_libc,
}));
}
fn setUpModule(translate_c: *TranslateC, module: *std.Build.Module) *std.Build.Module {
const graph = translate_c.step.owner.graph;
const arena = graph.arena;
if (translate_c.link_libc) module.link_libc = true;
for (translate_c.system_libs.items) |system_lib| {
module.link_objects.append(arena, .{ .system_lib = system_lib }) catch @panic("OOM");
}
return module;
}
pub fn addAfterIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void {
const graph = translate_c.step.owner.graph;
const arena = graph.arena;
translate_c.include_dirs.append(arena, .{ .path_after = lazy_path.dupe(graph) }) catch
@panic("OOM");
lazy_path.addStepDependencies(&translate_c.step);
}
pub fn addSystemIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void {
const graph = translate_c.step.owner.graph;
const arena = graph.arena;
translate_c.include_dirs.append(arena, .{ .path_system = lazy_path.dupe(graph) }) catch
@panic("OOM");
lazy_path.addStepDependencies(&translate_c.step);
}
pub fn addIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void {
const graph = translate_c.step.owner.graph;
const arena = graph.arena;
translate_c.include_dirs.append(arena, .{ .path = lazy_path.dupe(graph) }) catch
@panic("OOM");
lazy_path.addStepDependencies(&translate_c.step);
}
pub fn addConfigHeader(translate_c: *TranslateC, config_header: *Step.ConfigHeader) void {
const graph = translate_c.step.owner.graph;
const arena = graph.arena;
translate_c.include_dirs.append(arena, .{ .config_header_step = config_header }) catch
@panic("OOM");
translate_c.step.dependOn(&config_header.step);
}
pub fn addSystemFrameworkPath(translate_c: *TranslateC, directory_path: LazyPath) void {
const graph = translate_c.step.owner.graph;
const arena = graph.arena;
translate_c.include_dirs.append(arena, .{ .framework_path_system = directory_path.dupe(graph) }) catch
@panic("OOM");
directory_path.addStepDependencies(&translate_c.step);
}
pub fn addFrameworkPath(translate_c: *TranslateC, directory_path: LazyPath) void {
const graph = translate_c.step.owner.graph;
const arena = graph.arena;
translate_c.include_dirs.append(arena, .{ .framework_path = directory_path.dupe(graph) }) catch
@panic("OOM");
directory_path.addStepDependencies(&translate_c.step);
}
pub fn addCheckFile(translate_c: *TranslateC, expected_matches: []const []const u8) *Step.CheckFile {
return Step.CheckFile.create(
translate_c.step.owner,
translate_c.getOutput(),
.{ .expected_matches = expected_matches },
);
}
/// If the value is omitted, it is set to 1.
/// `name` and `value` need not live longer than the function call.
pub fn defineCMacro(translate_c: *TranslateC, name: []const u8, value: ?[]const u8) void {
const graph = translate_c.step.owner.graph;
const arena = graph.arena;
return addCFlags(translate_c, &.{
"-D",
arena.print("{s}={s}", .{ name, value orelse "1" }) catch @panic("OOM"),
});
}
/// name_and_value looks like [name]=[value].
pub fn defineCMacroRaw(translate_c: *TranslateC, name_and_value: []const u8) void {
return addCFlags(translate_c, &.{ "-D", name_and_value });
}
/// Append arbitrary C compiler CLI arguments to the translation unit.
pub fn addCFlags(translate_c: *TranslateC, args: []const []const u8) void {
const graph = translate_c.step.owner.graph;
const arena = graph.arena;
const wc = &graph.wip_configuration;
translate_c.cc_argv.ensureUnusedCapacity(arena, args.len) catch @panic("OOM");
for (args) |arg| translate_c.cc_argv.appendAssumeCapacity(wc.addString(arg) catch @panic("OOM"));
}
pub fn linkSystemLibrary(
translate_c: *TranslateC,
name: []const u8,
options: std.Build.Module.LinkSystemLibraryOptions,
) void {
const graph = translate_c.step.owner.graph;
const arena = graph.arena;
translate_c.system_libs.append(arena, .{
.name = graph.dupeString(name),
.needed = options.needed,
.weak = options.weak,
.use_pkg_config = options.use_pkg_config,
.preferred_link_mode = options.preferred_link_mode,
.search_strategy = options.search_strategy,
}) catch @panic("OOM");
}