跳转到内容

std.Build.Step.ObjCopy

标准库Zig 0.17.1官方原文
源码std/Build/Step/ObjCopy.zig

第 1 行

字段

step: Step
input_file: std.Build.LazyPath
basename: Configuration.OptionalString
output_file: Configuration.GeneratedFileIndex
debug_file: ?DebugFile
format: ?Format
only_section: Configuration.OptionalString
pad_to: ?u64
strip: Strip
compress_debug: bool
add_sections: std.ArrayList(AddSection) = .empty
update_sections: std.ArrayList(Configuration.Step.ObjCopy.UpdateSection) = .empty

std.Build.Step.ObjCopy.addSection

函数

第 108 行

pub fn addSection(oc: *ObjCopy, section_name: []const u8, options: AddSectionOptions) void

参数

oc: *ObjCopy
section_name: []const u8
options: AddSectionOptions

std.Build.Step.ObjCopy.AddSection

容器

第 28 行

字段

section_name: Configuration.String
file_path: std.Build.LazyPath

std.Build.Step.ObjCopy.AddSectionOptions

容器

第 104 行

字段

file_path: std.Build.LazyPath

std.Build.Step.ObjCopy.base_tag

常量

第 22 行

Step.Tag

std.Build.Step.ObjCopy.Configuration

别名

第 5 行

别名目标 std.Build.Configuration

std.Build.Step.ObjCopy.create

函数

第 59 行

pub fn create(owner: *std.Build, input_file: std.Build.LazyPath, options: Options) *ObjCopy

参数

owner: *std.Build
input_file: std.Build.LazyPath
options: Options

std.Build.Step.ObjCopy.DebugFile

容器

第 33 行

字段

std.Build.Step.ObjCopy.Format

容器

第 24 行

字段

binary
hex
elf

std.Build.Step.ObjCopy.getOutput

函数

第 119 行

pub fn getOutput(oc: *const ObjCopy) std.Build.LazyPath

参数

oc: *const ObjCopy

std.Build.Step.ObjCopy.getOutputSeparatedDebug

函数

第 123 行

pub fn getOutputSeparatedDebug(oc: *const ObjCopy) ?std.Build.LazyPath

参数

oc: *const ObjCopy

std.Build.Step.ObjCopy.ObjCopy

别名

第 1 行

别名目标 std.Build.Step.ObjCopy

std.Build.Step.ObjCopy.Options

容器

第 38 行

字段

basename: ?[]const u8 = null
format: ?Format = null
only_section: ?[]const u8 = null
pad_to: ?u64 = null
compress_debug: bool = false
strip: Strip = .none
separate_debug_file: ?SeparateDebugFile = null

将剥离的调试节放入单独文件。 注意:basename 会嵌入 ELF 文件,用于指定独立调试文件的链接。 参见 https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html。

使 getOutputSeparatedDebug 返回非空值。

std.Build.Step.ObjCopy.Options.SeparateDebugFile

容器

第 54 行

字段

basename: ?[]const u8

std.Build.Step.ObjCopy.SectionFlags

别名

第 26 行

别名目标 std.Build.Configuration.Step.ObjCopy.SectionFlags

std.Build.Step.ObjCopy.std

别名

第 3 行

别名目标 std

std.Build.Step.ObjCopy.Step

别名

第 4 行

别名目标 std.Build.Step

std.Build.Step.ObjCopy.Strip

别名

第 25 行

别名目标 std.Build.Configuration.Step.ObjCopy.Strip

std.Build.Step.ObjCopy.updateSection

函数

第 91 行

pub fn updateSection(oc: *ObjCopy, section_name: []const u8, options: UpdateSectionOptions) void

参数

oc: *ObjCopy
section_name: []const u8
options: UpdateSectionOptions

std.Build.Step.ObjCopy.UpdateSectionOptions

容器

第 86 行

字段

alignment: ?std.mem.Alignment = null
flags: SectionFlags = .default
源码

std/Build/Step/ObjCopy.zig

const ObjCopy = @This();

const std = @import("std");
const Step = std.Build.Step;
const Configuration = std.Build.Configuration;

step: Step,
input_file: std.Build.LazyPath,
basename: Configuration.OptionalString,
output_file: Configuration.GeneratedFileIndex,
debug_file: ?DebugFile,

format: ?Format,
only_section: Configuration.OptionalString,
pad_to: ?u64,
strip: Strip,
compress_debug: bool,

add_sections: std.ArrayList(AddSection) = .empty,
update_sections: std.ArrayList(Configuration.Step.ObjCopy.UpdateSection) = .empty,

pub const base_tag: Step.Tag = .obj_copy;

pub const Format = enum { binary, hex, elf };
pub const Strip = Configuration.Step.ObjCopy.Strip;
pub const SectionFlags = Configuration.Step.ObjCopy.SectionFlags;

pub const AddSection = struct {
    section_name: Configuration.String,
    file_path: std.Build.LazyPath,
};

pub const DebugFile = struct {
    basename: Configuration.OptionalString,
    output_file: Configuration.GeneratedFileIndex,
};

pub const Options = struct {
    basename: ?[]const u8 = null,
    format: ?Format = null,
    only_section: ?[]const u8 = null,
    pad_to: ?u64 = null,

    compress_debug: bool = false,
    strip: Strip = .none,

    /// 将剥离的调试节放入单独文件。
    /// 注意:`basename` 会嵌入 ELF 文件,用于指定独立调试文件的链接。
    /// 参见 https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html。
    ///
    /// 使 `getOutputSeparatedDebug` 返回非空值。
    separate_debug_file: ?SeparateDebugFile = null,

    pub const SeparateDebugFile = struct {
        basename: ?[]const u8,
    };
};

pub fn create(owner: *std.Build, input_file: std.Build.LazyPath, options: Options) *ObjCopy {
    const graph = owner.graph;
    const wc = &graph.wip_configuration;
    const oc = graph.create(ObjCopy);
    oc.* = .{
        .step = .init(.{
            .tag = base_tag,
            .name = owner.fmt("objcopy {f}", .{input_file}),
            .owner = owner,
        }),
        .input_file = input_file,
        .basename = if (options.basename) |s| .init(wc.addString(s) catch @panic("OOM")) else .none,
        .output_file = graph.addGeneratedFile(&oc.step),
        .debug_file = if (options.separate_debug_file) |df| .{
            .basename = if (df.basename) |s| .init(wc.addString(s) catch @panic("OOM")) else .none,
            .output_file = graph.addGeneratedFile(&oc.step),
        } else null,
        .format = options.format,
        .only_section = if (options.only_section) |s| .init(wc.addString(s) catch @panic("OOM")) else .none,
        .pad_to = options.pad_to,
        .strip = options.strip,
        .compress_debug = options.compress_debug,
    };
    input_file.addStepDependencies(&oc.step);
    return oc;
}

pub const UpdateSectionOptions = struct {
    alignment: ?std.mem.Alignment = null,
    flags: SectionFlags = .default,
};

pub fn updateSection(oc: *ObjCopy, section_name: []const u8, options: UpdateSectionOptions) void {
    const graph = oc.step.owner.graph;
    const arena = graph.arena;
    const wc = &graph.wip_configuration;
    oc.update_sections.append(arena, .{
        .flags = .{
            .section_flags = options.flags,
            .alignment = .init(options.alignment),
        },
        .section_name = wc.addString(section_name) catch @panic("OOM"),
    }) catch @panic("OOM");
}

pub const AddSectionOptions = struct {
    file_path: std.Build.LazyPath,
};

pub fn addSection(oc: *ObjCopy, section_name: []const u8, options: AddSectionOptions) void {
    const graph = oc.step.owner.graph;
    const arena = graph.arena;
    const wc = &graph.wip_configuration;
    oc.add_sections.append(arena, .{
        .section_name = wc.addString(section_name) catch @panic("OOM"),
        .file_path = options.file_path,
    }) catch @panic("OOM");
    options.file_path.addStepDependencies(&oc.step);
}

pub fn getOutput(oc: *const ObjCopy) std.Build.LazyPath {
    return .{ .generated = .{ .index = oc.output_file } };
}

pub fn getOutputSeparatedDebug(oc: *const ObjCopy) ?std.Build.LazyPath {
    const df = oc.debug_file orelse return null;
    return .{ .generated = .{ .index = df.output_file } };
}