aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/std/build.zig12
-rw-r--r--lib/std/macho.zig15
-rw-r--r--lib/std/zig/system.zig10
-rw-r--r--lib/std/zig/system/darwin.zig44
-rw-r--r--lib/std/zig/system/darwin/macos.zig (renamed from lib/std/zig/system/macos.zig)22
5 files changed, 74 insertions, 29 deletions
diff --git a/lib/std/build.zig b/lib/std/build.zig
index 17cad016e8..efb305d4a3 100644
--- a/lib/std/build.zig
+++ b/lib/std/build.zig
@@ -2672,7 +2672,11 @@ pub const LibExeObjStep = struct {
try zig_args.append(self.builder.pathFromRoot(include_path));
},
.raw_path_system => |include_path| {
- try zig_args.append("-isystem");
+ if (builder.sysroot != null) {
+ try zig_args.append("-iwithsysroot");
+ } else {
+ try zig_args.append("-isystem");
+ }
try zig_args.append(self.builder.pathFromRoot(include_path));
},
.other_step => |other| if (other.emit_h) {
@@ -2700,6 +2704,12 @@ pub const LibExeObjStep = struct {
if (self.target.isDarwin()) {
for (self.framework_dirs.items) |dir| {
+ if (builder.sysroot != null) {
+ try zig_args.append("-iframeworkwithsysroot");
+ } else {
+ try zig_args.append("-iframework");
+ }
+ try zig_args.append(dir);
try zig_args.append("-F");
try zig_args.append(dir);
}
diff --git a/lib/std/macho.zig b/lib/std/macho.zig
index cb030e941e..14be755a70 100644
--- a/lib/std/macho.zig
+++ b/lib/std/macho.zig
@@ -116,6 +116,21 @@ pub const build_tool_version = extern struct {
version: u32,
};
+pub const PLATFORM_MACOS: u32 = 0x1;
+pub const PLATFORM_IOS: u32 = 0x2;
+pub const PLATFORM_TVOS: u32 = 0x3;
+pub const PLATFORM_WATCHOS: u32 = 0x4;
+pub const PLATFORM_BRIDGEOS: u32 = 0x5;
+pub const PLATFORM_MACCATALYST: u32 = 0x6;
+pub const PLATFORM_IOSSIMULATOR: u32 = 0x7;
+pub const PLATFORM_TVOSSIMULATOR: u32 = 0x8;
+pub const PLATFORM_WATCHOSSIMULATOR: u32 = 0x9;
+pub const PLATFORM_DRIVERKIT: u32 = 0x10;
+
+pub const TOOL_CLANG: u32 = 0x1;
+pub const TOOL_SWIFT: u32 = 0x2;
+pub const TOOL_LD: u32 = 0x3;
+
/// The entry_point_command is a replacement for thread_command.
/// It is used for main executables to specify the location (file offset)
/// of main(). If -stack_size was used at link time, the stacksize
diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig
index 4d671efe94..c5c62911cc 100644
--- a/lib/std/zig/system.zig
+++ b/lib/std/zig/system.zig
@@ -13,12 +13,10 @@ const assert = std.debug.assert;
const process = std.process;
const Target = std.Target;
const CrossTarget = std.zig.CrossTarget;
-const macos = @import("system/macos.zig");
const native_endian = std.Target.current.cpu.arch.endian();
const linux = @import("system/linux.zig");
pub const windows = @import("system/windows.zig");
-
-pub const getSDKPath = macos.getSDKPath;
+pub const darwin = @import("system/darwin.zig");
pub const NativePaths = struct {
include_dirs: ArrayList([:0]u8),
@@ -255,7 +253,7 @@ pub const NativeTargetInfo = struct {
os.version_range.windows.min = detected_version;
os.version_range.windows.max = detected_version;
},
- .macos => try macos.detect(&os),
+ .macos => try darwin.macos.detect(&os),
.freebsd, .netbsd, .dragonfly => {
const key = switch (Target.current.os.tag) {
.freebsd => "kern.osreldate",
@@ -972,7 +970,7 @@ pub const NativeTargetInfo = struct {
switch (std.Target.current.os.tag) {
.linux => return linux.detectNativeCpuAndFeatures(),
- .macos => return macos.detectNativeCpuAndFeatures(),
+ .macos => return darwin.macos.detectNativeCpuAndFeatures(),
else => {},
}
@@ -983,6 +981,6 @@ pub const NativeTargetInfo = struct {
};
test {
- _ = @import("system/macos.zig");
+ _ = @import("system/darwin.zig");
_ = @import("system/linux.zig");
}
diff --git a/lib/std/zig/system/darwin.zig b/lib/std/zig/system/darwin.zig
new file mode 100644
index 0000000000..1e8d9e4b48
--- /dev/null
+++ b/lib/std/zig/system/darwin.zig
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: MIT
+// Copyright (c) 2015-2021 Zig Contributors
+// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
+// The MIT license requires this copyright notice to be included in all copies
+// and substantial portions of the software.
+const std = @import("std");
+const mem = std.mem;
+const Allocator = mem.Allocator;
+const Target = std.Target;
+
+pub const macos = @import("darwin/macos.zig");
+
+/// Detect SDK path on Darwin.
+/// Calls `xcrun --sdk <target_sdk> --show-sdk-path` which result can be used to specify
+/// `--sysroot` of the compiler.
+/// The caller needs to free the resulting path slice.
+pub fn getSDKPath(allocator: *Allocator, target: Target) !?[]u8 {
+ const is_simulator_abi = target.abi == .simulator;
+ const sdk = switch (target.os.tag) {
+ .macos => "macosx",
+ .ios => if (is_simulator_abi) "iphonesimulator" else "iphoneos",
+ .watchos => if (is_simulator_abi) "watchsimulator" else "watchos",
+ .tvos => if (is_simulator_abi) "appletvsimulator" else "appletvos",
+ else => return null,
+ };
+
+ const argv = &[_][]const u8{ "xcrun", "--sdk", sdk, "--show-sdk-path" };
+ const result = try std.ChildProcess.exec(.{ .allocator = allocator, .argv = argv });
+ defer {
+ allocator.free(result.stderr);
+ allocator.free(result.stdout);
+ }
+ if (result.stderr.len != 0 or result.term.Exited != 0) {
+ // We don't actually care if there were errors as this is best-effort check anyhow
+ // and in the worst case the user can specify the sysroot manually.
+ return null;
+ }
+ const sysroot = try allocator.dupe(u8, mem.trimRight(u8, result.stdout, "\r\n"));
+ return sysroot;
+}
+
+test "" {
+ _ = @import("darwin/macos.zig");
+}
diff --git a/lib/std/zig/system/macos.zig b/lib/std/zig/system/darwin/macos.zig
index ae450ecae5..c8f48800c5 100644
--- a/lib/std/zig/system/macos.zig
+++ b/lib/std/zig/system/darwin/macos.zig
@@ -408,28 +408,6 @@ fn testVersionEquality(expected: std.builtin.Version, got: std.builtin.Version)
try testing.expectEqualStrings(s_expected, s_got);
}
-/// Detect SDK path on Darwin.
-/// Calls `xcrun --show-sdk-path` which result can be used to specify
-/// `-syslibroot` param of the linker.
-/// The caller needs to free the resulting path slice.
-pub fn getSDKPath(allocator: *mem.Allocator) ![]u8 {
- assert(Target.current.isDarwin());
- const argv = &[_][]const u8{ "xcrun", "--show-sdk-path" };
- const result = try std.ChildProcess.exec(.{ .allocator = allocator, .argv = argv });
- defer {
- allocator.free(result.stderr);
- allocator.free(result.stdout);
- }
- if (result.stderr.len != 0) {
- std.log.err("unexpected 'xcrun --show-sdk-path' stderr: {s}", .{result.stderr});
- }
- if (result.term.Exited != 0) {
- return error.ProcessTerminated;
- }
- const syslibroot = mem.trimRight(u8, result.stdout, "\r\n");
- return mem.dupe(allocator, u8, syslibroot);
-}
-
pub fn detectNativeCpuAndFeatures() ?Target.Cpu {
var cpu_family: os.CPUFAMILY = undefined;
var len: usize = @sizeOf(os.CPUFAMILY);