Configure the runfiles environment globally at context start to ensure Bazel-built binaries locate their runfiles correctly.
This commit is contained in:
parent
57130577e9
commit
74e90855ca
@ -4,6 +4,8 @@ const std = @import("std");
|
|||||||
const asynk = @import("async");
|
const asynk = @import("async");
|
||||||
const mlir = @import("mlir");
|
const mlir = @import("mlir");
|
||||||
const pjrt = @import("pjrt");
|
const pjrt = @import("pjrt");
|
||||||
|
const c = @import("c");
|
||||||
|
const runfiles = @import("runfiles");
|
||||||
|
|
||||||
const platform = @import("platform.zig");
|
const platform = @import("platform.zig");
|
||||||
const Target = @import("platform.zig").Target;
|
const Target = @import("platform.zig").Target;
|
||||||
@ -40,10 +42,38 @@ pub const Context = struct {
|
|||||||
}
|
}
|
||||||
}.call);
|
}.call);
|
||||||
|
|
||||||
|
var runfiles_once = std.once(struct {
|
||||||
|
fn call_() !void {
|
||||||
|
if (std.process.hasEnvVarConstant("RUNFILES_MANIFEST_FILE") or std.process.hasEnvVarConstant("RUNFILES_DIR")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var arena = std.heap.ArenaAllocator.init(std.heap.c_allocator);
|
||||||
|
const allocator = arena.allocator();
|
||||||
|
defer arena.deinit();
|
||||||
|
|
||||||
|
var envMap = std.process.EnvMap.init(allocator);
|
||||||
|
var r = (try runfiles.Runfiles.create(.{ .allocator = allocator })) orelse return;
|
||||||
|
try r.environment(&envMap);
|
||||||
|
|
||||||
|
var it = envMap.iterator();
|
||||||
|
while (it.next()) |entry| {
|
||||||
|
const keyZ = try allocator.dupeZ(u8, entry.key_ptr.*);
|
||||||
|
const valueZ = try allocator.dupeZ(u8, entry.value_ptr.*);
|
||||||
|
_ = c.setenv(keyZ.ptr, valueZ.ptr, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn call() void {
|
||||||
|
call_() catch @panic("Unable to init runfiles env");
|
||||||
|
}
|
||||||
|
}.call);
|
||||||
|
|
||||||
platforms: PlatformsMap,
|
platforms: PlatformsMap,
|
||||||
|
|
||||||
/// Creates a ZML Context and returns it.
|
/// Creates a ZML Context and returns it.
|
||||||
pub fn init() !Context {
|
pub fn init() !Context {
|
||||||
|
Context.runfiles_once.call();
|
||||||
Context.apis_once.call();
|
Context.apis_once.call();
|
||||||
Context.mlir_once.call();
|
Context.mlir_once.call();
|
||||||
|
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user