How to avoid "E0463: can't find crate for `test` can't find crate" when building for thumbv7m-none-eabi?
Asked Answered
H

5

13

RLS is giving the following error message when working on a project with an ARM target:

E0463: can't find crate for test can't find crate

Reproduction:

cargo new --bin app
cd app
mkdir .cargo
echo '[build]' > .cargo/config
echo 'target = "thumbv7m-none-eabi"' >> .cargo/config
echo '#![no_std]' > src/main.rs
rls --cli

I believe this is because there is no test crate for the ARM target.

Is there a way to avoid this error?

There are several other SO posts on E0463 but appears those are configuration errors. The above is purely an RLS question. It's causing my editor to display errors and not do code complete, etc.

Hymenopterous answered 14/1, 2021 at 15:58 Comment(7)
Issues with running RLS in no_std projects is what pushed me to switch over to Rust Analyzer. I also want to note that RLS isn't being actively developed and is poised to be superceded by RA.Cuda
@IvanC I am getting the same error with rust-analyzer.Hymenopterous
I checked and I also have to add [unstable] build-std = ["core"] to .cargo/config.Cuda
@IvanC Does this mean you have to use unstable?Hymenopterous
In general you have to use nightly if you want to cross-compile.Cuda
Unfortunately I'm getting this with rust-analyzer despite using the build-std = ["core"] as well as nightly, and in fact despite including the checkOnSave.allTargets=false setting. Sigh.Riebling
Update: it was failing because I wasn't modifying languages.toml properly. Adding a .helix/languages.toml in my project root, with a [language.config] section inside [[language]] name="rust" with just that setting fixed it.Riebling
V
2

If you include:

{
  "rust-analyzer.cargo.target": "<your target architecture>",
  "rust-analyzer.check.allTargets": false,
}

and you are still getting the can't find crate for 'test' error on vscode, see if you have the Cargo extension by panicbit installed (https://marketplace.visualstudio.com/items?itemName=panicbit.cargo). It also uses cargo check on save without regards to the target architecture.

Ventriloquize answered 1/8, 2023 at 15:0 Comment(0)
L
1

This is because of Cargo trying to build test&benchs for your binary targets when you pass --all-targets(which is done by default by rust-analyzer)

To solve this, you can try rewrote your main target, disable it's tests by adding this to Cargo.toml:

[[bin]]
name = "your_crate_name"
path = "src/main.rs"
test = false
doctest = false
bench = false
Lowercase answered 3/5, 2024 at 10:39 Comment(1)
Thanks for your contribution! You may consider extending your answer by the information, on where the configuration snippet you provided should be placed, e.g. add a fragment like: "... by adding the following block to the <path/filename> file:" to the last sentence before the code block.Schoonmaker
R
0

Found this in a github issue:

In the file .vscode/settings.json:

{
    "rust-analyzer.check.allTargets": false,
    "rust-analyzer.check.extraArgs": [
        "--target",
        "<your target architecture>"
    ]
}

Replace <your target architecture> with the right target.

Re answered 8/1, 2023 at 11:35 Comment(1)
I'm not sure when this changed but VS Code now seems to expect check instead of checkOnSaveNatishanative
J
0

For Helix it is

# .helix/languages.toml
[[language]]
name = "rust"

[language-server.rust-analyzer.config.check]
targets = ["x86_64-unknown-linux-gnu"]
#allTargets = false
Javelin answered 11/4, 2024 at 10:41 Comment(0)
P
0

For VS Code workspaces

I you're wondering why the "rust-analyzer.*" properties in your .vscode folder are all grayed out even when you have the extension installed chances are you're using a workspace with multiple rust projects open, in which case you want to change the workspace settings under: File -> Preferences -> Settings -> Workspace tab.

Polyphemus answered 24/4, 2024 at 9:17 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.