aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-08-02 10:04:54 +0200
committerAndrew Kelley <andrew@ziglang.org>2021-08-02 13:41:58 -0400
commit159cd528b164f77177e71309dee9fa79d2d5f4f4 (patch)
tree364c79201b35da2319f8225e0a8138ee70ba3c4c /test
parent68e26a2ceea85a149cb23286504cbdcec1ae814e (diff)
downloadzig-159cd528b164f77177e71309dee9fa79d2d5f4f4.tar.gz
zig-159cd528b164f77177e71309dee9fa79d2d5f4f4.zip
Add -Denable-macos-sdk explicit flag to build.zig
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`.
Diffstat (limited to 'test')
-rw-r--r--test/standalone.zig4
-rw-r--r--test/standalone/objc/build.zig18
-rw-r--r--test/tests.zig19
3 files changed, 34 insertions, 7 deletions
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;