kubkon review changes: 3

- make vendored settings failure unreachable
- rename field `darwinSdkLayout` → `darwin_sdk_layout`
- make `darwin_sdk_layout` optional
This commit is contained in:
Michael Dusan 2023-09-25 15:51:57 -04:00
parent f6877fbc49
commit ebd0776b28
No known key found for this signature in database
GPG Key ID: ED4C5BA849FA1B74
4 changed files with 14 additions and 20 deletions

View File

@ -1557,7 +1557,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
.link_libc = link_libc,
.link_libcpp = link_libcpp,
.link_libunwind = link_libunwind,
.darwinSdkLayout = libc_dirs.darwinSdkLayout,
.darwin_sdk_layout = libc_dirs.darwin_sdk_layout,
.objects = options.link_objects,
.frameworks = options.frameworks,
.framework_dirs = options.framework_dirs,
@ -5287,7 +5287,7 @@ fn detectWin32ResourceIncludeDirs(arena: Allocator, options: InitOptions) !LibCD
.libc_installation = null,
.libc_framework_dir_list = &.{},
.sysroot = null,
.darwinSdkLayout = .none,
.darwin_sdk_layout = null,
},
}
}
@ -5656,7 +5656,7 @@ const LibCDirs = struct {
libc_installation: ?*const LibCInstallation,
libc_framework_dir_list: []const []const u8,
sysroot: ?[]const u8,
darwinSdkLayout: link.DarwinSdkLayout,
darwin_sdk_layout: ?link.DarwinSdkLayout,
};
fn getZigShippedLibCIncludeDirsDarwin(arena: Allocator, zig_lib_dir: []const u8) !LibCDirs {
@ -5672,7 +5672,7 @@ fn getZigShippedLibCIncludeDirsDarwin(arena: Allocator, zig_lib_dir: []const u8)
.libc_installation = null,
.libc_framework_dir_list = &.{},
.sysroot = null,
.darwinSdkLayout = .vendored,
.darwin_sdk_layout = .vendored,
};
}
@ -5690,7 +5690,7 @@ pub fn detectLibCIncludeDirs(
.libc_installation = null,
.libc_framework_dir_list = &.{},
.sysroot = null,
.darwinSdkLayout = .none,
.darwin_sdk_layout = null,
};
}
@ -5748,7 +5748,7 @@ pub fn detectLibCIncludeDirs(
.libc_installation = null,
.libc_framework_dir_list = &.{},
.sysroot = null,
.darwinSdkLayout = .none,
.darwin_sdk_layout = null,
};
}
@ -5803,7 +5803,7 @@ fn detectLibCFromLibCInstallation(arena: Allocator, target: Target, lci: *const
.libc_installation = lci,
.libc_framework_dir_list = framework_list.items,
.sysroot = sysroot,
.darwinSdkLayout = if (sysroot == null) .none else .sdk,
.darwin_sdk_layout = if (sysroot == null) null else .sdk,
};
}
@ -5865,7 +5865,7 @@ fn detectLibCFromBuilding(
.libc_installation = null,
.libc_framework_dir_list = &.{},
.sysroot = null,
.darwinSdkLayout = .vendored,
.darwin_sdk_layout = .vendored,
};
}

View File

@ -137,7 +137,7 @@ pub const Options = struct {
link_libc: bool,
link_libcpp: bool,
link_libunwind: bool,
darwinSdkLayout: DarwinSdkLayout,
darwin_sdk_layout: ?DarwinSdkLayout,
function_sections: bool,
no_builtin: bool,
eh_frame_hdr: bool,
@ -285,8 +285,6 @@ pub const CompressDebugSections = enum { none, zlib };
/// The filesystem layout of darwin SDK elements.
pub const DarwinSdkLayout = enum {
/// Does not apply to the target.
none,
/// macOS SDK layout: TOP { /usr/include, /usr/lib, /System/Library/Frameworks }.
sdk,
/// Shipped libc layout: TOP { /lib/libc/include, /lib/libc/darwin, <NONE> }.

View File

@ -652,8 +652,7 @@ pub fn resolveLibSystem(
"libSystem",
)) break :success;
switch (self.base.options.darwinSdkLayout) {
.none => unreachable,
switch (self.base.options.darwin_sdk_layout.?) {
.sdk => {
const dir = try fs.path.join(tmp_arena, &[_][]const u8{ self.base.options.sysroot.?, "usr", "lib" });
if (try accessLibPath(tmp_arena, &test_path, &checked_paths, dir, "libSystem")) break :success;

View File

@ -474,19 +474,16 @@ pub fn inferSdkVersion(gpa: Allocator, comp: *const Compilation) ?std.SemanticVe
const options = comp.bin_file.options;
const sdk_dir = switch (options.darwinSdkLayout) {
.none => unreachable,
const sdk_layout = options.darwin_sdk_layout.?;
const sdk_dir = switch (sdk_layout) {
.sdk => options.sysroot.?,
.vendored => std.fs.path.join(arena, &.{ comp.zig_lib_directory.path.?, "libc", "darwin" }) catch return null,
};
if (readSdkVersionFromSettings(arena, sdk_dir)) |ver| {
return parseSdkVersion(ver);
} else |_| {
if (options.darwinSdkLayout == .vendored) {
// vendored layout does not have versioned pathname
return null;
}
// We control vendored and reading settings should always succeed.
if (sdk_layout == .vendored) @panic("zig installation bug: unable to parse SDK version");
}
// infer from pathname