-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
macho: fix linking of dylibs and frameworks
Previously, I have incorrectly assumed that with two-level namespace we only need to link in dylibs/frameworks that actually export symbols which are undefined in the linked image. Turns out, regardless of whether we link with two-level namespace (default on macOS) or a flat namespace (more common on other platforms), we always need to put the dylibs/frameworks as specified by the user from the linker line into the final linked image.
- Loading branch information
Showing
5 changed files
with
54 additions
and
0 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
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,34 @@ | ||
const std = @import("std"); | ||
const Builder = std.build.Builder; | ||
const CrossTarget = std.zig.CrossTarget; | ||
|
||
fn isRunnableTarget(t: CrossTarget) bool { | ||
// TODO I think we might be able to run this on Linux via Darling. | ||
// Add a check for that here, and return true if Darling is available. | ||
if (t.isNative() and t.getOsTag() == .macos) | ||
return true | ||
else | ||
return false; | ||
} | ||
|
||
pub fn build(b: *Builder) void { | ||
const mode = b.standardReleaseOptions(); | ||
const target = b.standardTargetOptions(.{}); | ||
|
||
const test_step = b.step("test", "Test the program"); | ||
|
||
const exe = b.addExecutable("test", null); | ||
b.default_step.dependOn(&exe.step); | ||
exe.addCSourceFile("main.c", &[0][]const u8{}); | ||
exe.setBuildMode(mode); | ||
exe.setTarget(target); | ||
exe.linkLibC(); | ||
// TODO when we figure out how to ship framework stubs for cross-compilation, | ||
// populate paths to the sysroot here. | ||
exe.linkFramework("Cocoa"); | ||
|
||
if (isRunnableTarget(target)) { | ||
const run_cmd = exe.run(); | ||
test_step.dependOn(&run_cmd.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,7 @@ | ||
#include <assert.h> | ||
#include <objc/runtime.h> | ||
|
||
int main() { | ||
assert(objc_getClass("NSObject") > 0); | ||
assert(objc_getClass("NSApplication") > 0); | ||
} |