Commit 5e945f813c

Jakub Konka <kubkon@jakubkonka.com>
2023-08-14 16:32:41
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`.
1 parent 6a9fd55
Changed files (1)
lib
std
Build
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);
     }
 
     {