mirror of
https://github.com/ziglang/zig.git
synced 2025-12-27 08:33:15 +00:00
This change is seemingly insignificant but I actually agonized over this
for three days. Some other things I considered:
* (status quo in master branch) make Compile step creation functions
accept a Target.Query and delete the ResolvedTarget struct.
- downside: redundantly resolve target queries many times
* same as before but additionally add a hash map to cache target query
resolutions.
- downside: now there is a hash map that doesn't actually need to
exist, just to make the API more ergonomic.
* add is_native_os and is_native_abi fields to std.Target and use it
directly as the result of resolving a target query.
- downside: they really don't belong there. They would be available
as comptime booleans via `@import("builtin")` but they should not
be exposed that way.
With this change the downsides are:
* the option name of addExecutable and friends is `target` instead of
`resolved_target` matching the type name.
- upside: this does not break compatibility with existing build
scripts
* you likely end up seeing `target.result.cpu.arch` rather than
`target.cpu.arch`.
- upside: this is an improvement over `target.target.cpu.arch` which
it was before this commit.
- downside: `b.host.target` is now `b.host.result`.
97 lines
2.8 KiB
Zig
97 lines
2.8 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn build(b: *std.Build) void {
|
|
const test_step = b.step("test", "Test it");
|
|
b.default_step = test_step;
|
|
|
|
const target = b.standardTargetOptions(.{});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
// Unwinding with a frame pointer
|
|
//
|
|
// getcontext version: zig std
|
|
//
|
|
// Unwind info type:
|
|
// - ELF: DWARF .debug_frame
|
|
// - MachO: __unwind_info encodings:
|
|
// - x86_64: RBP_FRAME
|
|
// - aarch64: FRAME, DWARF
|
|
{
|
|
const exe = b.addExecutable(.{
|
|
.name = "unwind_fp",
|
|
.root_source_file = .{ .path = "unwind.zig" },
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.unwind_tables = target.result.isDarwin(),
|
|
.omit_frame_pointer = false,
|
|
});
|
|
|
|
const run_cmd = b.addRunArtifact(exe);
|
|
test_step.dependOn(&run_cmd.step);
|
|
}
|
|
|
|
// Unwinding without a frame pointer
|
|
//
|
|
// getcontext version: zig std
|
|
//
|
|
// Unwind info type:
|
|
// - ELF: DWARF .eh_frame_hdr + .eh_frame
|
|
// - MachO: __unwind_info encodings:
|
|
// - x86_64: STACK_IMMD, STACK_IND
|
|
// - aarch64: FRAMELESS, DWARF
|
|
{
|
|
const exe = b.addExecutable(.{
|
|
.name = "unwind_nofp",
|
|
.root_source_file = .{ .path = "unwind.zig" },
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.unwind_tables = true,
|
|
.omit_frame_pointer = true,
|
|
});
|
|
|
|
const run_cmd = b.addRunArtifact(exe);
|
|
test_step.dependOn(&run_cmd.step);
|
|
}
|
|
|
|
// Unwinding through a C shared library without a frame pointer (libc)
|
|
//
|
|
// getcontext version: libc
|
|
//
|
|
// Unwind info type:
|
|
// - ELF: DWARF .eh_frame + .debug_frame
|
|
// - MachO: __unwind_info encodings:
|
|
// - x86_64: STACK_IMMD, STACK_IND
|
|
// - aarch64: FRAMELESS, DWARF
|
|
{
|
|
const c_shared_lib = b.addSharedLibrary(.{
|
|
.name = "c_shared_lib",
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.strip = false,
|
|
});
|
|
|
|
if (target.result.os.tag == .windows)
|
|
c_shared_lib.defineCMacro("LIB_API", "__declspec(dllexport)");
|
|
|
|
c_shared_lib.addCSourceFile(.{
|
|
.file = .{ .path = "shared_lib.c" },
|
|
.flags = &.{"-fomit-frame-pointer"},
|
|
});
|
|
c_shared_lib.linkLibC();
|
|
|
|
const exe = b.addExecutable(.{
|
|
.name = "shared_lib_unwind",
|
|
.root_source_file = .{ .path = "shared_lib_unwind.zig" },
|
|
.target = target,
|
|
.optimize = optimize,
|
|
.unwind_tables = target.result.isDarwin(),
|
|
.omit_frame_pointer = true,
|
|
});
|
|
|
|
exe.linkLibrary(c_shared_lib);
|
|
|
|
const run_cmd = b.addRunArtifact(exe);
|
|
test_step.dependOn(&run_cmd.step);
|
|
}
|
|
}
|