Skip to content

Commit

Permalink
search include dir and lib dir from environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
igaryhe committed Oct 13, 2022
1 parent 0b47e69 commit 48d0fe6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions lib/std/zig/system/NativePaths.zig
Expand Up @@ -135,6 +135,48 @@ 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
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 dir = it.next() orelse break;
try self.addIncludeDir(dir);
}
} else |err| switch (err) {
error.InvalidUtf8 => {},
error.EnvironmentVariableNotFound => {},
error.OutOfMemory => |e| return e,
}

if (process.getEnvVarOwned(allocator, "CPLUS_INCLUDE_PATH")) |cplus_include_path| {
defer allocator.free(cplus_include_path);
var it = mem.tokenize(u8, cplus_include_path, ":");
while (true) {
const dir = it.next() orelse break;
try self.addIncludeDir(dir);
}
} else |err| switch (err) {
error.InvalidUtf8 => {},
error.EnvironmentVariableNotFound => {},
error.OutOfMemory => |e| return e,
}

if (process.getEnvVarOwned(allocator, "LIBRARY_PATH")) |library_path| {
defer allocator.free(library_path);
var it = mem.tokenize(u8, library_path, ":");
while (true) {
const dir = it.next() orelse break;
try self.addLibDir(dir);
}
} else |err| switch (err) {
error.InvalidUtf8 => {},
error.EnvironmentVariableNotFound => {},
error.OutOfMemory => |e| return e,
}
}

return self;
Expand Down

0 comments on commit 48d0fe6

Please sign in to comment.