最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

visual studio code - VSCode Rust-Analyzer: Per Workspace Target? - Stack Overflow

programmeradmin2浏览0评论

I have a situation where different products inside a main workspace require different targets. The simplified situation has a folder structure like this:

The backend needs to be built with the default target. The frontend needs to be built with target wasm32-unknown-unknown. I can build both of these products individually. But I can't figure out how to set rust-analyzer to build different folders in the overall workspace for specific distinct targets. If I set the whole workspace (VSCode rust-analyzer settings.json) target to wasm32-unknown-unknown, RA builds the frontend correctly, but fails on the backend. Leaving the overall setting to "null" builds the backend correctly, but fails on the frontend. I can set up just a workspace for the frontend, and a separate workspace for everything else, but then I end up doing a lot of context switching to go back and forth between products. It very much seems like, and there is documentation suggesting that, it should be possible to have rust-analyzer build different folders for specific targets, e.g. override the default whole-workspace setting for a specific folder. Has anyone actually succeeded at configuring rust-analyzer to do this?

What I've tried:

  • .cargo/config.toml:

    [build]
    target = "wasm32-unknown-unknown"

  • .vscode/settings.json:

    {
       "rust-analyzer.cargo.target": "wasm32-unknown-unknown",
       "rust-analyzer.checkOnSave.target": "wasm32-unknown-unknown",
       "rust-analyzer.checkOnSavemand": "clippy",
       "rust-analyzer.checkOnSave.extraArgs": ["--target", "wasm32-unknown-unknown"]
    }

  • rust-project.json:

    {
        "crates": [
            {
                "root_module": "src/main.rs",
                "edition": "2021",
                "target": "wasm32-unknown-unknown",
                "deps": []
            }
        ]
    }

  • ((EDIT)) Per Chayim Friedman suggestion in the comments, using the linkedProjects settings to point to the right spot:
    "rust-analyzer.linkedProjects": [
        "/absolute/path/to/frontend-wasm32/rust-project.json",
        "/absolute/path/to/backend-default/Cargo.toml",
    ],
  • rust-toolchain.toml:

    [toolchain] 
    channel = "stable" 
    targets = [ "wasm32-unknown-unknown" ]

(If you're curious about the specific build problem, in this case, it's the getrandom library, which is apparently a dependency of several other required elements. It only builds if I add "wasm_js" in to the features in Cargo.toml. But adding the "wasm_js" feature flag causes the error "'wasm_js' backend can only be built for OS-less wasm targets!". And thus, down the above rabbit trail I have wandered.)

发布评论

评论列表(0)

  1. 暂无评论