Troubleshooting 'proc-macro crate build data is missing dylib path' error

Hello,
I am trying to troubleshoot an error that pops up when trying to use rust-analyzer in VSCode on a project that has a complex build system.
I got pretty far into configuring rust-analyzer for VSCode (and generating configurations). But I'm getting stuck on this error that seems to be related to the defmt crate and its macros:

proc-macro crate build data is missing dylib path

This error diseappiears when I remove ariel-os/defmt from the enabled features in the rust-analyzer config.

I created a repository to recreate the issue here: github.com/nponsard/ariel-os-vscode-config-troubleshooting

Here's how you can replicate the issue:

  • clone the repository
  • open it in VSCode (you can use the devcontainer configuration)
  • install the dependencies ./install-deps.sh
  • restart rust-analyzer
  • open src/main.rs and wait for it to finish scanning the project
  • once rust-analyzer finished scanning, try to jump to the definition of the info!() macro line 8
  • the error should appear and propagate back to main.rs "proc-macro crate build data is missing dylib path"

Do you have any idea how to troubleshoot this further ?

Thanks

You may need to set rust-analyzer.cargo.buildScripts.overrideCommand with the full cargo check command that is needed to build your project with all applicable cargo features. Also add --message-format json to it as rust-analyzer needs to parse json output from cargo.

That seems to be it, thank you very much !
For reference, I added this to .vscode/settings.json:

  "rust-analyzer.cargo.buildScripts.overrideCommand": [
    "cargo",
    "clippy",
    "--config",
    "./build/imports/ariel-os/ariel-os-cargo.toml",
    "--features=ariel-os/semihosting,ariel-os/single-core,ariel-os/executor-interrupt,ariel-os/rtt-target,ariel-os/panic-printing,ariel-os/defmt,ariel-os/debug-console",
    "--message-format=json"
  ],

cargo check should be enough and is likely a bit quicker. This invocation is never used to report errors or warnings, only to build proc macros and run build scripts.

1 Like