make
Function parameters
Parameters
- step:*Step
- options:Step.MakeOptions
Type definitions in this namespace
Types
Functions in this namespace
Functions
- addModule
- Creates a module from the translated source and adds it to the package's
- createModule
- Creates a private module from the translated source to be used by the
- defineCMacro
- If the value is omitted, it is set to 1.
- defineCMacroRaw
- name_and_value looks like [name]=[value].
= .translate_c
Values
- base_id
- = .translate_c
Source
Implementation
fn make(step: *Step, options: Step.MakeOptions) !void {
const prog_node = options.progress_node;
const b = step.owner;
const translate_c: *TranslateC = @fieldParentPtr("step", step);
var argv_list = std.array_list.Managed([]const u8).init(b.allocator);
try argv_list.append(b.graph.zig_exe);
try argv_list.append("translate-c");
if (translate_c.link_libc) {
try argv_list.append("-lc");
}
if (!translate_c.use_clang) {
try argv_list.append("-fno-clang");
}
try argv_list.append("--cache-dir");
try argv_list.append(b.cache_root.path orelse ".");
try argv_list.append("--global-cache-dir");
try argv_list.append(b.graph.global_cache_root.path orelse ".");
try argv_list.append("--listen=-");
if (!translate_c.target.query.isNative()) {
try argv_list.append("-target");
try argv_list.append(try translate_c.target.query.zigTriple(b.allocator));
}
switch (translate_c.optimize) {
.Debug => {}, // Skip since it's the default.
else => try argv_list.append(b.fmt("-O{s}", .{@tagName(translate_c.optimize)})),
}
for (translate_c.include_dirs.items) |include_dir| {
try include_dir.appendZigProcessFlags(b, &argv_list, step);
}
for (translate_c.c_macros.items) |c_macro| {
try argv_list.append("-D");
try argv_list.append(c_macro);
}
const c_source_path = translate_c.source.getPath2(b, step);
try argv_list.append(c_source_path);
const output_dir = try step.evalZigProcess(argv_list.items, prog_node, false, options.web_server, options.gpa);
const basename = std.fs.path.stem(std.fs.path.basename(c_source_path));
translate_c.out_basename = b.fmt("{s}.zig", .{basename});
translate_c.output_file.path = output_dir.?.joinString(b.allocator, translate_c.out_basename) catch @panic("OOM");
}