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>
This commit is contained in:
dan 2022-10-16 23:37:35 +08:00 committed by GitHub
parent c750d95417
commit ca1c185eb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;