字段
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
函数
pub fn addAfterIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void
参数
translate_c: *TranslateC
lazy_path: LazyPath
std.Build.Step.TranslateC.addCFlags
函数
向翻译单元追加任意 C 编译器命令行参数。
pub fn addCFlags(translate_c: *TranslateC, args: []const []const u8) void
参数
translate_c: *TranslateC
args: []const []const u8
std.Build.Step.TranslateC.addCheckFile
函数
pub fn addCheckFile(translate_c: *TranslateC, expected_matches: []const []const u8) *Step.CheckFile
参数
translate_c: *TranslateC
expected_matches: []const []const u8
std.Build.Step.TranslateC.addConfigHeader
函数
pub fn addConfigHeader(translate_c: *TranslateC, config_header: *Step.ConfigHeader) void
参数
translate_c: *TranslateC
config_header: *Step.ConfigHeader
std.Build.Step.TranslateC.AddExecutableOptions
容器
字段
std.Build.Step.TranslateC.addFrameworkPath
函数
pub fn addFrameworkPath(translate_c: *TranslateC, directory_path: LazyPath) void
参数
translate_c: *TranslateC
directory_path: LazyPath
std.Build.Step.TranslateC.addIncludePath
函数
pub fn addIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void
参数
translate_c: *TranslateC
lazy_path: LazyPath
std.Build.Step.TranslateC.addModule
函数
根据转换后的源码创建模块,并将其加入包的
模块集合,使依赖此包的其他包可使用它。
可改用 createModule 创建私有模块。
pub fn addModule(translate_c: *TranslateC, name: []const u8) *std.Build.Module
参数
translate_c: *TranslateC
name: []const u8
std.Build.Step.TranslateC.addSystemFrameworkPath
函数
pub fn addSystemFrameworkPath(translate_c: *TranslateC, directory_path: LazyPath) void
参数
translate_c: *TranslateC
directory_path: LazyPath
std.Build.Step.TranslateC.addSystemIncludePath
函数
pub fn addSystemIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void
参数
translate_c: *TranslateC
lazy_path: LazyPath
std.Build.Step.TranslateC.base_tag
常量
Step.Tag
std.Build.Step.TranslateC.Configuration
别名
std.Build.Step.TranslateC.create
函数
pub fn create(owner: *std.Build, options: Options) *TranslateC
参数
std.Build.Step.TranslateC.createModule
函数
根据转换后的源码创建私有模块,供当前包使用,
但不向依赖本包的其他包暴露。
若要创建公共模块,可改用 addModule。
pub fn createModule(translate_c: *TranslateC) *std.Build.Module
参数
translate_c: *TranslateC
std.Build.Step.TranslateC.defineCMacro
函数
省略值时,将其设置为 1。
name 和 value 无需比函数调用存活更久。
pub fn defineCMacro(translate_c: *TranslateC, name: []const u8, value: ?[]const u8) void
参数
std.Build.Step.TranslateC.defineCMacroRaw
函数
name_and_value 的形式为 [name]=[value]。
pub fn defineCMacroRaw(translate_c: *TranslateC, name_and_value: []const u8) void
参数
translate_c: *TranslateC
name_and_value: []const u8
std.Build.Step.TranslateC.fs
别名
别名目标 std.fs
std.Build.Step.TranslateC.getOutput
函数
pub fn getOutput(translate_c: *TranslateC) std.Build.LazyPath
参数
translate_c: *TranslateC
std.Build.Step.TranslateC.LazyPath
别名
别名目标 std.Build.LazyPath
std.Build.Step.TranslateC.linkSystemLibrary
函数
pub fn linkSystemLibrary( translate_c: *TranslateC, name: []const u8, options: std.Build.Module.LinkSystemLibraryOptions, ) void
参数
std.Build.Step.TranslateC.mem
别名
别名目标 std.mem
std.Build.Step.TranslateC.Options
容器
字段
std.Build.Step.TranslateC.setUpModule
函数
fn setUpModule(translate_c: *TranslateC, module: *std.Build.Module) *std.Build.Module
参数
translate_c: *TranslateC
module: *std.Build.Module
std.Build.Step.TranslateC.std
别名
别名目标 std
std.Build.Step.TranslateC.Step
别名
别名目标 std.Build.Step
std.Build.Step.TranslateC.TranslateC
别名
源码
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 } };
}
/// 根据转换后的源码创建模块,并将其加入包的
/// 模块集合,使依赖此包的其他包可使用它。
/// 可改用 `createModule` 创建私有模块。
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,
}));
}
/// 根据转换后的源码创建私有模块,供当前包使用,
/// 但不向依赖本包的其他包暴露。
/// 若要创建公共模块,可改用 `addModule`。
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 },
);
}
/// 省略值时,将其设置为 1。
/// `name` 和 `value` 无需比函数调用存活更久。
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 的形式为 [name]=[value]。
pub fn defineCMacroRaw(translate_c: *TranslateC, name_and_value: []const u8) void {
return addCFlags(translate_c, &.{ "-D", name_and_value });
}
/// 向翻译单元追加任意 C 编译器命令行参数。
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");
}