Commit 573bb77ab6

Jakub Konka <kubkon@jakubkonka.com>
2023-08-16 12:19:34
macho: add smoke test for re-exports in static libs
1 parent 787e755
Changed files (4)
test
link
macho
test/link/macho/reexports/a.zig
@@ -0,0 +1,7 @@
+const x: i32 = 42;
+export fn foo() i32 {
+    return x;
+}
+comptime {
+    @export(foo, .{ .name = "bar", .linkage = .Strong });
+}
test/link/macho/reexports/build.zig
@@ -0,0 +1,38 @@
+const std = @import("std");
+
+pub const requires_symlinks = true;
+
+pub fn build(b: *std.Build) void {
+    const test_step = b.step("test", "Test it");
+    b.default_step = test_step;
+
+    add(b, test_step, .Debug);
+    add(b, test_step, .ReleaseFast);
+    add(b, test_step, .ReleaseSmall);
+    add(b, test_step, .ReleaseSafe);
+}
+
+fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
+    const target: std.zig.CrossTarget = .{ .os_tag = .macos };
+
+    const lib = b.addStaticLibrary(.{
+        .name = "a",
+        .root_source_file = .{ .path = "a.zig" },
+        .optimize = optimize,
+        .target = target,
+    });
+
+    const exe = b.addExecutable(.{
+        .name = "test",
+        .optimize = optimize,
+        .target = target,
+    });
+    exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
+    exe.linkLibrary(lib);
+    exe.linkLibC();
+
+    const run = b.addRunArtifact(exe);
+    run.skip_foreign_checks = true;
+    run.expectExitCode(0);
+    test_step.dependOn(&run.step);
+}
test/link/macho/reexports/main.c
@@ -0,0 +1,5 @@
+extern int foo();
+extern int bar();
+int main() {
+  return bar() - foo();
+}
test/link.zig
@@ -156,6 +156,10 @@ pub const cases = [_]Case{
         .build_root = "test/link/macho/pagezero",
         .import = @import("link/macho/pagezero/build.zig"),
     },
+    .{
+        .build_root = "test/link/macho/reexports",
+        .import = @import("link/macho/reexports/build.zig"),
+    },
     .{
         .build_root = "test/link/macho/search_strategy",
         .import = @import("link/macho/search_strategy/build.zig"),