Skip to content

rust-analyzer doesn't work on bootstrap anymore #101070

Description

@tmandry

#97513 took bootstrap out of the cargo workspace, meaning that rust-analyzer can't see it anymore. I haven't yet found a config that makes rust-analyzer see it, short of opening bootstrap in a separate window.

This is annoying since I rust-analyzer particularly useful when working on bootstrap, but at least opening another window works for now.

cc @jyn514

Activity

  1. added
    T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
    C-bugCategory: This is a bug.
    on Aug 27, 2022
  2. changed the title [-]rust-analyzer doesn't work on bootstrap[/-] [+]rust-analyzer doesn't work on bootstrap anymore[/+] on Aug 27, 2022
  3. RalfJung commented on Aug 28, 2022

    @RalfJung
    Member

    Also see rust-lang/rust-analyzer#10793 -- this is somewhat blocked on RA getting better support for projects that use custom build scripts such as ./x.py.

  4. jyn514 commented on Aug 28, 2022

    @jyn514
    Member

    yeah, you can set linked-workspaces to have it use both, but then you get a bunch of spurious errors when you open the project

  5. jyn514 commented on Sep 15, 2022

    @jyn514
    Member
  6. Veykril commented on Oct 23, 2022

    @Veykril
    Member

    Build scripts now work properly when rust-analyzer.linkedProjects is set if you follow the updated dev-guide instructions rust-lang/rustc-dev-guide#1487 ... is what I would like to say but there is one small problem:
    x.py check --json-output does not emit build data for dependencies of bootstrap for example, so if you set linkedProjects to the bootstrap toml, r-a will currently fail to find the proc-macro dylibs for serde, because bootstrap uses a different serde version than the top level workspace has, and only the top level used one is reported (if I upgrade the serde version of bootstrap to the top-level one r-a finds the proc-macro dylibs for serde).
    Looks like I either fixed it, or its a spurious problem

  7. jyn514 commented on Nov 5, 2022

    @jyn514
    Member

    @Veykril I can't get this working. I have in .vscode/settings.json:

        "rust-analyzer.checkOnSave.enable": true,
        "rust-analyzer.checkOnSave.overrideCommand": [
            "python3",
            "x.py",
            "check",
            "--json-output"
        ],
        "rust-analyzer.rustfmt.overrideCommand": [
            "./build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt",
            "--edition=2021"
        ],
        "rust-analyzer.cargo.buildScripts.enable": true,
        "rust-analyzer.cargo.buildScripts.invocationLocation": "root",
        "rust-analyzer.cargo.buildScripts.invocationStrategy": "once",
        "rust-analyzer.cargo.buildScripts.overrideCommand": [
            "python3",
            "x.py",
            "check",
            "--json-output"
        ],
        "rust-analyzer.rustc.source": "./Cargo.toml",
        "rust-analyzer.cargo.sysroot": "./build/x86_64-unknown-linux-gnu/stage0-sysroot",
        "rust-analyzer.procMacro.enable": true,
        "rust-analyzer.linkedProjects": ["Cargo.toml", "src/bootstrap/Cargo.toml"],

    which fails to find x.py:

    [ERROR flycheck] Flycheck failed to run the following command: "python3" "x.py" "check" "--json-output"
    [ERROR rust_analyzer::lsp_utils] cargo check failed
    
    Cargo watcher failed, the command produced no valid metadata (exit code: ExitStatus(unix_wait_status(512))):
    python3: can't open file 'x.py': [Errno 2] No such file or directory
    

    If I disable checkOnSave it does seem to work ok, though. Maybe the options you added need to be global instead of specific to build scripts?

  8. Veykril commented on Nov 5, 2022

    @Veykril
    Member

    You'll need to set

        "rust-analyzer.cargo.checkOnSave.invocationLocation": "root",
        "rust-analyzer.cargo.checkOnSave.invocationStrategy": "once",

    The reason I didn't add those to the dev guide is that you won't get diagnostics for linked projects anyways until x.py changes the paths in its output to be relative to the project root or rust-lang/cargo#11007 is fixed (assuming x.py is using that flag). Otherwise r-a will not be able to deduce the correct files for the diagnostics as they are relative to the Cargo.toml of the linked projects without knowing which diagnostics come from what linked project.

  9. jyn514 commented on Feb 3, 2023

    @jyn514
    Member

    You'll need to set

        "rust-analyzer.cargo.checkOnSave.invocationLocation": "root",
        "rust-analyzer.cargo.checkOnSave.invocationStrategy": "once",

    The reason I didn't add those to the dev guide is that you won't get diagnostics for linked projects anyways until x.py changes the paths in its output to be relative to the project root or rust-lang/cargo#11007 is fixed (assuming x.py is using that flag). Otherwise r-a will not be able to deduce the correct files for the diagnostics as they are relative to the Cargo.toml of the linked projects without knowing which diagnostics come from what linked project.

    I think we should add them anyway - even if the diagnostics are missing, having go-to-definition available is still extremely useful.

  10. jyn514 commented on Feb 3, 2023

    @jyn514
    Member

    Mentoring instructions: add "rust-analyzer.linkedProjects": ["src/bootstrap/Cargo.toml", "Cargo.toml"], to this section of the dev-guide.

  11. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    on Feb 3, 2023
  12. zephaniahong commented on Feb 9, 2023

    @zephaniahong
    Contributor

    Happy to help add this to the dev-guide but I noticed that the settings.json portion in the dev guide is no longer there. Is it due to #107547 ?

  13. zephaniahong commented on Feb 9, 2023

    @zephaniahong
    Contributor

    @rustbot claim

  14. jyn514 commented on Feb 9, 2023

    @jyn514
    Member

    Oh, sorry - this was fixed by #107757

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions