Commit ca1c185eb6

dan <2500076+igaryhe@users.noreply.github.com>
2022-10-16 17:37:35
std.zig: search include dir and lib dir from environment variables (#13145)
* minor fix based on feedback from @marler8997 Co-authored-by: dan <i@dan.games>
1 parent c750d95
Changed files (1)
lib
std
zig
lib/std/zig/system/NativePaths.zig
@@ -135,6 +135,32 @@ pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths
         // 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});
+
+        // NOTE: distro like guix doesn't use FHS, so it relies on envorinment
+        // variables (C_INCLUDE_PATH, CPLUS_INCLUDE_PATH and LIBRARY_PATH) to
+        // search for headers and libraries
+        // NOTE: we use os.getenv here since this part won't be executed on
+        // windows, to get rid of unnecessary error handling
+        if (std.os.getenv("C_INCLUDE_PATH")) |c_include_path| {
+            var it = mem.tokenize(u8, c_include_path, ":");
+            while (it.next()) |dir| {
+                try self.addIncludeDir(dir);
+            }
+        }
+
+        if (std.os.getenv("CPLUS_INCLUDE_PATH")) |cplus_include_path| {
+            var it = mem.tokenize(u8, cplus_include_path, ":");
+            while (it.next()) |dir| {
+                try self.addIncludeDir(dir);
+            }
+        }
+
+        if (std.os.getenv("LIBRARY_PATH")) |library_path| {
+            var it = mem.tokenize(u8, library_path, ":");
+            while (it.next()) |dir| {
+                try self.addLibDir(dir);
+            }
+        }
     }
 
     return self;