mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
Update std.zig.system.NativePaths.detect to support some more flags on NixOS like environment.
Basically detect `-idirafter` flag in `NIX_CFLAGS_COMPILE` and treat it like `-isystem`, also detect `NIX_CFLAGS_LINK` environment variable and treat it like the `NIX_LDFLAGS` .
Reference:
74eefb4210/pkgs/build-support/build-fhsenv-chroot/env.nix (L83)
This commit is contained in:
parent
51bb2b3d2d
commit
8382ee40be
1 changed files with 35 additions and 3 deletions
|
|
@ -21,9 +21,9 @@ pub fn detect(arena: Allocator, native_target: *const std.Target) !NativePaths {
|
||||||
var it = mem.tokenizeScalar(u8, nix_cflags_compile, ' ');
|
var it = mem.tokenizeScalar(u8, nix_cflags_compile, ' ');
|
||||||
while (true) {
|
while (true) {
|
||||||
const word = it.next() orelse break;
|
const word = it.next() orelse break;
|
||||||
if (mem.eql(u8, word, "-isystem")) {
|
if (mem.eql(u8, word, "-isystem") or mem.eql(u8, word, "-idirafter")) {
|
||||||
const include_path = it.next() orelse {
|
const include_path = it.next() orelse {
|
||||||
try self.addWarning("Expected argument after -isystem in NIX_CFLAGS_COMPILE");
|
try self.addWarningFmt("Expected argument after {s} in NIX_CFLAGS_COMPILE", .{word});
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
try self.addIncludeDir(include_path);
|
try self.addIncludeDir(include_path);
|
||||||
|
|
@ -65,7 +65,7 @@ pub fn detect(arena: Allocator, native_target: *const std.Target) !NativePaths {
|
||||||
const lib_path = word[2..];
|
const lib_path = word[2..];
|
||||||
try self.addLibDir(lib_path);
|
try self.addLibDir(lib_path);
|
||||||
try self.addRPath(lib_path);
|
try self.addRPath(lib_path);
|
||||||
} else if (mem.startsWith(u8, word, "-l")) {
|
} else if (mem.startsWith(u8, word, "-l") or mem.startsWith(u8, word, "-static")) {
|
||||||
// Ignore this argument.
|
// Ignore this argument.
|
||||||
} else {
|
} else {
|
||||||
try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS: {s}", .{word});
|
try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS: {s}", .{word});
|
||||||
|
|
@ -77,6 +77,38 @@ pub fn detect(arena: Allocator, native_target: *const std.Target) !NativePaths {
|
||||||
error.EnvironmentVariableNotFound => {},
|
error.EnvironmentVariableNotFound => {},
|
||||||
error.OutOfMemory => |e| return e,
|
error.OutOfMemory => |e| return e,
|
||||||
}
|
}
|
||||||
|
if (process.getEnvVarOwned(arena, "NIX_CFLAGS_LINK")) |nix_cflags_link| {
|
||||||
|
is_nix = true;
|
||||||
|
var it = mem.tokenizeScalar(u8, nix_cflags_link, ' ');
|
||||||
|
while (true) {
|
||||||
|
const word = it.next() orelse break;
|
||||||
|
if (mem.eql(u8, word, "-rpath")) {
|
||||||
|
const rpath = it.next() orelse {
|
||||||
|
try self.addWarning("Expected argument after -rpath in NIX_CFLAGS_LINK");
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
try self.addRPath(rpath);
|
||||||
|
} else if (mem.eql(u8, word, "-L") or mem.eql(u8, word, "-l")) {
|
||||||
|
_ = it.next() orelse {
|
||||||
|
try self.addWarning("Expected argument after -L or -l in NIX_CFLAGS_LINK");
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
} else if (mem.startsWith(u8, word, "-L")) {
|
||||||
|
const lib_path = word[2..];
|
||||||
|
try self.addLibDir(lib_path);
|
||||||
|
try self.addRPath(lib_path);
|
||||||
|
} else if (mem.startsWith(u8, word, "-l") or mem.startsWith(u8, word, "-static")) {
|
||||||
|
// Ignore this argument.
|
||||||
|
} else {
|
||||||
|
try self.addWarningFmt("Unrecognized C flag from NIX_CFLAGS_LINK: {s}", .{word});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else |err| switch (err) {
|
||||||
|
error.InvalidWtf8 => unreachable,
|
||||||
|
error.EnvironmentVariableNotFound => {},
|
||||||
|
error.OutOfMemory => |e| return e,
|
||||||
|
}
|
||||||
if (is_nix) {
|
if (is_nix) {
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue