commit 8eaaa905f709db623432a95fd9d4e4dfecdb7eae (tree)
parent 647c6e0d0955260947d9a0e07014af2a337d9330
Author: LemonBoy <LemonBoy@users.noreply.github.com>
Date: Thu, 19 Nov 2020 23:30:16 +0100
stage2: Make zig cc more verbose (#7166)
* stage2: Make zig cc more verbose
Make `zig cc` print more info from Clang itself and from our own linker
invocation, this is needed for CMake to properly discover all the
include directories and library search paths.
Closes #7110
* Update `update_clang_options`
* Typo fixes
Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
Diffstat:
7 files changed, 47 insertions(+), 14 deletions(-)
diff --git a/src/clang_options_data.zig b/src/clang_options_data.zig
@@ -165,7 +165,7 @@ sepd1("Zlinker-input"),
.{
.name = "###",
.syntax = .flag,
- .zig_equivalent = .verbose_cmds,
+ .zig_equivalent = .dry_run,
.pd1 = true,
.pd2 = false,
.psl = false,
@@ -4439,7 +4439,14 @@ flagpd1("twolevel_namespace_hints"),
sepd1("umbrella"),
flagpd1("undef"),
sepd1("unexported_symbols_list"),
-flagpd1("v"),
+.{
+ .name = "v",
+ .syntax = .flag,
+ .zig_equivalent = .verbose,
+ .pd1 = true,
+ .pd2 = false,
+ .psl = false,
+},
flagpd1("vectorize-loops"),
flagpd1("vectorize-slp"),
flagpd1("verify"),
diff --git a/src/link/Coff.zig b/src/link/Coff.zig
@@ -907,8 +907,11 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
// Create an LLD command line and invoke it.
var argv = std.ArrayList([]const u8).init(self.base.allocator);
defer argv.deinit();
- // Even though we're calling LLD as a library it thinks the first argument is its own exe name.
- try argv.append("lld");
+ // The first argument is ignored as LLD is called as a library, set it
+ // anyway to the correct LLD driver name for this target so that it's
+ // correctly printed when `verbose_link` is true. This is needed for some
+ // tools such as CMake when Zig is used as C compiler.
+ try argv.append("lld-link");
try argv.append("-ERRORLIMIT:0");
try argv.append("-NOLOGO");
diff --git a/src/link/Elf.zig b/src/link/Elf.zig
@@ -1353,8 +1353,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
// Create an LLD command line and invoke it.
var argv = std.ArrayList([]const u8).init(self.base.allocator);
defer argv.deinit();
- // Even though we're calling LLD as a library it thinks the first argument is its own exe name.
- try argv.append("lld");
+ // The first argument is ignored as LLD is called as a library, set it
+ // anyway to the correct LLD driver name for this target so that it's
+ // correctly printed when `verbose_link` is true. This is needed for some
+ // tools such as CMake when Zig is used as C compiler.
+ try argv.append("ld.lld");
if (is_obj) {
try argv.append("-r");
}
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
@@ -542,8 +542,12 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
if (self.base.options.system_linker_hack) {
try argv.append("ld");
} else {
- // Even though we're calling LLD as a library it thinks the first argument is its own exe name.
- try argv.append("lld");
+ // The first argument is ignored as LLD is called as a library, set
+ // it anyway to the correct LLD driver name for this target so that
+ // it's correctly printed when `verbose_link` is true. This is
+ // needed for some tools such as CMake when Zig is used as C
+ // compiler.
+ try argv.append("ld64");
try argv.append("-error-limit");
try argv.append("0");
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig
@@ -339,8 +339,11 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
// Create an LLD command line and invoke it.
var argv = std.ArrayList([]const u8).init(self.base.allocator);
defer argv.deinit();
- // Even though we're calling LLD as a library it thinks the first argument is its own exe name.
- try argv.append("lld");
+ // The first argument is ignored as LLD is called as a library, set it
+ // anyway to the correct LLD driver name for this target so that it's
+ // correctly printed when `verbose_link` is true. This is needed for some
+ // tools such as CMake when Zig is used as C compiler.
+ try argv.append("ld-wasm");
if (is_obj) {
try argv.append("-r");
}
diff --git a/src/main.zig b/src/main.zig
@@ -1062,9 +1062,17 @@ fn buildOutputType(
}
},
.linker_script => linker_script = it.only_arg,
- .verbose_cmds => {
- verbose_cc = true;
+ .verbose => {
+ verbose_link = true;
+ // Have Clang print more infos, some tools such as CMake
+ // parse this to discover any implicit include and
+ // library dir to look-up into.
+ try clang_argv.append("-v");
+ },
+ .dry_run => {
verbose_link = true;
+ try clang_argv.append("-###");
+ // XXX: Don't execute anything!
},
.for_linker => try linker_args.append(it.only_arg),
.linker_input_z => {
@@ -2776,7 +2784,8 @@ pub const ClangArgIterator = struct {
debug,
sanitize,
linker_script,
- verbose_cmds,
+ dry_run,
+ verbose,
for_linker,
linker_input_z,
lib_dir,
diff --git a/tools/update_clang_options.zig b/tools/update_clang_options.zig
@@ -214,7 +214,11 @@ const known_options = [_]KnownOpt{
},
.{
.name = "###",
- .ident = "verbose_cmds",
+ .ident = "dry_run",
+ },
+ .{
+ .name = "v",
+ .ident = "verbose",
},
.{
.name = "L",