Skip to content

Commit 05eb30e

Browse files
committed
comp: move all of the logic into detectLibCFromLibCInstallation
1 parent 3617eb1 commit 05eb30e

File tree

1 file changed

+21
-36
lines changed

1 file changed

+21
-36
lines changed

src/Compilation.zig

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ job_queued_compiler_rt_obj: bool = false,
104104
alloc_failure_occurred: bool = false,
105105
formatted_panics: bool = false,
106106
last_update_was_cache_hit: bool = false,
107-
want_native_paths: bool = false,
108107

109108
c_source_files: []const CSourceFile,
110109
clang_argv: []const []const u8,
@@ -854,10 +853,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
854853

855854
const darwin_native = (comptime builtin.target.isDarwin()) and options.target.isDarwin() and
856855
options.sysroot == null;
857-
comp.want_native_paths = (options.sysroot == null and options.is_native_os and
858-
(options.system_lib_names.len > 0 or options.want_native_include_dirs orelse false)) or
859-
darwin_native;
860-
861856
const darwin_sdk: ?std.zig.system.darwin.DarwinSDK = if (darwin_native and
862857
!std.zig.system.NativePaths.isNix() and
863858
std.zig.system.darwin.isDarwinSDKInstalled(arena))
@@ -947,13 +942,17 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
947942

948943
const dll_export_fns = options.dll_export_fns orelse (is_dyn_lib or options.rdynamic);
949944

950-
const libc_dirs = try comp.detectLibCDirs(
945+
const want_native_paths = (options.sysroot == null and options.is_native_os and
946+
(options.system_lib_names.len > 0 or options.want_native_include_dirs orelse false)) or
947+
darwin_native;
948+
const libc_dirs = try detectLibCDirs(
951949
arena,
952950
options.zig_lib_directory.path.?,
953951
options.target,
954952
options.is_native_abi,
955953
link_libc,
956954
options.libc_installation,
955+
want_native_paths,
957956
darwin_sdk,
958957
);
959958

@@ -4312,28 +4311,6 @@ pub fn addCCArgs(
43124311
try argv.append("-isystem");
43134312
try argv.append(c_headers_dir);
43144313

4315-
if (comp.want_native_paths) {
4316-
const paths = std.zig.system.NativePaths.detect(arena, target) catch |err| {
4317-
fatal("unable to detect native system paths: {s}", .{@errorName(err)});
4318-
};
4319-
4320-
for (paths.warnings.items) |warning| {
4321-
std.log.warn("{s}", .{warning});
4322-
}
4323-
4324-
try argv.ensureUnusedCapacity(paths.include_dirs.items.len * 2);
4325-
for (paths.include_dirs.items) |include_dir| {
4326-
argv.appendAssumeCapacity("-isystem");
4327-
argv.appendAssumeCapacity(include_dir);
4328-
}
4329-
4330-
try argv.ensureUnusedCapacity(paths.framework_dirs.items.len * 2);
4331-
for (paths.framework_dirs.items) |framework_dir| {
4332-
argv.appendAssumeCapacity("-iframework");
4333-
argv.appendAssumeCapacity(framework_dir);
4334-
}
4335-
}
4336-
43374314
try argv.ensureUnusedCapacity(comp.libc_include_dir_list.len * 2);
43384315
for (comp.libc_include_dir_list) |include_dir| {
43394316
argv.appendAssumeCapacity("-isystem");
@@ -4816,13 +4793,13 @@ const LibCDirs = struct {
48164793
};
48174794

48184795
fn detectLibCDirs(
4819-
comp: *Compilation,
48204796
arena: Allocator,
48214797
zig_lib_dir: []const u8,
48224798
target: Target,
48234799
is_native_abi: bool,
48244800
link_libc: bool,
48254801
libc_installation: ?*const LibCInstallation,
4802+
want_native_paths: bool,
48264803
darwin_sdk: ?std.zig.system.darwin.DarwinSDK,
48274804
) !LibCDirs {
48284805
if (!link_libc) {
@@ -4836,7 +4813,7 @@ fn detectLibCDirs(
48364813
}
48374814

48384815
if (libc_installation) |lci| {
4839-
return comp.detectLibCFromLibCInstallation(arena, target, lci);
4816+
return detectLibCFromLibCInstallation(arena, target, lci, want_native_paths);
48404817
}
48414818

48424819
// If linking system libraries and targeting the native abi, default to
@@ -4862,7 +4839,7 @@ fn detectLibCDirs(
48624839
},
48634840
else => |e| return e,
48644841
};
4865-
return comp.detectLibCFromLibCInstallation(arena, target, libc);
4842+
return detectLibCFromLibCInstallation(arena, target, libc, want_native_paths);
48664843
}
48674844

48684845
// If not linking system libraries, build and provide our own libc by
@@ -4887,7 +4864,7 @@ fn detectLibCDirs(
48874864
.darwin_sdk = darwin_sdk,
48884865
.verbose = true,
48894866
});
4890-
return comp.detectLibCFromLibCInstallation(arena, target, libc);
4867+
return detectLibCFromLibCInstallation(arena, target, libc, want_native_paths);
48914868
}
48924869

48934870
return LibCDirs{
@@ -4900,10 +4877,10 @@ fn detectLibCDirs(
49004877
}
49014878

49024879
fn detectLibCFromLibCInstallation(
4903-
comp: *Compilation,
49044880
arena: Allocator,
49054881
target: Target,
49064882
lci: *const LibCInstallation,
4883+
want_native_paths: bool,
49074884
) !LibCDirs {
49084885
var list = try std.ArrayList([]const u8).initCapacity(arena, 5);
49094886
var lib_dir_list = std.ArrayList([]const u8).init(arena);
@@ -4940,7 +4917,7 @@ fn detectLibCFromLibCInstallation(
49404917
list.appendAssumeCapacity(config_dir);
49414918
}
49424919

4943-
if (comp.want_native_paths) {
4920+
if (want_native_paths) {
49444921
const paths = std.zig.system.NativePaths.detect(arena, target) catch |err| {
49454922
fatal("unable to detect native system paths: {s}", .{@errorName(err)});
49464923
};
@@ -4949,16 +4926,24 @@ fn detectLibCFromLibCInstallation(
49494926
std.log.warn("{s}", .{warning});
49504927
}
49514928

4929+
try list.ensureUnusedCapacity(paths.include_dirs.items.len);
4930+
for (paths.include_dirs.items) |include_dir| {
4931+
list.appendAssumeCapacity(include_dir);
4932+
}
4933+
49524934
try framework_list.ensureUnusedCapacity(paths.framework_dirs.items.len);
49534935
for (paths.framework_dirs.items) |framework_dir| {
49544936
framework_list.appendAssumeCapacity(framework_dir);
49554937
}
49564938

4939+
try lib_dir_list.ensureUnusedCapacity(paths.lib_dirs.items.len);
49574940
for (paths.lib_dirs.items) |lib_dir| {
4958-
try lib_dir_list.append(lib_dir);
4941+
lib_dir_list.appendAssumeCapacity(lib_dir);
49594942
}
4943+
4944+
try rpath_list.ensureUnusedCapacity(paths.rpaths.items.len);
49604945
for (paths.rpaths.items) |rpath| {
4961-
try rpath_list.append(rpath);
4946+
rpath_list.appendAssumeCapacity(rpath);
49624947
}
49634948
}
49644949

0 commit comments

Comments
 (0)