authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-10 08:51:18-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-11 08:41:51-07:00
log5a8b1bde5b3ce2628a8e490c3cef9fcc95f94ab5
tree07af03158be5141b44d03bd69e2abc0f560f3edb
parentc96cb98ad13d0ebb4593cd0a29159b64b6c7621b

std.Build.CompileStep: remove output_dir

Build scripts must instead use the FileSource abstraction rather than telling the compiler directly where to output files. closes #14951

1 files changed, 12 insertions(+), 47 deletions(-)

lib/std/Build/CompileStep.zig+12-47
......@@ -103,7 +103,6 @@ link_objects: ArrayList(LinkObject),
103103include_dirs: ArrayList(IncludeDir),
104104c_macros: ArrayList([]const u8),
105105installed_headers: ArrayList(*Step),
106output_dir: ?[]const u8,
107106is_linking_libc: bool = false,
108107is_linking_libcpp: bool = false,
109108vcpkg_bin_path: ?[]const u8 = null,
......@@ -386,7 +385,6 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
386385 .disable_sanitize_c = false,
387386 .sanitize_thread = false,
388387 .rdynamic = false,
389 .output_dir = null,
390388 .override_dest_dir = null,
391389 .installed_path = null,
392390 .force_undefined_symbols = StringHashMap(void).init(owner.allocator),
......@@ -450,19 +448,9 @@ fn computeOutFileNames(self: *CompileStep) void {
450448 self.out_lib_filename = self.out_filename;
451449 }
452450 }
453 if (self.output_dir != null) {
454 self.output_lib_path_source.path = b.pathJoin(
455 &.{ self.output_dir.?, self.out_lib_filename },
456 );
457 }
458451 }
459452}
460453
461pub fn setOutputDir(self: *CompileStep, dir: []const u8) void {
462 const b = self.step.owner;
463 self.output_dir = b.dupePath(dir);
464}
465
466454pub fn installHeader(cs: *CompileStep, src_path: []const u8, dest_rel_path: []const u8) void {
467455 const b = cs.step.owner;
468456 const install_file = b.addInstallHeaderFile(src_path, dest_rel_path);
......@@ -1931,54 +1919,31 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
19311919 },
19321920 else => |e| return e,
19331921 };
1934 const build_output_dir = fs.path.dirname(output_bin_path).?;
1935
1936 if (self.output_dir) |output_dir| {
1937 var src_dir = try fs.cwd().openIterableDir(build_output_dir, .{});
1938 defer src_dir.close();
1939
1940 // Create the output directory if it doesn't exist.
1941 try fs.cwd().makePath(output_dir);
1942
1943 var dest_dir = try fs.cwd().openDir(output_dir, .{});
1944 defer dest_dir.close();
1945
1946 var it = src_dir.iterate();
1947 while (try it.next()) |entry| {
1948 // The compiler can put these files into the same directory, but we don't
1949 // want to copy them over.
1950 if (mem.eql(u8, entry.name, "llvm-ar.id") or
1951 mem.eql(u8, entry.name, "libs.txt") or
1952 mem.eql(u8, entry.name, "builtin.zig") or
1953 mem.eql(u8, entry.name, "zld.id") or
1954 mem.eql(u8, entry.name, "lld.id")) continue;
1955
1956 _ = try src_dir.dir.updateFile(entry.name, dest_dir, entry.name, .{});
1957 }
1958 } else {
1959 self.output_dir = build_output_dir;
1960 }
1961
1962 // This will ensure all output filenames will now have the output_dir available!
1963 self.computeOutFileNames();
1922 const output_dir = fs.path.dirname(output_bin_path).?;
19641923
19651924 // Update generated files
1966 if (self.output_dir != null) {
1967 self.output_dirname_source.path = self.output_dir.?;
1925 {
1926 self.output_dirname_source.path = output_dir;
19681927
19691928 self.output_path_source.path = b.pathJoin(
1970 &.{ self.output_dir.?, self.out_filename },
1929 &.{ output_dir, self.out_filename },
19711930 );
19721931
1932 if (self.kind == .lib) {
1933 self.output_lib_path_source.path = b.pathJoin(
1934 &.{ output_dir, self.out_lib_filename },
1935 );
1936 }
1937
19731938 if (self.emit_h) {
19741939 self.output_h_path_source.path = b.pathJoin(
1975 &.{ self.output_dir.?, self.out_h_filename },
1940 &.{ output_dir, self.out_h_filename },
19761941 );
19771942 }
19781943
19791944 if (self.target.isWindows() or self.target.isUefi()) {
19801945 self.output_pdb_path_source.path = b.pathJoin(
1981 &.{ self.output_dir.?, self.out_pdb_filename },
1946 &.{ output_dir, self.out_pdb_filename },
19821947 );
19831948 }
19841949 }