authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-14 16:32:41+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-18 08:00:40+02:00
log5e945f813c89b47a92ed0e1b3051ebc38547a790
treee12ee8df6be656c9ae7564683cacaa662ca6eb44
parent6a9fd55809298ca99fcb62df2b52b120b2d8c4a4

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 files changed, 6 insertions(+), 28 deletions(-)

lib/std/Build/Step/Compile.zig+6-28
......@@ -1772,27 +1772,8 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
17721772 try zig_args.append(include_path.getPath(b));
17731773 },
17741774 .path_system => |include_path| {
1775 if (b.sysroot != null) {
1776 try zig_args.append("-iwithsysroot");
1777 } else {
1778 try zig_args.append("-isystem");
1779 }
1780
1781 const resolved_include_path = include_path.getPath(b);
1782
1783 const common_include_path = if (builtin.os.tag == .windows and b.sysroot != null and fs.path.isAbsolute(resolved_include_path)) blk: {
1784 // We need to check for disk designator and strip it out from dir path so
1785 // that zig/clang can concat resolved_include_path with sysroot.
1786 const disk_designator = fs.path.diskDesignatorWindows(resolved_include_path);
1787
1788 if (mem.indexOf(u8, resolved_include_path, disk_designator)) |where| {
1789 break :blk resolved_include_path[where + disk_designator.len ..];
1790 }
1791
1792 break :blk resolved_include_path;
1793 } else resolved_include_path;
1794
1795 try zig_args.append(common_include_path);
1775 try zig_args.append("-isystem");
1776 try zig_args.append(include_path.getPath(b));
17961777 },
17971778 .other_step => |other| {
17981779 if (other.generated_h) |header| {
......@@ -1848,14 +1829,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
18481829 }
18491830
18501831 for (self.framework_dirs.items) |directory_source| {
1851 if (b.sysroot != null) {
1852 try zig_args.append("-iframeworkwithsysroot");
1853 } else {
1854 try zig_args.append("-iframework");
1855 }
1856 try zig_args.append(directory_source.getPath2(b, step));
1832 const path = directory_source.getPath(b);
1833 try zig_args.append("-iframework");
1834 try zig_args.append(path);
18571835 try zig_args.append("-F");
1858 try zig_args.append(directory_source.getPath2(b, step));
1836 try zig_args.append(path);
18591837 }
18601838
18611839 {