authorgravatar for 2500076+igaryhe@users.noreply.github.comdan <2500076+igaryhe@users.noreply.github.com> 2022-10-16 23:37:35+08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-10-16 11:37:35-04:00
logca1c185eb6164123eed29d3d62441608877ed01a
tree24beb097fea4907acd8aa25fd36ca11c5cce9f5a
parentc750d95417ec94e91a76da769db96f6810900c03
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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 files changed, 26 insertions(+), 0 deletions(-)

lib/std/zig/system/NativePaths.zig+26
......@@ -135,6 +135,32 @@ pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths
135135 // zlib.h is in /usr/include (added above)
136136 // libz.so.1 is in /lib/x86_64-linux-gnu (added here)
137137 try self.addLibDirFmt("/lib/{s}", .{triple});
138
139 // NOTE: distro like guix doesn't use FHS, so it relies on envorinment
140 // variables (C_INCLUDE_PATH, CPLUS_INCLUDE_PATH and LIBRARY_PATH) to
141 // search for headers and libraries
142 // NOTE: we use os.getenv here since this part won't be executed on
143 // windows, to get rid of unnecessary error handling
144 if (std.os.getenv("C_INCLUDE_PATH")) |c_include_path| {
145 var it = mem.tokenize(u8, c_include_path, ":");
146 while (it.next()) |dir| {
147 try self.addIncludeDir(dir);
148 }
149 }
150
151 if (std.os.getenv("CPLUS_INCLUDE_PATH")) |cplus_include_path| {
152 var it = mem.tokenize(u8, cplus_include_path, ":");
153 while (it.next()) |dir| {
154 try self.addIncludeDir(dir);
155 }
156 }
157
158 if (std.os.getenv("LIBRARY_PATH")) |library_path| {
159 var it = mem.tokenize(u8, library_path, ":");
160 while (it.next()) |dir| {
161 try self.addLibDir(dir);
162 }
163 }
138164 }
139165
140166 return self;