rust-lang / rust-lang/rust-analyzer

VSCode: Missing DYLD_FALLBACK_LIBRARY_PATH config for test debugging

Open
#11,426 7 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

rust-analyzer version: fd3942eb6 2022-01-31 stable

rustc version: 1.56.0 (09c42c458 2021-10-18)

Running VSCode on macOS and attempting to debug a unit test through Lens results in a dyld crash; Library not loaded: @rpath/libtest-*dylib. Further investigation shows that setting

[lib]
proc-macro = true

in Cargo.toml always adds dynamic linking to libtest and libstd:

$: otool -l target/debug/deps/ra_repro-31a9e1719a1d9b00

...
Load command 14
          cmd LC_LOAD_DYLIB
      cmdsize 64
         name @rpath/libtest-587b2e5ab4fd237b.dylib (offset 24)
   time stamp 2 Wed Dec 31 16:00:02 1969
      current version 0.0.0
compatibility version 0.0.0
Load command 15
          cmd LC_LOAD_DYLIB
      cmdsize 64
         name @rpath/libstd-034b65e7f48264be.dylib (offset 24)
   time stamp 2 Wed Dec 31 16:00:02 1969
      current version 0.0.0
compatibility version 0.0.0
Load command 16
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libSystem.B.dylib (offset 24)
   time stamp 2 Wed Dec 31 16:00:02 1969
      current version 1311.0.0
compatibility version 1.0.0
...

Encountering the dyld: Library not loaded error implies rust-analyzer does not properly set DYLD_FALLBACK_LIBRARY_PATH when debugging tests. Manually setting the envvar path fixes the problem, either by running:

export DYLD_FALLBACK_LIBRARY_PATH=$DYLD_FALLBACK_LIBRARY_PATH:/Users/[username]/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib

and manually executing the executable in the same terminal session

or by adding the following to VSCode's settings.json:

"rust-analyzer.debug.engineSettings": {
    "lldb": {
        "env": {
            "DYLD_FALLBACK_LIBRARY_PATH": "$DYLD_FALLBACK_LIBRARY_PATH:/Users/[username]/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib"
        }
    }
}

These workarounds should not be necessary and debugging should work without them.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with VSCode Lens unit-test debugging and the LLDB engine settings described in the issue, then reproduce on macOS with a Cargo.toml containing proc-macro = true. Compare debugging with and without DYLD_FALLBACK_LIBRARY_PATH; done means the test launches without the manual environment-variable workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
macos, rust, vscode
Domain
devtools, operating-systems, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.