support all OSs for the build (although many will not be practical)
This commit is contained in:
parent
4318c14fe3
commit
bfea6e15ef
1 changed files with 25 additions and 27 deletions
18
build.zig
18
build.zig
|
@ -112,21 +112,20 @@ fn configure(compile: *std.Build.Step.Compile, paths: std.zig.system.NativePaths
|
||||||
}
|
}
|
||||||
|
|
||||||
fn checkNix(b: *std.Build, target_query: *std.Target.Query) !std.zig.system.NativePaths {
|
fn checkNix(b: *std.Build, target_query: *std.Target.Query) !std.zig.system.NativePaths {
|
||||||
// All linux-specific stuff should be in here
|
|
||||||
if (@import("builtin").os.tag != .linux or !(target_query.os_tag == null or target_query.os_tag.? == .linux)) {
|
|
||||||
std.log.err("Only linux host and target builds supported right now", .{});
|
|
||||||
return error.NotImplemented;
|
|
||||||
}
|
|
||||||
// Capture the natively detected paths for potential future use
|
|
||||||
const native_result = b.resolveTargetQuery(target_query.*);
|
const native_result = b.resolveTargetQuery(target_query.*);
|
||||||
const paths = try std.zig.system.NativePaths.detect(b.allocator, native_result.result);
|
const paths = try std.zig.system.NativePaths.detect(b.allocator, native_result.result);
|
||||||
const nix_develop_bintools = std.posix.getenv("NIX_BINTOOLS");
|
|
||||||
if (nix_develop_bintools) |bintools| {
|
// If we are not using nix, we can build anywhere provided the system dependencies exist
|
||||||
// std.debug.print("\nDetected nix bintools\n", .{});
|
if (!std.process.hasEnvVarConstant("NIX_BINTOOLS")) return paths;
|
||||||
|
|
||||||
|
// Capture the natively detected paths for potential future use
|
||||||
|
const bintools = try std.process.getEnvVarOwned(b.allocator, "NIX_BINTOOLS");
|
||||||
|
|
||||||
// We'll capture the interpreter used in $NIX_BINTOOLS/bin/size
|
// We'll capture the interpreter used in $NIX_BINTOOLS/bin/size
|
||||||
// We expect this to be a symlink to a native elf executable
|
// We expect this to be a symlink to a native elf executable
|
||||||
// readlink $NIX_BINTOOLS/bin/size
|
// readlink $NIX_BINTOOLS/bin/size
|
||||||
var pathbuf: [std.posix.PATH_MAX]u8 = undefined;
|
var pathbuf: [std.posix.PATH_MAX]u8 = undefined;
|
||||||
|
// posix.readlink is supported on all OSs
|
||||||
const elf_path = try std.posix.readlink(
|
const elf_path = try std.posix.readlink(
|
||||||
try std.fs.path.join(b.allocator, &[_][]const u8{
|
try std.fs.path.join(b.allocator, &[_][]const u8{
|
||||||
bintools,
|
bintools,
|
||||||
|
@ -141,7 +140,6 @@ fn checkNix(b: *std.Build, target_query: *std.Target.Query) !std.zig.system.Nati
|
||||||
// paths. We'll put these back from the values captured above in
|
// paths. We'll put these back from the values captured above in
|
||||||
// our configure function
|
// our configure function
|
||||||
target_query.dynamic_linker = try getDynamicLinker(elf_path);
|
target_query.dynamic_linker = try getDynamicLinker(elf_path);
|
||||||
}
|
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
fn getDynamicLinker(elf_path: []const u8) !std.Target.DynamicLinker {
|
fn getDynamicLinker(elf_path: []const u8) !std.Target.DynamicLinker {
|
||||||
|
|
Loading…
Add table
Reference in a new issue