From 5e945f813c89b47a92ed0e1b3051ebc38547a790 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Mon, 14 Aug 2023 16:32:41 +0200 Subject: [PATCH] build: do not emit -iwithsysroot/-iframeworkwithsysroot implicitly Prior to this change, we would unconditionally emit any system include path/framework path as `-iwithsysroot`/`-iframeworkwithsysroot` if the sysroot was set which can lead to unexpected build failures. Now, calls to `b.addSystemIncludePath` and `b.addFrameworkPath` will always emit search paths as `-isystem`/`-iframework`. As a result, it is now up to the user to correctly concat the search paths with the sysroot when and where desired. If there is a need for emitting `-iwithsysroot`/`-iframeworkwithsysroot` I would advise adding explicit hooks such as `addSystemIncludePathWithSysroot` and `addFrameworkPathWithSysroot`. --- lib/std/Build/Step/Compile.zig | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 681343faaee0856530b40926b091b87226081f23..5a376f17d4d16ae3a4060ee1ff1c26f2b3b14f59 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -1772,27 +1772,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { try zig_args.append(include_path.getPath(b)); }, .path_system => |include_path| { - if (b.sysroot != null) { - try zig_args.append("-iwithsysroot"); - } else { - try zig_args.append("-isystem"); - } - - const resolved_include_path = include_path.getPath(b); - - const common_include_path = if (builtin.os.tag == .windows and b.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); + try zig_args.append("-isystem"); + try zig_args.append(include_path.getPath(b)); }, .other_step => |other| { if (other.generated_h) |header| { @@ -1848,14 +1829,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { } for (self.framework_dirs.items) |directory_source| { - if (b.sysroot != null) { - try zig_args.append("-iframeworkwithsysroot"); - } else { - try zig_args.append("-iframework"); - } - try zig_args.append(directory_source.getPath2(b, step)); + const path = directory_source.getPath(b); + try zig_args.append("-iframework"); + try zig_args.append(path); try zig_args.append("-F"); - try zig_args.append(directory_source.getPath2(b, step)); + try zig_args.append(path); } { -- 2.54.0