| author | |
| committer | |
| log | 159cd528b164f77177e71309dee9fa79d2d5f4f4 |
| tree | 364c79201b35da2319f8225e0a8138ee70ba3c4c |
| parent | 68e26a2ceea85a149cb23286504cbdcec1ae814e |
This way, we can explicitly signal if a test requires the presence
of macOS SDK to build. For instance, when testing our in-house
MachO linker for correctly linking Objective-C, we require the
presence of the SDK on the host system, and we can enforce this
with `-Denable-macos-sdk` flag to `zig build test-standalone`.5 files changed, 37 insertions(+), 9 deletions(-)
build.zig+2-1| ... | @@ -61,6 +61,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -61,6 +61,7 @@ pub fn build(b: *Builder) !void { |
| 61 | const omit_stage2 = b.option(bool, "omit-stage2", "Do not include stage2 behind a feature flag inside stage1") orelse false; | 61 | const omit_stage2 = b.option(bool, "omit-stage2", "Do not include stage2 behind a feature flag inside stage1") orelse false; |
| 62 | const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false; | 62 | const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false; |
| 63 | const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm); | 63 | const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm); |
| 64 | const enable_macos_sdk = b.option(bool, "enable-macos-sdk", "Run tests requiring presence of macOS SDK and frameworks") orelse false; | ||
| 64 | const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h"); | 65 | const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h"); |
| 65 | 66 | ||
| 66 | if (!skip_install_lib_files) { | 67 | if (!skip_install_lib_files) { |
| ... | @@ -340,7 +341,7 @@ pub fn build(b: *Builder) !void { | ... | @@ -340,7 +341,7 @@ pub fn build(b: *Builder) !void { |
| 340 | )); | 341 | )); |
| 341 | 342 | ||
| 342 | toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes)); | 343 | toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes)); |
| 343 | toolchain_step.dependOn(tests.addStandaloneTests(b, test_filter, modes, skip_non_native, target)); | 344 | toolchain_step.dependOn(tests.addStandaloneTests(b, test_filter, modes, skip_non_native, enable_macos_sdk, target)); |
| 344 | toolchain_step.dependOn(tests.addStackTraceTests(b, test_filter, modes)); | 345 | toolchain_step.dependOn(tests.addStackTraceTests(b, test_filter, modes)); |
| 345 | toolchain_step.dependOn(tests.addCliTests(b, test_filter, modes)); | 346 | toolchain_step.dependOn(tests.addCliTests(b, test_filter, modes)); |
| 346 | toolchain_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes)); | 347 | toolchain_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes)); |
ci/azure/macos_script+1-1| ... | @@ -57,7 +57,7 @@ make $JOBS install | ... | @@ -57,7 +57,7 @@ make $JOBS install |
| 57 | # TODO figure out why this causes a segmentation fault | 57 | # TODO figure out why this causes a segmentation fault |
| 58 | # release/bin/zig test ../test/behavior.zig -fno-stage1 -fLLVM -I ../test | 58 | # release/bin/zig test ../test/behavior.zig -fno-stage1 -fLLVM -I ../test |
| 59 | 59 | ||
| 60 | release/bin/zig build test-toolchain | 60 | release/bin/zig build test-toolchain -Denable-macos-sdk |
| 61 | release/bin/zig build test-std | 61 | release/bin/zig build test-std |
| 62 | release/bin/zig build docs | 62 | release/bin/zig build docs |
| 63 | 63 |
test/standalone.zig+1-3| ... | @@ -38,9 +38,7 @@ pub fn addCases(cases: *tests.StandaloneContext) void { | ... | @@ -38,9 +38,7 @@ pub fn addCases(cases: *tests.StandaloneContext) void { |
| 38 | cases.addBuildFile("test/standalone/pie/build.zig", .{}); | 38 | cases.addBuildFile("test/standalone/pie/build.zig", .{}); |
| 39 | } | 39 | } |
| 40 | // Try to build and run an Objective-C executable. | 40 | // Try to build and run an Objective-C executable. |
| 41 | if (std.Target.current.os.tag == .macos) { | 41 | cases.addBuildFile("test/standalone/objc/build.zig", .{ .build_modes = true, .requires_macos_sdk = true }); |
| 42 | cases.addBuildFile("test/standalone/objc/build.zig", .{ .build_modes = true }); | ||
| 43 | } | ||
| 44 | 42 | ||
| 45 | // Ensure the development tools are buildable. | 43 | // Ensure the development tools are buildable. |
| 46 | cases.add("tools/gen_spirv_spec.zig"); | 44 | cases.add("tools/gen_spirv_spec.zig"); |
test/standalone/objc/build.zig+16-2| ... | @@ -1,5 +1,15 @@ | ... | @@ -1,5 +1,15 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const Builder = std.build.Builder; | 2 | const Builder = std.build.Builder; |
| 3 | const CrossTarget = std.zig.CrossTarget; | ||
| 4 | |||
| 5 | fn isRunnableTarget(t: CrossTarget) bool { | ||
| 6 | // TODO I think we might be able to run this on Linux via Darling. | ||
| 7 | // Add a check for that here, and return true if Darling is available. | ||
| 8 | if (t.isNative() and t.getOsTag() == .macos) | ||
| 9 | return true | ||
| 10 | else | ||
| 11 | return false; | ||
| 12 | } | ||
| 3 | 13 | ||
| 4 | pub fn build(b: *Builder) void { | 14 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); | 15 | const mode = b.standardReleaseOptions(); |
| ... | @@ -15,8 +25,12 @@ pub fn build(b: *Builder) void { | ... | @@ -15,8 +25,12 @@ pub fn build(b: *Builder) void { |
| 15 | exe.setBuildMode(mode); | 25 | exe.setBuildMode(mode); |
| 16 | exe.setTarget(target); | 26 | exe.setTarget(target); |
| 17 | exe.linkLibC(); | 27 | exe.linkLibC(); |
| 28 | // TODO when we figure out how to ship framework stubs for cross-compilation, | ||
| 29 | // populate paths to the sysroot here. | ||
| 18 | exe.linkFramework("Foundation"); | 30 | exe.linkFramework("Foundation"); |
| 19 | 31 | ||
| 20 | const run_cmd = exe.run(); | 32 | if (isRunnableTarget(target)) { |
| 21 | test_step.dependOn(&run_cmd.step); | 33 | const run_cmd = exe.run(); |
| 34 | test_step.dependOn(&run_cmd.step); | ||
| 35 | } | ||
| 22 | } | 36 | } |
test/tests.zig+17-2| ... | @@ -383,7 +383,14 @@ pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8, modes: | ... | @@ -383,7 +383,14 @@ pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8, modes: |
| 383 | return cases.step; | 383 | return cases.step; |
| 384 | } | 384 | } |
| 385 | 385 | ||
| 386 | pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode, skip_non_native: bool, target: std.zig.CrossTarget) *build.Step { | 386 | pub fn addStandaloneTests( |
| 387 | b: *build.Builder, | ||
| 388 | test_filter: ?[]const u8, | ||
| 389 | modes: []const Mode, | ||
| 390 | skip_non_native: bool, | ||
| 391 | enable_macos_sdk: bool, | ||
| 392 | target: std.zig.CrossTarget, | ||
| 393 | ) *build.Step { | ||
| 387 | const cases = b.allocator.create(StandaloneContext) catch unreachable; | 394 | const cases = b.allocator.create(StandaloneContext) catch unreachable; |
| 388 | cases.* = StandaloneContext{ | 395 | cases.* = StandaloneContext{ |
| 389 | .b = b, | 396 | .b = b, |
| ... | @@ -392,6 +399,7 @@ pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: [] | ... | @@ -392,6 +399,7 @@ pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: [] |
| 392 | .test_filter = test_filter, | 399 | .test_filter = test_filter, |
| 393 | .modes = modes, | 400 | .modes = modes, |
| 394 | .skip_non_native = skip_non_native, | 401 | .skip_non_native = skip_non_native, |
| 402 | .enable_macos_sdk = enable_macos_sdk, | ||
| 395 | .target = target, | 403 | .target = target, |
| 396 | }; | 404 | }; |
| 397 | 405 | ||
| ... | @@ -831,6 +839,7 @@ pub const StandaloneContext = struct { | ... | @@ -831,6 +839,7 @@ pub const StandaloneContext = struct { |
| 831 | test_filter: ?[]const u8, | 839 | test_filter: ?[]const u8, |
| 832 | modes: []const Mode, | 840 | modes: []const Mode, |
| 833 | skip_non_native: bool, | 841 | skip_non_native: bool, |
| 842 | enable_macos_sdk: bool, | ||
| 834 | target: std.zig.CrossTarget, | 843 | target: std.zig.CrossTarget, |
| 835 | 844 | ||
| 836 | pub fn addC(self: *StandaloneContext, root_src: []const u8) void { | 845 | pub fn addC(self: *StandaloneContext, root_src: []const u8) void { |
| ... | @@ -841,9 +850,15 @@ pub const StandaloneContext = struct { | ... | @@ -841,9 +850,15 @@ pub const StandaloneContext = struct { |
| 841 | self.addAllArgs(root_src, false); | 850 | self.addAllArgs(root_src, false); |
| 842 | } | 851 | } |
| 843 | 852 | ||
| 844 | pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8, features: struct { build_modes: bool = false, cross_targets: bool = false }) void { | 853 | pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8, features: struct { |
| 854 | build_modes: bool = false, | ||
| 855 | cross_targets: bool = false, | ||
| 856 | requires_macos_sdk: bool = false, | ||
| 857 | }) void { | ||
| 845 | const b = self.b; | 858 | const b = self.b; |
| 846 | 859 | ||
| 860 | if (features.requires_macos_sdk and !self.enable_macos_sdk) return; | ||
| 861 | |||
| 847 | const annotated_case_name = b.fmt("build {s}", .{build_file}); | 862 | const annotated_case_name = b.fmt("build {s}", .{build_file}); |
| 848 | if (self.test_filter) |filter| { | 863 | if (self.test_filter) |filter| { |
| 849 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; | 864 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |