From 65bea514ae3860a5169d044d22ece7170c445bd3 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 11 Sep 2022 16:37:03 -0700 Subject: Compilation: handle system C compiler not found When linking libc and compiling natively, Zig tries to integrate with the system C compiler. However, this caused Zig to fail when no system C compiler is installed, despite the fact that Zig is perfectly capable of compiling & linking libc without one. This commit makes Zig fall back to using its own ability to provide libc in the case that no C compiler is installed. For glibc, it means sometimes getting the warning "zig cannot build new glibc version abc, providing instead xyz". Ideally, Zig would do some more validation about the system libraries being linked against, and report an error in case it could not provide the exact correct libc version of the system libraries (or that the system libraries themselves conflict with each other), however, I think it is fair to call that a separate enhancement. --- src/glibc.zig | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/glibc.zig') diff --git a/src/glibc.zig b/src/glibc.zig index 4e33867169..3dd7565e96 100644 --- a/src/glibc.zig +++ b/src/glibc.zig @@ -719,17 +719,16 @@ pub fn buildSharedObjects(comp: *Compilation) !void { .lt => continue, .gt => { // TODO Expose via compile error mechanism instead of log. - log.err("invalid target glibc version: {}", .{target_version}); + log.warn("invalid target glibc version: {}", .{target_version}); return error.InvalidTargetGLibCVersion; }, } - } else { + } else blk: { const latest_index = metadata.all_versions.len - 1; - // TODO Expose via compile error mechanism instead of log. - log.err("zig does not yet provide glibc version {}, the max provided version is {}", .{ + log.warn("zig cannot build new glibc version {}; providing instead {}", .{ target_version, metadata.all_versions[latest_index], }); - return error.InvalidTargetGLibCVersion; + break :blk latest_index; }; { -- cgit v1.2.3