| ... | @@ -0,0 +1,29 @@ |
| 1 | const std = @import("std"); |
| 2 | const Builder = std.build.Builder; |
| 3 | |
| 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); |
| 6 | |
| 7 | const target: std.zig.CrossTarget = .{ .os_tag = .macos }; |
| 8 | const target_info = std.zig.system.NativeTargetInfo.detect(target) catch unreachable; |
| 9 | const sdk = std.zig.system.darwin.getDarwinSDK(b.allocator, target_info.target) orelse |
| 10 | @panic("macOS SDK is required to run the test"); |
| 11 | |
| 12 | const test_step = b.step("test", "Test the program"); |
| 13 | |
| 14 | const exe = b.addExecutable("test", null); |
| 15 | b.default_step.dependOn(&exe.step); |
| 16 | exe.addIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include" }) catch unreachable); |
| 17 | exe.addIncludePath(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/include/c++/v1" }) catch unreachable); |
| 18 | exe.addCSourceFile("test.cpp", &.{ |
| 19 | "-nostdlib++", |
| 20 | "-nostdinc++", |
| 21 | }); |
| 22 | exe.addObjectFile(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/lib/libc++.tbd" }) catch unreachable); |
| 23 | exe.setBuildMode(mode); |
| 24 | |
| 25 | const run_cmd = exe.run(); |
| 26 | run_cmd.expectStdErrEqual("x: 5\n"); |
| 27 | |
| 28 | test_step.dependOn(&run_cmd.step); |
| 29 | } |