-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
macho: fix invalid default dylib link behavior
- Loading branch information
Showing
5 changed files
with
87 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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 exe = b.addSystemCommand(&.{ | ||
"cc", | ||
"-fno-lto", | ||
"main.c", | ||
"-framework", | ||
"Cocoa", | ||
"-B../../../zig-out/bin/", | ||
"-o", | ||
"a1.out", | ||
}); | ||
test_step.dependOn(&exe.step); | ||
|
||
const check = std.Build.Step.CheckObject.create(b, .{ .path = b.pathFromRoot("a1.out") }, .macho); | ||
check.checkStart("cmd LOAD_DYLIB"); | ||
check.checkNext("name {*}Cocoa"); | ||
check.checkStart("cmd LOAD_DYLIB"); | ||
check.checkNext("name {*}libobjc{*}.dylib"); | ||
check.step.dependOn(&exe.step); | ||
test_step.dependOn(&check.step); | ||
|
||
const run = b.addSystemCommand(&.{"./a1.out"}); | ||
run.has_side_effects = true; | ||
run.step.dependOn(&exe.step); | ||
test_step.dependOn(&run.step); | ||
} | ||
|
||
{ | ||
const exe = b.addSystemCommand(&.{ | ||
"cc", | ||
"-fno-lto", | ||
"main.c", | ||
"-Wl,-dead_strip_dylibs", | ||
"-framework", | ||
"Cocoa", | ||
"-B../../../zig-out/bin/", | ||
"-o", | ||
"a2.out", | ||
}); | ||
test_step.dependOn(&exe.step); | ||
|
||
const run = b.addSystemCommand(&.{"./a2.out"}); | ||
run.has_side_effects = true; | ||
run.expectExitCode(@as(u8, @bitCast(@as(i8, -2)))); | ||
run.step.dependOn(&exe.step); | ||
test_step.dependOn(&run.step); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <objc/runtime.h> | ||
|
||
int main(int argc, char* argv[]) { | ||
if (objc_getClass("NSObject") == 0) { | ||
return -1; | ||
} | ||
if (objc_getClass("NSApplication") == 0) { | ||
return -2; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters