aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2022-06-28 09:14:35 +0200
committerJakub Konka <kubkon@jakubkonka.com>2022-06-28 09:22:04 +0200
commit075f5bc5ffdbe0a458a733d596a1fc4a74b8e1ab (patch)
tree03202c54ac0b5c5d3e12ebfc4a5a433ab4a57ca9 /test
parent20bd722464699bd11a05fe8e250f9f8086853cf2 (diff)
downloadzig-075f5bc5ffdbe0a458a733d596a1fc4a74b8e1ab.tar.gz
zig-075f5bc5ffdbe0a458a733d596a1fc4a74b8e1ab.zip
link-tests: test -weak-lx and -weak_framework x
Diffstat (limited to 'test')
-rw-r--r--test/link.zig11
-rw-r--r--test/link/macho/needed_library/a.c (renamed from test/link/macho/needed_l/a.c)0
-rw-r--r--test/link/macho/needed_library/build.zig (renamed from test/link/macho/needed_l/build.zig)0
-rw-r--r--test/link/macho/needed_library/main.c (renamed from test/link/macho/needed_l/main.c)0
-rw-r--r--test/link/macho/weak_framework/build.zig24
-rw-r--r--test/link/macho/weak_framework/main.c3
-rw-r--r--test/link/macho/weak_library/a.c9
-rw-r--r--test/link/macho/weak_library/build.zig33
-rw-r--r--test/link/macho/weak_library/main.c9
9 files changed, 88 insertions, 1 deletions
diff --git a/test/link.zig b/test/link.zig
index 6878881a66..c578638ec3 100644
--- a/test/link.zig
+++ b/test/link.zig
@@ -45,7 +45,11 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
.requires_macos_sdk = true,
});
- cases.addBuildFile("test/link/macho/needed_l/build.zig", .{
+ cases.addBuildFile("test/link/macho/needed_library/build.zig", .{
+ .build_modes = true,
+ });
+
+ cases.addBuildFile("test/link/macho/weak_library/build.zig", .{
.build_modes = true,
});
@@ -54,6 +58,11 @@ pub fn addCases(cases: *tests.StandaloneContext) void {
.requires_macos_sdk = true,
});
+ cases.addBuildFile("test/link/macho/weak_framework/build.zig", .{
+ .build_modes = true,
+ .requires_macos_sdk = true,
+ });
+
// Try to build and run an Objective-C executable.
cases.addBuildFile("test/link/macho/objc/build.zig", .{
.build_modes = true,
diff --git a/test/link/macho/needed_l/a.c b/test/link/macho/needed_library/a.c
index 4bcf8c9786..4bcf8c9786 100644
--- a/test/link/macho/needed_l/a.c
+++ b/test/link/macho/needed_library/a.c
diff --git a/test/link/macho/needed_l/build.zig b/test/link/macho/needed_library/build.zig
index 708a09dc32..708a09dc32 100644
--- a/test/link/macho/needed_l/build.zig
+++ b/test/link/macho/needed_library/build.zig
diff --git a/test/link/macho/needed_l/main.c b/test/link/macho/needed_library/main.c
index ca68d24cc7..ca68d24cc7 100644
--- a/test/link/macho/needed_l/main.c
+++ b/test/link/macho/needed_library/main.c
diff --git a/test/link/macho/weak_framework/build.zig b/test/link/macho/weak_framework/build.zig
new file mode 100644
index 0000000000..44675a15f8
--- /dev/null
+++ b/test/link/macho/weak_framework/build.zig
@@ -0,0 +1,24 @@
+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());
+
+ const exe = b.addExecutable("test", null);
+ exe.addCSourceFile("main.c", &[0][]const u8{});
+ exe.setBuildMode(mode);
+ exe.linkLibC();
+ exe.linkFrameworkWeak("Cocoa");
+
+ const check = exe.checkObject(.macho);
+ check.checkStart("cmd LOAD_WEAK_DYLIB");
+ check.checkNext("name {*}Cocoa");
+ test_step.dependOn(&check.step);
+
+ const run_cmd = exe.run();
+ test_step.dependOn(&run_cmd.step);
+}
diff --git a/test/link/macho/weak_framework/main.c b/test/link/macho/weak_framework/main.c
new file mode 100644
index 0000000000..ca68d24cc7
--- /dev/null
+++ b/test/link/macho/weak_framework/main.c
@@ -0,0 +1,3 @@
+int main(int argc, char* argv[]) {
+ return 0;
+}
diff --git a/test/link/macho/weak_library/a.c b/test/link/macho/weak_library/a.c
new file mode 100644
index 0000000000..9f49802ce6
--- /dev/null
+++ b/test/link/macho/weak_library/a.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+int a = 42;
+
+const char* asStr() {
+ static char str[3];
+ sprintf(str, "%d", 42);
+ return str;
+}
diff --git a/test/link/macho/weak_library/build.zig b/test/link/macho/weak_library/build.zig
new file mode 100644
index 0000000000..5a1f7b4ce5
--- /dev/null
+++ b/test/link/macho/weak_library/build.zig
@@ -0,0 +1,33 @@
+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());
+
+ const dylib = b.addSharedLibrary("a", null, b.version(1, 0, 0));
+ dylib.setBuildMode(mode);
+ dylib.addCSourceFile("a.c", &.{});
+ dylib.linkLibC();
+ dylib.install();
+
+ const exe = b.addExecutable("test", null);
+ exe.addCSourceFile("main.c", &[0][]const u8{});
+ exe.setBuildMode(mode);
+ exe.linkLibC();
+ exe.linkSystemLibraryWeak("a");
+ exe.addLibraryPath(b.pathFromRoot("zig-out/lib"));
+ exe.addRPath(b.pathFromRoot("zig-out/lib"));
+
+ const check = exe.checkObject(.macho);
+ check.checkStart("cmd LOAD_WEAK_DYLIB");
+ check.checkNext("name @rpath/liba.dylib");
+ test_step.dependOn(&check.step);
+
+ const run_cmd = exe.run();
+ run_cmd.expectStdOutEqual("42 42");
+ test_step.dependOn(&run_cmd.step);
+}
diff --git a/test/link/macho/weak_library/main.c b/test/link/macho/weak_library/main.c
new file mode 100644
index 0000000000..ee5367fef7
--- /dev/null
+++ b/test/link/macho/weak_library/main.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+
+extern int a;
+extern const char* asStr();
+
+int main(int argc, char* argv[]) {
+ printf("%d %s", a, asStr());
+ return 0;
+}