Merge pull request #9734 from Andoryuuta/macho-zld-win-filepath

link/include: fix invalid file path concatenation when cross-compiling for Windows -> Mac
This commit is contained in:
Jakub Konka 2021-09-13 09:04:11 +02:00 committed by GitHub
commit 50e34a063c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -2549,7 +2549,22 @@ pub const LibExeObjStep = struct {
} else {
try zig_args.append("-isystem");
}
try zig_args.append(self.builder.pathFromRoot(include_path));
const resolved_include_path = self.builder.pathFromRoot(include_path);
const common_include_path = if (std.Target.current.os.tag == .windows and builder.sysroot != null and fs.path.isAbsolute(resolved_include_path)) blk: {
// We need to check for disk designator and strip it out from dir path so
// that zig/clang can concat resolved_include_path with sysroot.
const disk_designator = fs.path.diskDesignatorWindows(resolved_include_path);
if (mem.indexOf(u8, resolved_include_path, disk_designator)) |where| {
break :blk resolved_include_path[where + disk_designator.len ..];
}
break :blk resolved_include_path;
} else resolved_include_path;
try zig_args.append(common_include_path);
},
.other_step => |other| if (other.emit_h) {
const h_path = other.getOutputHSource().getPath(self.builder);

View File

@ -493,7 +493,19 @@ fn resolveSearchDir(
if (fs.path.isAbsolute(dir)) {
if (syslibroot) |root| {
const full_path = try fs.path.join(arena, &[_][]const u8{ root, dir });
const common_dir = if (std.Target.current.os.tag == .windows) blk: {
// We need to check for disk designator and strip it out from dir path so
// that we can concat dir with syslibroot.
// TODO we should backport this mechanism to 'MachO.Dylib.parseDependentLibs()'
const disk_designator = fs.path.diskDesignatorWindows(dir);
if (mem.indexOf(u8, dir, disk_designator)) |where| {
break :blk dir[where + disk_designator.len ..];
}
break :blk dir;
} else dir;
const full_path = try fs.path.join(arena, &[_][]const u8{ root, common_dir });
try candidates.append(full_path);
}
}