Skip to content

Commit a2432b6

Browse files
authored
Merge pull request #4735 from ziglang/renameat
zig build system: correctly handle multiple output artifacts
2 parents 0a69a10 + a27a856 commit a2432b6

File tree

12 files changed

+407
-176
lines changed

12 files changed

+407
-176
lines changed

doc/docgen.zig

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10961096
try build_args.append("-lc");
10971097
try out.print(" -lc", .{});
10981098
}
1099+
const target = try std.zig.CrossTarget.parse(.{
1100+
.arch_os_abi = code.target_str orelse "native",
1101+
});
10991102
if (code.target_str) |triple| {
11001103
try build_args.appendSlice(&[_][]const u8{ "-target", triple });
11011104
if (!code.is_inline) {
@@ -1150,7 +1153,15 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11501153
}
11511154
}
11521155

1153-
const path_to_exe = mem.trim(u8, exec_result.stdout, " \r\n");
1156+
const path_to_exe_dir = mem.trim(u8, exec_result.stdout, " \r\n");
1157+
const path_to_exe_basename = try std.fmt.allocPrint(allocator, "{}{}", .{
1158+
code.name,
1159+
target.exeFileExt(),
1160+
});
1161+
const path_to_exe = try fs.path.join(allocator, &[_][]const u8{
1162+
path_to_exe_dir,
1163+
path_to_exe_basename,
1164+
});
11541165
const run_args = &[_][]const u8{path_to_exe};
11551166

11561167
var exited_with_signal = false;
@@ -1486,7 +1497,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14861497
}
14871498

14881499
fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u8) !ChildProcess.ExecResult {
1489-
const result = try ChildProcess.exec(allocator, args, null, env_map, max_doc_file_size);
1500+
const result = try ChildProcess.exec2(.{
1501+
.allocator = allocator,
1502+
.argv = args,
1503+
.env_map = env_map,
1504+
.max_output_bytes = max_doc_file_size,
1505+
});
14901506
switch (result.term) {
14911507
.Exited => |exit_code| {
14921508
if (exit_code != 0) {

lib/std/build.zig

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,17 +2144,22 @@ pub const LibExeObjStep = struct {
21442144
try zig_args.append("--cache");
21452145
try zig_args.append("on");
21462146

2147-
const output_path_nl = try builder.execFromStep(zig_args.toSliceConst(), &self.step);
2148-
const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
2147+
const output_dir_nl = try builder.execFromStep(zig_args.toSliceConst(), &self.step);
2148+
const build_output_dir = mem.trimRight(u8, output_dir_nl, "\r\n");
21492149

21502150
if (self.output_dir) |output_dir| {
2151-
const full_dest = try fs.path.join(builder.allocator, &[_][]const u8{
2152-
output_dir,
2153-
fs.path.basename(output_path),
2154-
});
2155-
try builder.updateFile(output_path, full_dest);
2151+
var src_dir = try std.fs.cwd().openDirTraverse(build_output_dir);
2152+
defer src_dir.close();
2153+
2154+
var dest_dir = try std.fs.cwd().openDirList(output_dir);
2155+
defer dest_dir.close();
2156+
2157+
var it = src_dir.iterate();
2158+
while (try it.next()) |entry| {
2159+
_ = try src_dir.updateFile(entry.name, dest_dir, entry.name, .{});
2160+
}
21562161
} else {
2157-
self.output_dir = fs.path.dirname(output_path).?;
2162+
self.output_dir = build_output_dir;
21582163
}
21592164
}
21602165

lib/std/c.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub extern "c" fn mkdir(path: [*:0]const u8, mode: c_uint) c_int;
106106
pub extern "c" fn mkdirat(dirfd: fd_t, path: [*:0]const u8, mode: u32) c_int;
107107
pub extern "c" fn symlink(existing: [*:0]const u8, new: [*:0]const u8) c_int;
108108
pub extern "c" fn rename(old: [*:0]const u8, new: [*:0]const u8) c_int;
109+
pub extern "c" fn renameat(olddirfd: fd_t, old: [*:0]const u8, newdirfd: fd_t, new: [*:0]const u8) c_int;
109110
pub extern "c" fn chdir(path: [*:0]const u8) c_int;
110111
pub extern "c" fn fchdir(fd: fd_t) c_int;
111112
pub extern "c" fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) c_int;

0 commit comments

Comments
 (0)