diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-12-15 19:56:32 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-12-16 03:01:13 -0700 |
| commit | c9863c0a0cd959a1fec748dd9cc8f841e2c81a30 (patch) | |
| tree | 5f4575841ec6ef38c5786a5251e3f7af32fccd8f /src | |
| parent | c8af00c66e8b6f62e4dd6ac4d86a3de03e9ea354 (diff) | |
| download | zig-c9863c0a0cd959a1fec748dd9cc8f841e2c81a30.tar.gz zig-c9863c0a0cd959a1fec748dd9cc8f841e2c81a30.zip | |
CLI: helpful error message when libc requested but not provided
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 8 | ||||
| -rw-r--r-- | src/main.zig | 24 |
2 files changed, 30 insertions, 2 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 236a344027..b3c2608c05 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1586,6 +1586,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { // If we need to build glibc for the target, add work items for it. // We go through the work queue so that building can be done in parallel. if (comp.wantBuildGLibCFromSource()) { + if (!target_util.canBuildLibC(comp.getTarget())) return error.LibCUnavailable; + if (glibc.needsCrtiCrtn(comp.getTarget())) { try comp.work_queue.write(&[_]Job{ .{ .glibc_crt_file = .crti_o }, @@ -1599,6 +1601,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { }); } if (comp.wantBuildMuslFromSource()) { + if (!target_util.canBuildLibC(comp.getTarget())) return error.LibCUnavailable; + try comp.work_queue.ensureUnusedCapacity(6); if (musl.needsCrtiCrtn(comp.getTarget())) { comp.work_queue.writeAssumeCapacity(&[_]Job{ @@ -1617,6 +1621,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { }); } if (comp.wantBuildWasiLibcFromSource()) { + if (!target_util.canBuildLibC(comp.getTarget())) return error.LibCUnavailable; + const wasi_emulated_libs = comp.bin_file.options.wasi_emulated_libs; try comp.work_queue.ensureUnusedCapacity(wasi_emulated_libs.len + 2); // worst-case we need all components for (wasi_emulated_libs) |crt_file| { @@ -1630,6 +1636,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { }); } if (comp.wantBuildMinGWFromSource()) { + if (!target_util.canBuildLibC(comp.getTarget())) return error.LibCUnavailable; + const static_lib_jobs = [_]Job{ .{ .mingw_crt_file = .mingw32_lib }, .{ .mingw_crt_file = .msvcrt_os_lib }, diff --git a/src/main.zig b/src/main.zig index 57342702ee..e3221ecc67 100644 --- a/src/main.zig +++ b/src/main.zig @@ -2495,8 +2495,28 @@ fn buildOutputType( .debug_compile_errors = debug_compile_errors, .enable_link_snapshots = enable_link_snapshots, .native_darwin_sdk = native_darwin_sdk, - }) catch |err| { - fatal("unable to create compilation: {s}", .{@errorName(err)}); + }) catch |err| switch (err) { + error.LibCUnavailable => { + const target = target_info.target; + const triple_name = try target.zigTriple(arena); + std.log.err("unable to find or provide libc for target '{s}'", .{triple_name}); + + for (target_util.available_libcs) |t| { + if (t.arch == target.cpu.arch and t.os == target.os.tag) { + if (t.os_ver) |os_ver| { + std.log.info("zig can provide libc for related target {s}-{s}.{d}-{s}", .{ + @tagName(t.arch), @tagName(t.os), os_ver.major, @tagName(t.abi), + }); + } else { + std.log.info("zig can provide libc for related target {s}-{s}-{s}", .{ + @tagName(t.arch), @tagName(t.os), @tagName(t.abi), + }); + } + } + } + process.exit(1); + }, + else => fatal("unable to create compilation: {s}", .{@errorName(err)}), }; var comp_destroyed = false; defer if (!comp_destroyed) comp.destroy(); |
