Skip to content

Commit a92750f

Browse files
committed
Fix linux LD_LIBRARY_PATH
1 parent a09d8e1 commit a92750f

2 files changed

Lines changed: 52 additions & 11 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ jobs:
2525
#TODO test on linux! we are currently broken due to rpath issues
2626
# https://github.com/pkgxdev/pkgm/pull/30#issuecomment-2678957666
2727
test:
28-
runs-on: macos-latest
28+
strategy:
29+
matrix:
30+
os:
31+
- macos-latest
32+
- ubuntu-latest
33+
runs-on: ${{ matrix.os }}
2934
steps:
3035
- uses: actions/checkout@v4
3136
- uses: pkgxdev/setup@v3

pkgm.ts

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ async function install(args: string[], basePath: string) {
130130
const pkgx_dir = Deno.env.get("PKGX_DIR") || `${Deno.env.get("HOME")}/.pkgx`;
131131
const needs_sudo = Deno.uid() != 0 && basePath === "/usr/local";
132132

133-
const runtime_env = expand_runtime_env(json.runtime_env, basePath);
133+
const runtime_env = expand_runtime_env(json, basePath);
134134

135135
args = [
136136
"pkgx",
@@ -142,7 +142,7 @@ async function install(args: string[], basePath: string) {
142142
self,
143143
"sudo-install",
144144
pkgx_dir,
145-
runtime_env,
145+
JSON.stringify(runtime_env),
146146
basePath,
147147
...pkg_prefixes,
148148
];
@@ -248,7 +248,18 @@ async function mirror_directory(dst: string, src: string, prefix: string) {
248248
}
249249

250250
async function symlink(src: string, dst: string) {
251-
for (const base of ["bin", "sbin", "share", "lib", "libexec", "var", "etc"]) {
251+
for (
252+
const base of [
253+
"bin",
254+
"sbin",
255+
"share",
256+
"lib",
257+
"libexec",
258+
"var",
259+
"etc",
260+
"ssl",
261+
]
262+
) {
252263
const foo = join(src, base);
253264
if (existsSync(foo)) {
254265
await processEntry(foo, join(dst, base));
@@ -311,19 +322,44 @@ async function create_v_symlinks(prefix: string) {
311322
}
312323

313324
function expand_runtime_env(
314-
runtime_env: Record<string, Record<string, string>>,
325+
// deno-lint-ignore no-explicit-any
326+
json: Record<string, any>,
315327
basePath: string,
316328
) {
317-
const expanded: Record<string, Record<string, string>> = {};
318-
for (const [project, env] of Object.entries(runtime_env)) {
319-
const expanded_env: Record<string, string> = {};
329+
const runtime_env = json.runtime_env as Record<string, string>;
330+
331+
//FIXME this combines all runtime env which is strictly overkill
332+
// for transitive deps that may not need it
333+
334+
const expanded: Record<string, Set<string>> = {};
335+
for (const [_project, env] of Object.entries(runtime_env)) {
320336
for (const [key, value] of Object.entries(env)) {
337+
//TODO expand all moustaches
321338
const new_value = value.replaceAll(/\$?{{.*prefix}}/g, basePath);
322-
expanded_env[key] = new_value;
339+
expanded[key] ??= new Set<string>();
340+
expanded[key].add(new_value);
323341
}
324-
expanded[project] = expanded_env;
325342
}
326-
return JSON.stringify(expanded);
343+
344+
// fix https://github.com/pkgxdev/pkgm/pull/30#issuecomment-2678957666
345+
if (Deno.build.os == "linux") {
346+
expanded["LD_LIBRARY_PATH"] ??= new Set<string>();
347+
expanded["LD_LIBRARY_PATH"].add(`${basePath}/lib`);
348+
}
349+
350+
const rv: Record<string, string> = {};
351+
for (const [key, set] of Object.entries(expanded)) {
352+
rv[key] = [...set].join(":");
353+
}
354+
355+
// DUMB but easiest way to fix a bug
356+
// deno-lint-ignore no-explicit-any
357+
const rv2: Record<string, any> = {};
358+
for (const { project } of json.pkgs as Record<string, string>[]) {
359+
rv2[project] = rv;
360+
}
361+
362+
return rv2;
327363
}
328364

329365
function symlink_with_overwrite(src: string, dst: string) {

0 commit comments

Comments
 (0)