| ... | @@ -0,0 +1,56 @@ |
| 1 | const std = @import("std"); |
| 2 | const builtin = @import("builtin"); |
| 3 | |
| 4 | pub const requires_symlinks = true; |
| 5 | pub const requires_macos_sdk = false; |
| 6 | |
| 7 | pub fn build(b: *std.Build) void { |
| 8 | const test_step = b.step("test", "Test it"); |
| 9 | b.default_step = test_step; |
| 10 | |
| 11 | add(b, test_step, .Debug); |
| 12 | add(b, test_step, .ReleaseFast); |
| 13 | add(b, test_step, .ReleaseSmall); |
| 14 | add(b, test_step, .ReleaseSafe); |
| 15 | } |
| 16 | |
| 17 | fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { |
| 18 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 19 | |
| 20 | const lib = b.addSharedLibrary(.{ |
| 21 | .name = "a", |
| 22 | .version = .{ .major = 1, .minor = 0, .patch = 0 }, |
| 23 | .optimize = optimize, |
| 24 | .target = target, |
| 25 | }); |
| 26 | lib.addCSourceFile("a.c", &.{}); |
| 27 | lib.linkLibC(); |
| 28 | |
| 29 | const tbd_file = b.addWriteFile("liba.tbd", |
| 30 | \\--- !tapi-tbd-v3 |
| 31 | \\archs: [ arm64 ] |
| 32 | \\uuids: [ 'arm64: DEADBEEF' ] |
| 33 | \\platform: macos |
| 34 | \\install-name: @rpath/liba.dylib |
| 35 | \\current-version: 0 |
| 36 | \\exports: |
| 37 | \\ - archs: [ arm64 ] |
| 38 | \\ symbols: [ _getFoo ] |
| 39 | ); |
| 40 | |
| 41 | const exe = b.addExecutable(.{ |
| 42 | .name = "main", |
| 43 | .root_source_file = .{ .path = "main.c" }, |
| 44 | .optimize = optimize, |
| 45 | .target = target, |
| 46 | }); |
| 47 | exe.linkSystemLibrary("a"); |
| 48 | exe.addLibraryPathDirectorySource(tbd_file.getDirectorySource()); |
| 49 | exe.addRPathDirectorySource(lib.getOutputDirectorySource()); |
| 50 | exe.linkLibC(); |
| 51 | |
| 52 | const run = b.addRunArtifact(exe); |
| 53 | run.skip_foreign_checks = true; |
| 54 | |
| 55 | test_step.dependOn(&run.step); |
| 56 | } |