Content-Security-Policy: default-src 'none'
Content-Type: text/plain; charset=UTF-8
Content-Length: 6162
Content-Disposition: inline; filename="zig-use-system-paths.patch"
Last-Modified: Fri, 01 Nov 2024 09:35:42 GMT
Expires: Mon, 30 Oct 2034 09:35:42 GMT
ETag: "a008beafc2e1a9ccb559916cbc4cbfb07836d75a"

This patch replaces the OS-specific detection mechanism by one that solely
relies on environment variables.  This has the benefit that said environment
variables can be used as search paths in Guix.

diff --git a/lib/std/zig/system/NativePaths.zig b/lib/std/zig/system/NativePaths.zig
index 8e3e46e48..1ed9d3206 100644
--- a/lib/std/zig/system/NativePaths.zig
+++ b/lib/std/zig/system/NativePaths.zig
@@ -26,73 +26,42 @@ pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths
     };
     errdefer self.deinit();
 
-    var is_nix = false;
-    if (process.getEnvVarOwned(allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
-        defer allocator.free(nix_cflags_compile);
-
-        is_nix = true;
-        var it = mem.tokenize(u8, nix_cflags_compile, " ");
+    // TODO: Support cross-compile paths?
+    if (process.getEnvVarOwned(allocator, "C_INCLUDE_PATH")) |c_include_path| {
+        defer allocator.free(c_include_path);
+        var it = mem.tokenize(u8, c_include_path, ":");
         while (true) {
-            const word = it.next() orelse break;
-            if (mem.eql(u8, word, "-isystem")) {
-                const include_path = it.next() orelse {
-                    try self.addWarning("Expected argument after -isystem in NIX_CFLAGS_COMPILE");
-                    break;
-                };
-                try self.addIncludeDir(include_path);
-            } else {
-            </td></tr></table>
<table class='tabs'><tr><td>
<a href='/immutables/?h=v0.5'>summary</a><a href='/immutables/refs/?h=v0.5&amp;id=4d966a1cf9acb21c9f71f2a630da11e4ac848502'>refs</a><a href='/immutables/log/.ci/travis-release.sh?h=v0.5'>log</a><a href='/immutables/tree/.ci/travis-release.sh?h=v0.5&amp;id=4d966a1cf9acb21c9f71f2a630da11e4ac848502'>tree</a><a href='/immutables/commit/.ci/travis-release.sh?h=v0.5&amp;id=4d966a1cf9acb21c9f71f2a630da11e4ac848502'>commit</a><a class='active' href='/immutables/diff/.ci/travis-release.sh?h=v0.5&amp;id=4d966a1cf9acb21c9f71f2a630da11e4ac848502&amp;id2=771954f43c70d3ba6546fafcaec40ba59a7c1d44'>diff</a></td><td class='form'><form class='right' method='get' action='/immutables/log/.ci/travis-release.sh'>
<input type='hidden' name='h' value='v0.5'/><input type='hidden' name='id' value='4d966a1cf9acb21c9f71f2a630da11e4ac848502'/><input type='hidden' name='id2' value='771954f43c70d3ba6546fafcaec40ba59a7c1d44'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/immutables/diff/?h=v0.5&amp;id=4d966a1cf9acb21c9f71f2a630da11e4ac848502&amp;id2=771954f43c70d3ba6546fafcaec40ba59a7c1d44'>root</a>/<a href='/immutables/diff/.ci?h=v0.5&amp;id=4d966a1cf9acb21c9f71f2a630da11e4ac848502&amp;id2=771954f43c70d3ba6546fafcaec40ba59a7c1d44'>.ci</a>/<a href='/immutables/diff/.ci/travis-release.sh?h=v0.5&amp;id=4d966a1cf9acb21c9f71f2a630da11e4ac848502&amp;id2=771954f43c70d3ba6546fafcaec40ba59a7c1d44'>travis-release.sh</a></div><div class='content'><div class='cgit-panel'><b>diff options</b><form method='get'><input type='hidden' name='h' value='v0.5'/><input type='hidden' name='id' value='4d966a1cf9acb21c9f71f2a630da11e4ac848502'/><input type='hidden' name='id2' value='771954f43c70d3ba6546fafcaec40ba59a7c1d44'/><table><tr><td colspan='2'/></tr><tr><td class='label'>context:</td><td class='ctrl'><select name='context' onchange='this.form.submit();'><option value='1'>1</option><option value='2'>2</option><option value='3' selected='selected'>3</option><option value='4'>4</option><option value='5'>5</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option><option value='10'>10</option><option value='15'>15</option><option value='20'>20</option><option value='25'>25</option><option value='30'>30</option><option value='35'>35</option><option value='40'>40</option></select></td></tr><tr><td class='label'>space:</td><td class='ctrl'><select name='ignorews' onchange='this.form.submit();'><option value='0' selected='selected'>include</option><option value='1'>ignore</option></select></td></tr><tr><td class='label'>mode:</td><td class='ctrl'><select name='dt' onchange='this.form.submit();'><option value='0' selected='selected'>unified</option><option value='1'>ssdiff</option><option value='2'>stat only</option></select></td></tr><tr><td/><td class='ctrl'><noscript><input type='submit' value='reload'/></noscript></td></tr></table></form></div><div class='diffstat-header'><a href='/immutables/diff/?h=v0.5&amp;id=4d966a1cf9acb21c9f71f2a630da11e4ac848502&amp;id2=771954f43c70d3ba6546fafcaec40ba59a7c1d44'>Diffstat</a> (limited to '.ci/travis-release.sh')</div><table summary='diffstat' class='diffstat'></table><div class='diffstat-summary'>0 files changed, 0 insertions, 0 deletions</div><table summary='diff' class='diff'><tr><td></td></tr></table></div> <!-- class=content -->
                         <div class=footer>generated by
                             <a href="https://git.zx2c4.com/cgit/about/">
                                 cgit
                             </a>
                         </div>
                        </div> <!-- id=cgit -->
</body>
</html>
nux distro, with zlib installed from apt:
-        // zlib.h is in /usr/include (added above)
-        // libz.so.1 is in /lib/x86_64-linux-gnu (added here)
-        try self.addLibDirFmt("/lib/{s}", .{triple});
+    if (process.getEnvVarOwned(allocator, "DYLD_FRAMEWORK_PATH")) |dyld_framework_path| {
+        defer allocator.free(dyld_framework_path);
+        var it = mem.tokenize(u8, dyld_framework_path, ":");
+        while (true) {
+            const dir = it.next() orelse break;
+            try self.addFrameworkDir(dir);
+        }
+    } else |err| switch (err) {
+        error.InvalidUtf8 => {},
+        error.EnvironmentVariableNotFound => {},
+        error.OutOfMemory => |e| return e,
     }
 
     return self;
