From 573bb77ab6f4f00753bb257314d8115cbaac17ae Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Wed, 16 Aug 2023 12:19:34 +0200 Subject: [PATCH] macho: add smoke test for re-exports in static libs --- test/link.zig | 4 +++ test/link/macho/reexports/a.zig | 7 ++++++ test/link/macho/reexports/build.zig | 38 +++++++++++++++++++++++++++++ test/link/macho/reexports/main.c | 5 ++++ 4 files changed, 54 insertions(+) create mode 100644 test/link/macho/reexports/a.zig create mode 100644 test/link/macho/reexports/build.zig create mode 100644 test/link/macho/reexports/main.c diff --git a/test/link.zig b/test/link.zig index 56b1cf415d..53caefd64f 100644 --- a/test/link.zig +++ b/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"), diff --git a/test/link/macho/reexports/a.zig b/test/link/macho/reexports/a.zig new file mode 100644 index 0000000000..cfa7e8b3ac --- /dev/null +++ b/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 }); +} diff --git a/test/link/macho/reexports/build.zig b/test/link/macho/reexports/build.zig new file mode 100644 index 0000000000..d9a9481fa0 --- /dev/null +++ b/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); +} diff --git a/test/link/macho/reexports/main.c b/test/link/macho/reexports/main.c new file mode 100644 index 0000000000..2beb701f1f --- /dev/null +++ b/test/link/macho/reexports/main.c @@ -0,0 +1,5 @@ +extern int foo(); +extern int bar(); +int main() { + return bar() - foo(); +}