mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 04:17:49 +00:00
MachO linker now handles `-needed-l<name>`, `-needed_library=<name>` and `-needed_framework=<name>`. While on macOS `-l` is equivalent to `-needed-l`, and `-framework` to `-needed_framework`, it can be used to the same effect as on Linux if combined with `-dead_strip_dylibs`. This commit also adds handling for `-needed_library` which is macOS specific flag only (in addition to `-needed-l`). Finally, in order to leverage new linker testing harness, this commit added ability to specify lowering to those flags via `build.zig`: `linkSystemLibraryNeeded` (and related), and `linkFrameworkNeeded`.
47 lines
1.4 KiB
Zig
47 lines
1.4 KiB
Zig
const std = @import("std");
|
|
const Builder = std.build.Builder;
|
|
const LibExeObjectStep = std.build.LibExeObjStep;
|
|
|
|
pub fn build(b: *Builder) void {
|
|
const mode = b.standardReleaseOptions();
|
|
|
|
const test_step = b.step("test", "Test the program");
|
|
test_step.dependOn(b.getInstallStep());
|
|
|
|
{
|
|
// Without -dead_strip_dylibs we expect `-la` to include liba.dylib in the final executable
|
|
const exe = createScenario(b, mode);
|
|
|
|
const check = exe.checkObject(.macho);
|
|
check.checkStart("cmd LOAD_DYLIB");
|
|
check.checkNext("name {*}Cocoa");
|
|
|
|
check.checkStart("cmd LOAD_DYLIB");
|
|
check.checkNext("name {*}libobjc{*}.dylib");
|
|
|
|
test_step.dependOn(&check.step);
|
|
|
|
const run_cmd = exe.run();
|
|
test_step.dependOn(&run_cmd.step);
|
|
}
|
|
|
|
{
|
|
// With -dead_strip_dylibs, we should include liba.dylib as it's unreachable
|
|
const exe = createScenario(b, mode);
|
|
exe.dead_strip_dylibs = true;
|
|
|
|
const run_cmd = exe.run();
|
|
run_cmd.expected_exit_code = @bitCast(u8, @as(i8, -2)); // should fail
|
|
test_step.dependOn(&run_cmd.step);
|
|
}
|
|
}
|
|
|
|
fn createScenario(b: *Builder, mode: std.builtin.Mode) *LibExeObjectStep {
|
|
const exe = b.addExecutable("test", null);
|
|
exe.addCSourceFile("main.c", &[0][]const u8{});
|
|
exe.setBuildMode(mode);
|
|
exe.linkLibC();
|
|
exe.linkFramework("Cocoa");
|
|
return exe;
|
|
}
|