jank icon indicating copy to clipboard operation
jank copied to clipboard

Load libraries using relative paths

Open shantanu-sardesai opened this issue 2 months ago • 1 comments

jank health check

─ system ───────────────────────────────────────────────────────────────────────────────────────────
─ ✅ operating system: macos
─ ✅ default triple: arm64-apple-darwin24.6.0

─ jank install ─────────────────────────────────────────────────────────────────────────────────────
─ ✅ jank version: jank-0.1-3986783acadecafbc35d646cc82fe95fcd503164
─ ⚠️ jank assertions are enabled; performance will be impacted
─ ✅ jank resource dir: ../lib/jank/0.1  (not found)
─ ✅ jank resolved resource dir: /Users/shantanusardesai/Desktop/code/projects/jank/compiler+runtime/build/../lib/jank/0.1  (ignored for dev build)
─ ✅ jank user cache dir: /Users/shantanusardesai/.cache/jank/arm64-apple-darwin24.6.0-1c9643717be0b4eb9972385705bbe7c03f18eafd3a5f497b91a737f223d3e1c2  (not found)

─ clang install ────────────────────────────────────────────────────────────────────────────────────
─ ✅ configured clang path: /opt/homebrew/opt/llvm/bin/clang++ (found)
─ ✅ configured clang resource dir: /opt/homebrew/Cellar/llvm/HEAD-17efa57/lib/clang/22 (found)

─ jank runtime ─────────────────────────────────────────────────────────────────────────────────────
─ ✅ jank runtime initialized
─ ✅ jank pch path: /Users/shantanusardesai/.cache/jank/arm64-apple-darwin24.6.0-1c9643717be0b4eb9972385705bbe7c03f18eafd3a5f497b91a737f223d3e1c2 (found)
─ ✅ jank can jit compile c++
─ ✅ jank can jit compile llvm ir
ld: warning: ignoring duplicate libraries: '-lc++'
ld: warning: search path '/Users/shantanusardesai/Desktop/code/projects/jank/compiler+runtime/build/../lib/jank/0.1/lib' not found
ld: warning: search path '/lib' not found
ld: warning: reexported library with install name '/opt/homebrew/opt/llvm/lib/unwind/libunwind.1.dylib' found at '/opt/homebrew/Cellar/llvm/HEAD-17efa57/lib/unwind/libunwind.1.0.dylib' couldn't be matched with any parent library and will be linked directly
─ ✅ jank can aot compile working binaries

Description of the issue with reproduction steps

Currently jank doesn't load libraries based on relative paths and fails with the following error:

$ jank \
  -I"./third-party/pytorch/libtorch_install_cpp20_debug/include" \
  -I"./third-party/pytorch/libtorch_install_cpp20_debug/include/torch/csrc/api/include" \
  -l"./third-party/pytorch/libtorch_install_cpp20_debug/lib/libtorch.dylib" \
  run src/main.jank

─ system/failure ───────────────────────────────────────────────────────────────────────────────────
error: Failed to load dynamic library
       './third-party/pytorch/libtorch_install_cpp20_debug/lib/libtorch.dylib'.

But the same command works with absolute paths:

$ jank \
  -I"$(pwd)/third-party/pytorch/libtorch_install_cpp20_debug/include" \
  -I"$(pwd)/third-party/pytorch/libtorch_install_cpp20_debug/include/torch/csrc/api/include" \
  -l"$(pwd)/third-party/pytorch/libtorch_install_cpp20_debug/lib/libtorch.dylib" \
  run src/main.jank

Stack trace

N/A.

shantanu-sardesai avatar Oct 11 '25 05:10 shantanu-sardesai

This is not a bug, it's a feature request. I have removed it from the alpha release, too. Please don't add things into there unless you're absolutely certain it needs to be a part of the alpha.

Clang doesn't support -l./foo.so and so we don't either. We could, but it introduces potential securities issues with relocating scripts which then pick up different libraries.

❯ ls
foo.cpp  foo.so  libfoo.so  main.cpp  main.o

❯ clang++ main.o -l./libfoo.so
/nix/store/v63bxfiacw082c7ijshf60alvvrpfxsq-binutils-2.44/bin/ld: cannot find -l./libfoo.so: No such file or directory
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

❯ clang++ main.o -L. -lfoo

jeaye avatar Oct 11 '25 18:10 jeaye