diff --git a/build.zig b/build.zig index 40e1b36e71..f60cd573a4 100644 --- a/build.zig +++ b/build.zig @@ -61,6 +61,7 @@ pub fn build(b: *Builder) !void { const omit_stage2 = b.option(bool, "omit-stage2", "Do not include stage2 behind a feature flag inside stage1") orelse false; const static_llvm = b.option(bool, "static-llvm", "Disable integration with system-installed LLVM, Clang, LLD, and libc++") orelse false; const enable_llvm = b.option(bool, "enable-llvm", "Build self-hosted compiler with LLVM backend enabled") orelse (is_stage1 or static_llvm); + const enable_macos_sdk = b.option(bool, "enable-macos-sdk", "Run tests requiring presence of macOS SDK and frameworks") orelse false; const config_h_path_option = b.option([]const u8, "config_h", "Path to the generated config.h"); if (!skip_install_lib_files) { @@ -340,7 +341,7 @@ pub fn build(b: *Builder) !void { )); toolchain_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes)); - toolchain_step.dependOn(tests.addStandaloneTests(b, test_filter, modes, skip_non_native, target)); + toolchain_step.dependOn(tests.addStandaloneTests(b, test_filter, modes, skip_non_native, enable_macos_sdk, target)); toolchain_step.dependOn(tests.addStackTraceTests(b, test_filter, modes)); toolchain_step.dependOn(tests.addCliTests(b, test_filter, modes)); toolchain_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes)); diff --git a/ci/azure/macos_script b/ci/azure/macos_script index 01ac3f5838..d56ba63b6b 100755 --- a/ci/azure/macos_script +++ b/ci/azure/macos_script @@ -57,7 +57,7 @@ make $JOBS install # TODO figure out why this causes a segmentation fault # release/bin/zig test ../test/behavior.zig -fno-stage1 -fLLVM -I ../test -release/bin/zig build test-toolchain +release/bin/zig build test-toolchain -Denable-macos-sdk release/bin/zig build test-std release/bin/zig build docs diff --git a/test/standalone.zig b/test/standalone.zig index 52fba31828..9a32701ddd 100644 --- a/test/standalone.zig +++ b/test/standalone.zig @@ -38,9 +38,7 @@ pub fn addCases(cases: *tests.StandaloneContext) void { cases.addBuildFile("test/standalone/pie/build.zig", .{}); } // Try to build and run an Objective-C executable. - if (std.Target.current.os.tag == .macos) { - cases.addBuildFile("test/standalone/objc/build.zig", .{ .build_modes = true }); - } + cases.addBuildFile("test/standalone/objc/build.zig", .{ .build_modes = true, .requires_macos_sdk = true }); // Ensure the development tools are buildable. cases.add("tools/gen_spirv_spec.zig"); diff --git a/test/standalone/objc/build.zig b/test/standalone/objc/build.zig index 30becd398c..7fdec514e7 100644 --- a/test/standalone/objc/build.zig +++ b/test/standalone/objc/build.zig @@ -1,5 +1,15 @@ const std = @import("std"); const Builder = std.build.Builder; +const CrossTarget = std.zig.CrossTarget; + +fn isRunnableTarget(t: CrossTarget) bool { + // TODO I think we might be able to run this on Linux via Darling. + // Add a check for that here, and return true if Darling is available. + if (t.isNative() and t.getOsTag() == .macos) + return true + else + return false; +} pub fn build(b: *Builder) void { const mode = b.standardReleaseOptions(); @@ -15,8 +25,12 @@ pub fn build(b: *Builder) void { exe.setBuildMode(mode); exe.setTarget(target); exe.linkLibC(); + // TODO when we figure out how to ship framework stubs for cross-compilation, + // populate paths to the sysroot here. exe.linkFramework("Foundation"); - const run_cmd = exe.run(); - test_step.dependOn(&run_cmd.step); + if (isRunnableTarget(target)) { + const run_cmd = exe.run(); + test_step.dependOn(&run_cmd.step); + } } diff --git a/test/tests.zig b/test/tests.zig index 0b736792b9..fc83137bc4 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -383,7 +383,14 @@ pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8, modes: return cases.step; } -pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode, skip_non_native: bool, target: std.zig.CrossTarget) *build.Step { +pub fn addStandaloneTests( + b: *build.Builder, + test_filter: ?[]const u8, + modes: []const Mode, + skip_non_native: bool, + enable_macos_sdk: bool, + target: std.zig.CrossTarget, +) *build.Step { const cases = b.allocator.create(StandaloneContext) catch unreachable; cases.* = StandaloneContext{ .b = b, @@ -392,6 +399,7 @@ pub fn addStandaloneTests(b: *build.Builder, test_filter: ?[]const u8, modes: [] .test_filter = test_filter, .modes = modes, .skip_non_native = skip_non_native, + .enable_macos_sdk = enable_macos_sdk, .target = target, }; @@ -831,6 +839,7 @@ pub const StandaloneContext = struct { test_filter: ?[]const u8, modes: []const Mode, skip_non_native: bool, + enable_macos_sdk: bool, target: std.zig.CrossTarget, pub fn addC(self: *StandaloneContext, root_src: []const u8) void { @@ -841,9 +850,15 @@ pub const StandaloneContext = struct { self.addAllArgs(root_src, false); } - pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8, features: struct { build_modes: bool = false, cross_targets: bool = false }) void { + pub fn addBuildFile(self: *StandaloneContext, build_file: []const u8, features: struct { + build_modes: bool = false, + cross_targets: bool = false, + requires_macos_sdk: bool = false, + }) void { const b = self.b; + if (features.requires_macos_sdk and !self.enable_macos_sdk) return; + const annotated_case_name = b.fmt("build {s}", .{build_file}); if (self.test_filter) |filter| { if (mem.indexOf(u8, annotated_case_name, filter) == null) return;