Skip to content

Commit 19ef5b0

Browse files
committed
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 parent 2f84df4 commit 19ef5b0

File tree

1 file changed

+12
-47
lines changed

1 file changed

+12
-47
lines changed

lib/std/Build/CompileStep.zig

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ link_objects: ArrayList(LinkObject),
103103
include_dirs: ArrayList(IncludeDir),
104104
c_macros: ArrayList([]const u8),
105105
installed_headers: ArrayList(*Step),
106-
output_dir: ?[]const u8,
107106
is_linking_libc: bool = false,
108107
is_linking_libcpp: bool = false,
109108
vcpkg_bin_path: ?[]const u8 = null,
@@ -387,7 +386,6 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
387386
.disable_sanitize_c = false,
388387
.sanitize_thread = false,
389388
.rdynamic = false,
390-
.output_dir = null,
391389
.override_dest_dir = null,
392390
.installed_path = null,
393391
.install_step = null,
@@ -452,19 +450,9 @@ fn computeOutFileNames(self: *CompileStep) void {
452450
self.out_lib_filename = self.out_filename;
453451
}
454452
}
455-
if (self.output_dir != null) {
456-
self.output_lib_path_source.path = b.pathJoin(
457-
&.{ self.output_dir.?, self.out_lib_filename },
458-
);
459-
}
460453
}
461454
}
462455

463-
pub fn setOutputDir(self: *CompileStep, dir: []const u8) void {
464-
const b = self.step.owner;
465-
self.output_dir = b.dupePath(dir);
466-
}
467-
468456
pub fn install(self: *CompileStep) void {
469457
const b = self.step.owner;
470458
b.installArtifact(self);
@@ -1937,54 +1925,31 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
19371925
},
19381926
else => |e| return e,
19391927
};
1940-
const build_output_dir = fs.path.dirname(output_bin_path).?;
1941-
1942-
if (self.output_dir) |output_dir| {
1943-
var src_dir = try fs.cwd().openIterableDir(build_output_dir, .{});
1944-
defer src_dir.close();
1945-
1946-
// Create the output directory if it doesn't exist.
1947-
try fs.cwd().makePath(output_dir);
1948-
1949-
var dest_dir = try fs.cwd().openDir(output_dir, .{});
1950-
defer dest_dir.close();
1951-
1952-
var it = src_dir.iterate();
1953-
while (try it.next()) |entry| {
1954-
// The compiler can put these files into the same directory, but we don't
1955-
// want to copy them over.
1956-
if (mem.eql(u8, entry.name, "llvm-ar.id") or
1957-
mem.eql(u8, entry.name, "libs.txt") or
1958-
mem.eql(u8, entry.name, "builtin.zig") or
1959-
mem.eql(u8, entry.name, "zld.id") or
1960-
mem.eql(u8, entry.name, "lld.id")) continue;
1961-
1962-
_ = try src_dir.dir.updateFile(entry.name, dest_dir, entry.name, .{});
1963-
}
1964-
} else {
1965-
self.output_dir = build_output_dir;
1966-
}
1967-
1968-
// This will ensure all output filenames will now have the output_dir available!
1969-
self.computeOutFileNames();
1928+
const output_dir = fs.path.dirname(output_bin_path).?;
19701929

19711930
// Update generated files
1972-
if (self.output_dir != null) {
1973-
self.output_dirname_source.path = self.output_dir.?;
1931+
{
1932+
self.output_dirname_source.path = output_dir;
19741933

19751934
self.output_path_source.path = b.pathJoin(
1976-
&.{ self.output_dir.?, self.out_filename },
1935+
&.{ output_dir, self.out_filename },
19771936
);
19781937

1938+
if (self.kind == .lib) {
1939+
self.output_lib_path_source.path = b.pathJoin(
1940+
&.{ output_dir, self.out_lib_filename },
1941+
);
1942+
}
1943+
19791944
if (self.emit_h) {
19801945
self.output_h_path_source.path = b.pathJoin(
1981-
&.{ self.output_dir.?, self.out_h_filename },
1946+
&.{ output_dir, self.out_h_filename },
19821947
);
19831948
}
19841949

19851950
if (self.target.isWindows() or self.target.isUefi()) {
19861951
self.output_pdb_path_source.path = b.pathJoin(
1987-
&.{ self.output_dir.?, self.out_pdb_filename },
1952+
&.{ output_dir, self.out_pdb_filename },
19881953
);
19891954
}
19901955
}

0 commit comments

Comments
 (0)