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 {...@@ -1586,6 +1586,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1586 // If we need to build glibc for the target, add work items for it.1586 // If we need to build glibc for the target, add work items for it.
1587 // We go through the work queue so that building can be done in parallel.1587 // We go through the work queue so that building can be done in parallel.
1588 if (comp.wantBuildGLibCFromSource()) {1588 if (comp.wantBuildGLibCFromSource()) {
1589 if (!target_util.canBuildLibC(comp.getTarget())) return error.LibCUnavailable;
1590
1589 if (glibc.needsCrtiCrtn(comp.getTarget())) {1591 if (glibc.needsCrtiCrtn(comp.getTarget())) {
1590 try comp.work_queue.write(&[_]Job{1592 try comp.work_queue.write(&[_]Job{
1591 .{ .glibc_crt_file = .crti_o },1593 .{ .glibc_crt_file = .crti_o },
...@@ -1599,6 +1601,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1599,6 +1601,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1599 });1601 });
1600 }1602 }
1601 if (comp.wantBuildMuslFromSource()) {1603 if (comp.wantBuildMuslFromSource()) {
1604 if (!target_util.canBuildLibC(comp.getTarget())) return error.LibCUnavailable;
1605
1602 try comp.work_queue.ensureUnusedCapacity(6);1606 try comp.work_queue.ensureUnusedCapacity(6);
1603 if (musl.needsCrtiCrtn(comp.getTarget())) {1607 if (musl.needsCrtiCrtn(comp.getTarget())) {
1604 comp.work_queue.writeAssumeCapacity(&[_]Job{1608 comp.work_queue.writeAssumeCapacity(&[_]Job{
...@@ -1617,6 +1621,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1617,6 +1621,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1617 });1621 });
1618 }1622 }
1619 if (comp.wantBuildWasiLibcFromSource()) {1623 if (comp.wantBuildWasiLibcFromSource()) {
1624 if (!target_util.canBuildLibC(comp.getTarget())) return error.LibCUnavailable;
1625
1620 const wasi_emulated_libs = comp.bin_file.options.wasi_emulated_libs;1626 const wasi_emulated_libs = comp.bin_file.options.wasi_emulated_libs;
1621 try comp.work_queue.ensureUnusedCapacity(wasi_emulated_libs.len + 2); // worst-case we need all components1627 try comp.work_queue.ensureUnusedCapacity(wasi_emulated_libs.len + 2); // worst-case we need all components
1622 for (wasi_emulated_libs) |crt_file| {1628 for (wasi_emulated_libs) |crt_file| {
...@@ -1630,6 +1636,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1630,6 +1636,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1630 });1636 });
1631 }1637 }
1632 if (comp.wantBuildMinGWFromSource()) {1638 if (comp.wantBuildMinGWFromSource()) {
1639 if (!target_util.canBuildLibC(comp.getTarget())) return error.LibCUnavailable;
1640
1633 const static_lib_jobs = [_]Job{1641 const static_lib_jobs = [_]Job{
1634 .{ .mingw_crt_file = .mingw32_lib },1642 .{ .mingw_crt_file = .mingw32_lib },
1635 .{ .mingw_crt_file = .msvcrt_os_lib },1643 .{ .mingw_crt_file = .msvcrt_os_lib },
src/main.zig+22-2
...@@ -2495,8 +2495,28 @@ fn buildOutputType(...@@ -2495,8 +2495,28 @@ fn buildOutputType(
2495 .debug_compile_errors = debug_compile_errors,2495 .debug_compile_errors = debug_compile_errors,
2496 .enable_link_snapshots = enable_link_snapshots,2496 .enable_link_snapshots = enable_link_snapshots,
2497 .native_darwin_sdk = native_darwin_sdk,2497 .native_darwin_sdk = native_darwin_sdk,
2498 }) catch |err| {2498 }) catch |err| switch (err) {
2499 fatal("unable to create compilation: {s}", .{@errorName(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)}),
2500 };2520 };
2501 var comp_destroyed = false;2521 var comp_destroyed = false;
2502 defer if (!comp_destroyed) comp.destroy();2522 defer if (!comp_destroyed) comp.destroy();