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 {...@@ -179,6 +179,8 @@ pub fn main() !void {
179 usageAndErr(builder, false, stderr_stream);179 usageAndErr(builder, false, stderr_stream);
180 };180 };
181 try debug_log_scopes.append(next_arg);181 try debug_log_scopes.append(next_arg);
182 } else if (mem.eql(u8, arg, "--debug-pkg-config")) {
183 builder.debug_pkg_config = true;
182 } else if (mem.eql(u8, arg, "--debug-compile-errors")) {184 } else if (mem.eql(u8, arg, "--debug-compile-errors")) {
183 builder.debug_compile_errors = true;185 builder.debug_compile_errors = true;
184 } else if (mem.eql(u8, arg, "--glibc-runtimes")) {186 } 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...@@ -809,6 +811,7 @@ fn usage(builder: *std.Build, already_ran_build: bool, out_stream: anytype) !voi
809 \\ --zig-lib-dir [arg] Override path to Zig lib directory811 \\ --zig-lib-dir [arg] Override path to Zig lib directory
810 \\ --build-runner [file] Override path to build runner812 \\ --build-runner [file] Override path to build runner
811 \\ --debug-log [scope] Enable debugging the compiler813 \\ --debug-log [scope] Enable debugging the compiler
814 \\ --debug-pkg-config Fail if unknown pkg-config flags encountered
812 \\ --verbose-link Enable compiler debug output for linking815 \\ --verbose-link Enable compiler debug output for linking
813 \\ --verbose-air Enable compiler debug output for Zig AIR816 \\ --verbose-air Enable compiler debug output for Zig AIR
814 \\ --verbose-llvm-ir Enable compiler debug output for LLVM IR817 \\ --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,...@@ -85,6 +85,7 @@ pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null,
85args: ?[][]const u8 = null,85args: ?[][]const u8 = null,
86debug_log_scopes: []const []const u8 = &.{},86debug_log_scopes: []const []const u8 = &.{},
87debug_compile_errors: bool = false,87debug_compile_errors: bool = false,
88debug_pkg_config: bool = false,
8889
89/// Experimental. Use system Darling installation to run cross compiled macOS build artifacts.90/// Experimental. Use system Darling installation to run cross compiled macOS build artifacts.
90enable_darling: bool = false,91enable_darling: bool = false,
...@@ -316,6 +317,7 @@ fn createChildOnly(parent: *Build, dep_name: []const u8, build_root: Cache.Direc...@@ -316,6 +317,7 @@ fn createChildOnly(parent: *Build, dep_name: []const u8, build_root: Cache.Direc
316 .zig_lib_dir = parent.zig_lib_dir,317 .zig_lib_dir = parent.zig_lib_dir,
317 .debug_log_scopes = parent.debug_log_scopes,318 .debug_log_scopes = parent.debug_log_scopes,
318 .debug_compile_errors = parent.debug_compile_errors,319 .debug_compile_errors = parent.debug_compile_errors,
320 .debug_pkg_config = parent.debug_pkg_config,
319 .enable_darling = parent.enable_darling,321 .enable_darling = parent.enable_darling,
320 .enable_qemu = parent.enable_qemu,322 .enable_qemu = parent.enable_qemu,
321 .enable_rosetta = parent.enable_rosetta,323 .enable_rosetta = parent.enable_rosetta,
lib/std/Build/CompileStep.zig+36-45
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("../std.zig");2const std = @import("../std.zig");
3const mem = std.mem;3const mem = std.mem;
4const log = std.log;
5const fs = std.fs;4const fs = std.fs;
6const assert = std.debug.assert;5const assert = std.debug.assert;
7const panic = std.debug.panic;6const panic = std.debug.panic;
...@@ -697,7 +696,7 @@ pub fn linkSystemLibraryNeededPkgConfigOnly(self: *CompileStep, lib_name: []cons...@@ -697,7 +696,7 @@ pub fn linkSystemLibraryNeededPkgConfigOnly(self: *CompileStep, lib_name: []cons
697696
698/// Run pkg-config for the given library name and parse the output, returning the arguments697/// Run pkg-config for the given library name and parse the output, returning the arguments
699/// that should be passed to zig to link the given library.698/// 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 {
701 const b = self.step.owner;700 const b = self.step.owner;
702 const pkg_name = match: {701 const pkg_name = match: {
703 // First we have to map the library name to pkg config name. Unfortunately,702 // 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...@@ -783,8 +782,8 @@ pub fn runPkgConfig(self: *CompileStep, lib_name: []const u8) ![]const []const u
783 try zig_args.appendSlice(&[_][]const u8{ "-D", macro });782 try zig_args.appendSlice(&[_][]const u8{ "-D", macro });
784 } else if (mem.startsWith(u8, tok, "-D")) {783 } else if (mem.startsWith(u8, tok, "-D")) {
785 try zig_args.append(tok);784 try zig_args.append(tok);
786 } else if (b.verbose) {785 } else if (b.debug_pkg_config) {
787 log.warn("Ignoring pkg-config flag '{s}'", .{tok});786 return self.step.fail("unknown pkg-config flag '{s}'", .{tok});
788 }787 }
789 }788 }
790789
...@@ -1190,8 +1189,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -1190,8 +1189,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1190 const self = @fieldParentPtr(CompileStep, "step", step);1189 const self = @fieldParentPtr(CompileStep, "step", step);
11911190
1192 if (self.root_src == null and self.link_objects.items.len == 0) {1191 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});1192 return step.fail("the linker needs one or more objects to link", .{});
1194 return error.NeedAnObject;
1195 }1193 }
11961194
1197 var zig_args = ArrayList([]const u8).init(b.allocator);1195 var zig_args = ArrayList([]const u8).init(b.allocator);
...@@ -1280,10 +1278,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -1280,10 +1278,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1280 .system_lib => |system_lib| {1278 .system_lib => |system_lib| {
1281 const prefix: []const u8 = prefix: {1279 const prefix: []const u8 = prefix: {
1282 if (system_lib.needed) break :prefix "-needed-l";1280 if (system_lib.needed) break :prefix "-needed-l";
1283 if (system_lib.weak) {1281 if (system_lib.weak) break :prefix "-weak-l";
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 }
1287 break :prefix "-l";1282 break :prefix "-l";
1288 };1283 };
1289 switch (system_lib.use_pkg_config) {1284 switch (system_lib.use_pkg_config) {
...@@ -1774,18 +1769,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -1774,18 +1769,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1774 try zig_args.append(c_macro);1769 try zig_args.append(c_macro);
1775 }1770 }
17761771
1777 if (self.target.isDarwin()) {1772 for (self.framework_dirs.items) |dir| {
1778 for (self.framework_dirs.items) |dir| {1773 if (b.sysroot != null) {
1779 if (b.sysroot != null) {1774 try zig_args.append("-iframeworkwithsysroot");
1780 try zig_args.append("-iframeworkwithsysroot");1775 } else {
1781 } else {1776 try zig_args.append("-iframework");
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);
1787 }1777 }
1778 try zig_args.append(dir);
1779 try zig_args.append("-F");
1780 try zig_args.append(dir);
1781 }
17881782
1783 {
1789 var it = self.frameworks.iterator();1784 var it = self.frameworks.iterator();
1790 while (it.next()) |entry| {1785 while (it.next()) |entry| {
1791 const name = entry.key_ptr.*;1786 const name = entry.key_ptr.*;
...@@ -1799,14 +1794,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -1799,14 +1794,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1799 }1794 }
1800 try zig_args.append(name);1795 try zig_args.append(name);
1801 }1796 }
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 }
1810 }1797 }
18111798
1812 if (b.sysroot) |sysroot| {1799 if (b.sysroot) |sysroot| {
...@@ -1970,8 +1957,15 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -1970,8 +1957,15 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1970 }1957 }
1971 }1958 }
19721959
1973 if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and self.version != null and self.target.wantSharedLibSymLinks()) {1960 if (self.kind == .lib and self.linkage != null and self.linkage.? == .dynamic and
1974 try doAtomicSymLinks(b.allocator, self.getOutputSource().getPath(b), self.major_only_filename.?, self.name_only_filename.?);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 );
1975 }1969 }
1976}1970}
19771971
...@@ -2013,30 +2007,27 @@ fn findVcpkgRoot(allocator: Allocator) !?[]const u8 {...@@ -2013,30 +2007,27 @@ fn findVcpkgRoot(allocator: Allocator) !?[]const u8 {
2013}2007}
20142008
2015pub fn doAtomicSymLinks(2009pub fn doAtomicSymLinks(
2016 allocator: Allocator,2010 step: *Step,
2017 output_path: []const u8,2011 output_path: []const u8,
2018 filename_major_only: []const u8,2012 filename_major_only: []const u8,
2019 filename_name_only: []const u8,2013 filename_name_only: []const u8,
2020) !void {2014) !void {
2015 const arena = step.owner.allocator;
2021 const out_dir = fs.path.dirname(output_path) orelse ".";2016 const out_dir = fs.path.dirname(output_path) orelse ".";
2022 const out_basename = fs.path.basename(output_path);2017 const out_basename = fs.path.basename(output_path);
2023 // sym link for libfoo.so.1 to libfoo.so.1.2.32018 // sym link for libfoo.so.1 to libfoo.so.1.2.3
2024 const major_only_path = try fs.path.join(2019 const major_only_path = try fs.path.join(arena, &.{ out_dir, filename_major_only });
2025 allocator,2020 fs.atomicSymLink(arena, out_basename, major_only_path) catch |err| {
2026 &[_][]const u8{ out_dir, filename_major_only },2021 return step.fail("unable to symlink {s} -> {s}: {s}", .{
2027 );2022 major_only_path, out_basename, @errorName(err),
2028 fs.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {2023 });
2029 log.err("Unable to symlink {s} -> {s}", .{ major_only_path, out_basename });
2030 return err;
2031 };2024 };
2032 // sym link for libfoo.so to libfoo.so.12025 // sym link for libfoo.so to libfoo.so.1
2033 const name_only_path = try fs.path.join(2026 const name_only_path = try fs.path.join(arena, &.{ out_dir, filename_name_only });
2034 allocator,2027 fs.atomicSymLink(arena, filename_major_only, name_only_path) catch |err| {
2035 &[_][]const u8{ out_dir, filename_name_only },2028 return step.fail("Unable to symlink {s} -> {s}: {s}", .{
2036 );2029 name_only_path, filename_major_only, @errorName(err),
2037 fs.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {2030 });
2038 log.err("Unable to symlink {s} -> {s}", .{ name_only_path, filename_major_only });
2039 return err;
2040 };2031 };
2041}2032}
20422033
lib/std/Build/InstallArtifactStep.zig+1-1
...@@ -83,7 +83,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -83,7 +83,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
83 full_dest_path,83 full_dest_path,
84 );84 );
85 if (self.artifact.isDynamicLibrary() and self.artifact.version != null and self.artifact.target.wantSharedLibSymLinks()) {85 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.?);
87 }87 }
88 if (self.artifact.isDynamicLibrary() and self.artifact.target.isWindows() and self.artifact.emit_implib != .no_emit) {88 if (self.artifact.isDynamicLibrary() and self.artifact.target.isWindows() and self.artifact.emit_implib != .no_emit) {
89 const full_implib_path = dest_builder.getInstallPath(self.dest_dir, self.artifact.out_lib_filename);89 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 @@...@@ -1,5 +1,4 @@
1const std = @import("../std.zig");1const std = @import("../std.zig");
2const log = std.log;
3const fs = std.fs;2const fs = std.fs;
4const Step = std.Build.Step;3const Step = std.Build.Step;
5const RemoveDirStep = @This();4const RemoveDirStep = @This();