authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-15 19:56:32-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-16 03:01:13-07:00
logc9863c0a0cd959a1fec748dd9cc8f841e2c81a30
tree5f4575841ec6ef38c5786a5251e3f7af32fccd8f
parentc8af00c66e8b6f62e4dd6ac4d86a3de03e9ea354

CLI: helpful error message when libc requested but not provided


2 files changed, 30 insertions(+), 2 deletions(-)

src/Compilation.zig+8
......@@ -1586,6 +1586,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
15861586 // If we need to build glibc for the target, add work items for it.
15871587 // We go through the work queue so that building can be done in parallel.
15881588 if (comp.wantBuildGLibCFromSource()) {
1589 if (!target_util.canBuildLibC(comp.getTarget())) return error.LibCUnavailable;
1590
15891591 if (glibc.needsCrtiCrtn(comp.getTarget())) {
15901592 try comp.work_queue.write(&[_]Job{
15911593 .{ .glibc_crt_file = .crti_o },
......@@ -1599,6 +1601,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
15991601 });
16001602 }
16011603 if (comp.wantBuildMuslFromSource()) {
1604 if (!target_util.canBuildLibC(comp.getTarget())) return error.LibCUnavailable;
1605
16021606 try comp.work_queue.ensureUnusedCapacity(6);
16031607 if (musl.needsCrtiCrtn(comp.getTarget())) {
16041608 comp.work_queue.writeAssumeCapacity(&[_]Job{
......@@ -1617,6 +1621,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
16171621 });
16181622 }
16191623 if (comp.wantBuildWasiLibcFromSource()) {
1624 if (!target_util.canBuildLibC(comp.getTarget())) return error.LibCUnavailable;
1625
16201626 const wasi_emulated_libs = comp.bin_file.options.wasi_emulated_libs;
16211627 try comp.work_queue.ensureUnusedCapacity(wasi_emulated_libs.len + 2); // worst-case we need all components
16221628 for (wasi_emulated_libs) |crt_file| {
......@@ -1630,6 +1636,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
16301636 });
16311637 }
16321638 if (comp.wantBuildMinGWFromSource()) {
1639 if (!target_util.canBuildLibC(comp.getTarget())) return error.LibCUnavailable;
1640
16331641 const static_lib_jobs = [_]Job{
16341642 .{ .mingw_crt_file = .mingw32_lib },
16351643 .{ .mingw_crt_file = .msvcrt_os_lib },
src/main.zig+22-2
......@@ -2495,8 +2495,28 @@ fn buildOutputType(
24952495 .debug_compile_errors = debug_compile_errors,
24962496 .enable_link_snapshots = enable_link_snapshots,
24972497 .native_darwin_sdk = native_darwin_sdk,
2498 }) catch |err| {
2499 fatal("unable to create compilation: {s}", .{@errorName(err)});
2498 }) catch |err| switch (err) {
2499 error.LibCUnavailable => {
2500 const target = target_info.target;
2501 const triple_name = try target.zigTriple(arena);
2502 std.log.err("unable to find or provide libc for target '{s}'", .{triple_name});
2503
2504 for (target_util.available_libcs) |t| {
2505 if (t.arch == target.cpu.arch and t.os == target.os.tag) {
2506 if (t.os_ver) |os_ver| {
2507 std.log.info("zig can provide libc for related target {s}-{s}.{d}-{s}", .{
2508 @tagName(t.arch), @tagName(t.os), os_ver.major, @tagName(t.abi),
2509 });
2510 } else {
2511 std.log.info("zig can provide libc for related target {s}-{s}-{s}", .{
2512 @tagName(t.arch), @tagName(t.os), @tagName(t.abi),
2513 });
2514 }
2515 }
2516 }
2517 process.exit(1);
2518 },
2519 else => fatal("unable to create compilation: {s}", .{@errorName(err)}),
25002520 };
25012521 var comp_destroyed = false;
25022522 defer if (!comp_destroyed) comp.destroy();