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),...@@ -103,7 +103,6 @@ link_objects: ArrayList(LinkObject),
103include_dirs: ArrayList(IncludeDir),103include_dirs: ArrayList(IncludeDir),
104c_macros: ArrayList([]const u8),104c_macros: ArrayList([]const u8),
105installed_headers: ArrayList(*Step),105installed_headers: ArrayList(*Step),
106output_dir: ?[]const u8,
107is_linking_libc: bool = false,106is_linking_libc: bool = false,
108is_linking_libcpp: bool = false,107is_linking_libcpp: bool = false,
109vcpkg_bin_path: ?[]const u8 = null,108vcpkg_bin_path: ?[]const u8 = null,
...@@ -386,7 +385,6 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {...@@ -386,7 +385,6 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
386 .disable_sanitize_c = false,385 .disable_sanitize_c = false,
387 .sanitize_thread = false,386 .sanitize_thread = false,
388 .rdynamic = false,387 .rdynamic = false,
389 .output_dir = null,
390 .override_dest_dir = null,388 .override_dest_dir = null,
391 .installed_path = null,389 .installed_path = null,
392 .force_undefined_symbols = StringHashMap(void).init(owner.allocator),390 .force_undefined_symbols = StringHashMap(void).init(owner.allocator),
...@@ -450,19 +448,9 @@ fn computeOutFileNames(self: *CompileStep) void {...@@ -450,19 +448,9 @@ fn computeOutFileNames(self: *CompileStep) void {
450 self.out_lib_filename = self.out_filename;448 self.out_lib_filename = self.out_filename;
451 }449 }
452 }450 }
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 }
458 }451 }
459}452}
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
466pub fn installHeader(cs: *CompileStep, src_path: []const u8, dest_rel_path: []const u8) void {454pub fn installHeader(cs: *CompileStep, src_path: []const u8, dest_rel_path: []const u8) void {
467 const b = cs.step.owner;455 const b = cs.step.owner;
468 const install_file = b.addInstallHeaderFile(src_path, dest_rel_path);456 const install_file = b.addInstallHeaderFile(src_path, dest_rel_path);
...@@ -1931,54 +1919,31 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -1931,54 +1919,31 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1931 },1919 },
1932 else => |e| return e,1920 else => |e| return e,
1933 };1921 };
1934 const build_output_dir = fs.path.dirname(output_bin_path).?;1922 const 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();
19641923
1965 // Update generated files1924 // Update generated files
1966 if (self.output_dir != null) {1925 {
1967 self.output_dirname_source.path = self.output_dir.?;1926 self.output_dirname_source.path = output_dir;
19681927
1969 self.output_path_source.path = b.pathJoin(1928 self.output_path_source.path = b.pathJoin(
1970 &.{ self.output_dir.?, self.out_filename },1929 &.{ output_dir, self.out_filename },
1971 );1930 );
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
1973 if (self.emit_h) {1938 if (self.emit_h) {
1974 self.output_h_path_source.path = b.pathJoin(1939 self.output_h_path_source.path = b.pathJoin(
1975 &.{ self.output_dir.?, self.out_h_filename },1940 &.{ output_dir, self.out_h_filename },
1976 );1941 );
1977 }1942 }
19781943
1979 if (self.target.isWindows() or self.target.isUefi()) {1944 if (self.target.isWindows() or self.target.isUefi()) {
1980 self.output_pdb_path_source.path = b.pathJoin(1945 self.output_pdb_path_source.path = b.pathJoin(
1981 &.{ self.output_dir.?, self.out_pdb_filename },1946 &.{ output_dir, self.out_pdb_filename },
1982 );1947 );
1983 }1948 }
1984 }1949 }