authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-03 20:39:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-15 10:48:13-07:00
log1e63573d359f15042ebdcc9b0c32d7ce4662899f
tree8a0bbc14b98dac9b93409769a70cbc37adb42cbd
parentbb1960c2a4ae3257fab3eedd7fdf2293fde59cec

std.build.CompileStep: eliminate std.log usage


5 files changed, 42 insertions(+), 47 deletions(-)

lib/build_runner.zig+3
......@@ -179,6 +179,8 @@ pub fn main() !void {
179179 usageAndErr(builder, false, stderr_stream);
180180 };
181181 try debug_log_scopes.append(next_arg);
182 } else if (mem.eql(u8, arg, "--debug-pkg-config")) {
183 builder.debug_pkg_config = true;
182184 } else if (mem.eql(u8, arg, "--debug-compile-errors")) {
183185 builder.debug_compile_errors = true;
184186 } else if (mem.eql(u8, arg, "--glibc-runtimes")) {
......@@ -809,6 +811,7 @@ fn usage(builder: *std.Build, already_ran_build: bool, out_stream: anytype) !voi
809811 \\ --zig-lib-dir [arg] Override path to Zig lib directory
810812 \\ --build-runner [file] Override path to build runner
811813 \\ --debug-log [scope] Enable debugging the compiler
814 \\ --debug-pkg-config Fail if unknown pkg-config flags encountered
812815 \\ --verbose-link Enable compiler debug output for linking
813816 \\ --verbose-air Enable compiler debug output for Zig AIR
814817 \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR
lib/std/Build.zig+2
......@@ -85,6 +85,7 @@ pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null,
8585args: ?[][]const u8 = null,
8686debug_log_scopes: []const []const u8 = &.{},
8787debug_compile_errors: bool = false,
88debug_pkg_config: bool = false,
8889
8990/// Experimental. Use system Darling installation to run cross compiled macOS build artifacts.
9091enable_darling: bool = false,
......@@ -316,6 +317,7 @@ fn createChildOnly(parent: *Build, dep_name: []const u8, build_root: Cache.Direc
316317 .zig_lib_dir = parent.zig_lib_dir,
317318 .debug_log_scopes = parent.debug_log_scopes,
318319 .debug_compile_errors = parent.debug_compile_errors,
320 .debug_pkg_config = parent.debug_pkg_config,
319321 .enable_darling = parent.enable_darling,
320322 .enable_qemu = parent.enable_qemu,
321323 .enable_rosetta = parent.enable_rosetta,
lib/std/Build/CompileStep.zig+36-45
......@@ -1,7 +1,6 @@
11const builtin = @import("builtin");
22const std = @import("../std.zig");
33const mem = std.mem;
4const log = std.log;
54const fs = std.fs;
65const assert = std.debug.assert;
76const panic = std.debug.panic;
......@@ -697,7 +696,7 @@ pub fn linkSystemLibraryNeededPkgConfigOnly(self: *CompileStep, lib_name: []cons
697696
698697/// Run pkg-config for the given library name and parse the output, returning the arguments
699698/// that should be passed to zig to link the given library.
700pub fn runPkgConfig(self: *CompileStep, lib_name: []const u8) ![]const []const u8 {
699fn runPkgConfig(self: *CompileStep, lib_name: []const u8) ![]const []const u8 {
701700 const b = self.step.owner;
702701 const pkg_name = match: {
703702 // First we have to map the library name to pkg config name. Unfortunately,
......@@ -783,8 +782,8 @@ pub fn runPkgConfig(self: *CompileStep, lib_name: []const u8) ![]const []const u
783782 try zig_args.appendSlice(&[_][]const u8{ "-D", macro });
784783 } else if (mem.startsWith(u8, tok, "-D")) {
785784 try zig_args.append(tok);
786 } else if (b.verbose) {
787 log.warn("Ignoring pkg-config flag '{s}'", .{tok});
785 } else if (b.debug_pkg_config) {
786 return self.step.fail("unknown pkg-config flag '{s}'", .{tok});
788787 }
789788 }
790789
......@@ -1190,8 +1189,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
11901189 const self = @fieldParentPtr(CompileStep, "step", step);
11911190
11921191 if (self.root_src == null and self.link_objects.items.len == 0) {
1193 log.err("{s}: linker needs 1 or more objects to link", .{self.step.name});
1194 return error.NeedAnObject;
1192 return step.fail("the linker needs one or more objects to link", .{});
11951193 }
11961194
11971195 var zig_args = ArrayList([]const u8).init(b.allocator);
......@@ -1280,10 +1278,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
12801278 .system_lib => |system_lib| {
12811279 const prefix: []const u8 = prefix: {
12821280 if (system_lib.needed) break :prefix "-needed-l";
1283 if (system_lib.weak) {
1284 if (self.target.isDarwin()) break :prefix "-weak-l";
1285 log.warn("Weak library import used for a non-darwin target, this will be converted to normally library import `-lname`", .{});
1286 }
1281 if (system_lib.weak) break :prefix "-weak-l";
12871282 break :prefix "-l";
12881283 };
12891284 switch (system_lib.use_pkg_config) {
......@@ -1774,18 +1769,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
17741769 try zig_args.append(c_macro);
17751770 }
17761771
1777 if (self.target.isDarwin()) {
1778 for (self.framework_dirs.items) |dir| {
1779 if (b.sysroot != null) {
1780 try zig_args.append("-iframeworkwithsysroot");
1781 } else {
1782 try zig_args.append("-iframework");
1783 }
1784 try zig_args.append(dir);
1785 try zig_args.append("-F");
1786 try zig_args.append(dir);
1772 for (self.framework_dirs.items) |dir| {
1773 if (b.sysroot != null) {
1774 try zig_args.append("-iframeworkwithsysroot");
1775 } else {
1776 try zig_args.append("-iframework");
17871777 }
1778 try zig_args.append(dir);
1779 try zig_args.append("-F");
1780 try zig_args.append(dir);
1781 }
17881782
1783 {
17891784 var it = self.frameworks.iterator();
17901785 while (it.next()) |entry| {
17911786 const name = entry.key_ptr.*;
......@@ -1799,14 +1794,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
17991794 }
18001795 try zig_args.append(name);
18011796 }
1802 } else {
1803 if (self.framework_dirs.items.len > 0) {
1804 log.info("Framework directories have been added for a non-darwin target, this will have no affect on the build", .{});
1805 }
1806
1807 if (self.frameworks.count() > 0) {
1808 log.info("Frameworks have been added for a non-darwin target, this will have no affect on the build", .{});
1809 }
18101797 }
18111798
18121799 if (b.sysroot) |sysroot| {
......@@ -1970,8 +1957,15 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
19701957 }
19711958 }
19721959
1973 if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and self.version != null and self.target.wantSharedLibSymLinks()) {
1974 try doAtomicSymLinks(b.allocator, self.getOutputSource().getPath(b), self.major_only_filename.?, self.name_only_filename.?);
1960 if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and
1961 self.version != null and self.target.wantSharedLibSymLinks())
1962 {
1963 try doAtomicSymLinks(
1964 step,
1965 self.getOutputSource().getPath(b),
1966 self.major_only_filename.?,
1967 self.name_only_filename.?,
1968 );
19751969 }
19761970}
19771971
......@@ -2013,30 +2007,27 @@ fn findVcpkgRoot(allocator: Allocator) !?[]const u8 {
20132007}
20142008
20152009pub fn doAtomicSymLinks(
2016 allocator: Allocator,
2010 step: *Step,
20172011 output_path: []const u8,
20182012 filename_major_only: []const u8,
20192013 filename_name_only: []const u8,
20202014) !void {
2015 const arena = step.owner.allocator;
20212016 const out_dir = fs.path.dirname(output_path) orelse ".";
20222017 const out_basename = fs.path.basename(output_path);
20232018 // sym link for libfoo.so.1 to libfoo.so.1.2.3
2024 const major_only_path = try fs.path.join(
2025 allocator,
2026 &[_][]const u8{ out_dir, filename_major_only },
2027 );
2028 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
2029 log.err("Unable to symlink {s} -> {s}", .{ major_only_path, out_basename });
2030 return err;
2019 const major_only_path = try fs.path.join(arena, &.{ out_dir, filename_major_only });
2020 fs.atomicSymLink(arena, out_basename, major_only_path) catch |err| {
2021 return step.fail("unable to symlink {s} -> {s}: {s}", .{
2022 major_only_path, out_basename, @errorName(err),
2023 });
20312024 };
20322025 // sym link for libfoo.so to libfoo.so.1
2033 const name_only_path = try fs.path.join(
2034 allocator,
2035 &[_][]const u8{ out_dir, filename_name_only },
2036 );
2037 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
2038 log.err("Unable to symlink {s} -> {s}", .{ name_only_path, filename_major_only });
2039 return err;
2026 const name_only_path = try fs.path.join(arena, &.{ out_dir, filename_name_only });
2027 fs.atomicSymLink(arena, filename_major_only, name_only_path) catch |err| {
2028 return step.fail("Unable to symlink {s} -> {s}: {s}", .{
2029 name_only_path, filename_major_only, @errorName(err),
2030 });
20402031 };
20412032}
20422033
lib/std/Build/InstallArtifactStep.zig+1-1
......@@ -83,7 +83,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
8383 full_dest_path,
8484 );
8585 if (self.artifact.isDynamicLibrary() and self.artifact.version != null and self.artifact.target.wantSharedLibSymLinks()) {
86 try CompileStep.doAtomicSymLinks(src_builder.allocator, full_dest_path, self.artifact.major_only_filename.?, self.artifact.name_only_filename.?);
86 try CompileStep.doAtomicSymLinks(step, full_dest_path, self.artifact.major_only_filename.?, self.artifact.name_only_filename.?);
8787 }
8888 if (self.artifact.isDynamicLibrary() and self.artifact.target.isWindows() and self.artifact.emit_implib != .no_emit) {
8989 const full_implib_path = dest_builder.getInstallPath(self.dest_dir, self.artifact.out_lib_filename);
lib/std/Build/RemoveDirStep.zig-1
......@@ -1,5 +1,4 @@
11const std = @import("../std.zig");
2const log = std.log;
32const fs = std.fs;
43const Step = std.Build.Step;
54const RemoveDirStep = @This();