zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit ca1c185eb6164123eed29d3d62441608877ed01a (tree)
parent c750d95417ec94e91a76da769db96f6810900c03
Author: dan <2500076+igaryhe@users.noreply.github.com>
Date:   Sun, 16 Oct 2022 23:37:35 +0800

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>
Diffstat:
Mlib/std/zig/system/NativePaths.zig | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/lib/std/zig/system/NativePaths.zig b/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;