Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Struct

TranslateC

Public Struct

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
c_macros: std.ArrayList(Configuration.String) = .empty
target: std.Build.ResolvedTarget
optimize: std.builtin.Optimize
output_file: Configuration.GeneratedFileIndex
link_libc: bool

Namespaces

Structs

Values

Functions

pub fn create(owner: *std.Build, options: Options) *TranslateC
pub fn getOutput(translate_c: *TranslateC) std.Build.LazyPath
pub fn addModule(translate_c: *TranslateC, name: []const u8) *std.Build.Module

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 createModule(translate_c: *TranslateC) *std.Build.Module

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.

fn setUpModule(translate_c: *TranslateC, module: *std.Build.Module) *std.Build.Module
pub fn addAfterIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void
pub fn addSystemIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void
pub fn addIncludePath(translate_c: *TranslateC, lazy_path: LazyPath) void
pub fn addConfigHeader(translate_c: *TranslateC, config_header: *Step.ConfigHeader) void
pub fn addSystemFrameworkPath(translate_c: *TranslateC, directory_path: LazyPath) void
pub fn addFrameworkPath(translate_c: *TranslateC, directory_path: LazyPath) void
pub fn addCheckFile(translate_c: *TranslateC, expected_matches: []const []const u8) *Step.CheckFile
pub fn defineCMacro(translate_c: *TranslateC, name: []const u8, value: ?[]const u8) void

If the value is omitted, it is set to 1. name and value need not live longer than the function call.

pub fn defineCMacroRaw(translate_c: *TranslateC, name_and_value: []const u8) void

name_and_value looks like [name]=[value].

pub fn linkSystemLibrary(translate_c: *TranslateC, name: []const u8, options: std.Build.Module.LinkSystemLibraryOptions) void

File

Build/Step/TranslateC.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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,
c_macros: 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;
    const wc = &graph.wip_configuration;
    const macro = arena.print("{s}={s}", .{ name, value orelse "1" }) catch @panic("OOM");
    const macro_string = wc.addString(macro) catch @panic("OOM");
    translate_c.c_macros.append(arena, macro_string) catch @panic("OOM");
}

/// name_and_value looks like [name]=[value].
pub fn defineCMacroRaw(translate_c: *TranslateC, name_and_value: []const u8) void {
    const graph = translate_c.step.owner.graph;
    const arena = graph.arena;
    const wc = &graph.wip_configuration;
    const macro_string = wc.addString(name_and_value) catch @panic("OOM");
    translate_c.c_macros.append(arena, macro_string) 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");
}