rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.19k stars 1.59k forks source link

`excludeDirs` still reports `build.rs` failures #14081

Open mkeeter opened 1 year ago

mkeeter commented 1 year ago

I've got a dummy workspace project with two crates in it: foo and bar.

foo will panic in the build.rs (for the purposes of showing this issue), so I've added it to rust-analyzer.files.excludeDirs.

However, it's still throwing an error in my text editor:

LSP[rust_analyzer] failed to run build scripts

In the LSP logs, I see that rust-analyzer has correctly deserialized the excludeDirs configuration:

[DEBUG rust_analyzer::config] deserialized config data: ConfigData {
    assist_emitMustUse: false,
    assist_expressionFillDefault: Todo,
    cachePriming_enable: true,
    ... many lines skipped
    files_excludeDirs: [
        "foo",
    ],
    files_watcher: Client,
    ... many lines skipped

Despite this configuration, it then proceeds to try building proc-macros for foo:

Detailed logs ``` [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 272325875 } handle_event(FetchWorkspace(Report("metadata"))) [INFO rust_analyzer::reload] did fetch workspaces [Ok(Cargo { root: Some("rust-analyzer-test"), n_packages: 2, sysroot: true, n_rustc_compiler_crates: 0, n_rustc_cfg: 76, n_cfg_overrides: 1, toolchain: Some(Version { major: 1, minor: 65, patch: 0 }), data_layout: Ok("e-m:o-i64:64-i128:128-n32:64-S128") })] [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 551157750 } handle_event(FetchWorkspace(End([Ok(Cargo { root: Some("rust-analyzer-test"), n_packages: 2, sysroot: true, n_rustc_compiler_crates: 0, n_rustc_cfg: 76, n_cfg_overrides: 1, toolchain: Some(Version { major: 1, minor: 65, patch: 0 }), data_layout: Ok("e-m:o-i64:64-i128:128-n32:64-S128") })]))) [INFO rust_analyzer::reload] will switch workspaces cause=fetched workspace [DEBUG rust_analyzer::reload] abandon build scripts for workspaces [INFO rust_analyzer::reload] Spawning proc-macro servers [INFO rust_analyzer::reload] Using proc-macro server at /Users/mjk/.rustup/toolchains/stable-aarch64-apple-darwin/libexec/rust-analyzer-proc-macro-srv args=[] [INFO rust_analyzer::reload] did switch workspaces [INFO rust_analyzer::reload] will fetch workspaces cause=workspace vfs file change: /Users/mjk/rust-analyzer-test/foo/build.rs [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 552229500 } handle_event(Progress { n_total: 3, n_done: 0, config_version: 1 }) [INFO rust_analyzer::main_loop] task queue len: 1 [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 552298791 } handle_event(FetchWorkspace(Begin)) [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 552492750 } handle_event(Response(Response { id: RequestId(I32(3)), result: None, error: None })) [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 552645333 } handle_event(Response(Response { id: RequestId(I32(4)), result: None, error: None })) [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 554032375 } handle_event(Loaded { n_files: 1 }) [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 554750583 } handle_event(Loaded { n_files: 2 }) [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 579256625 } handle_event(Loaded { n_files: 1256 }) [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 651314875 } handle_event(FetchWorkspace(Report("metadata"))) [INFO rust_analyzer::reload] did fetch workspaces [Ok(Cargo { root: Some("rust-analyzer-test"), n_packages: 2, sysroot: true, n_rustc_compiler_crates: 0, n_rustc_cfg: 76, n_cfg_overrides: 1, toolchain: Some(Version { major: 1, minor: 65, patch: 0 }), data_layout: Ok("e-m:o-i64:64-i128:128-n32:64-S128") })] [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 865308958 } handle_event(FetchWorkspace(End([Ok(Cargo { root: Some("rust-analyzer-test"), n_packages: 2, sysroot: true, n_rustc_compiler_crates: 0, n_rustc_cfg: 76, n_cfg_overrides: 1, toolchain: Some(Version { major: 1, minor: 65, patch: 0 }), data_layout: Ok("e-m:o-i64:64-i128:128-n32:64-S128") })]))) [INFO rust_analyzer::reload] will switch workspaces cause=fetched workspace [INFO rust_analyzer::reload] build scripts do not match the version of the active workspace [INFO rust_analyzer::reload] will fetch workspaces cause=workspace vfs file change: /Users/mjk/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/profiler_builtins/build.rs [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 865449875 } handle_event(FetchWorkspace(Begin)) [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 865618541 } handle_event(Response(Response { id: RequestId(I32(5)), result: None, error: None })) [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394562, tv_nsec: 965401916 } handle_event(FetchWorkspace(Report("metadata"))) [INFO rust_analyzer::reload] did fetch workspaces [Ok(Cargo { root: Some("rust-analyzer-test"), n_packages: 2, sysroot: true, n_rustc_compiler_crates: 0, n_rustc_cfg: 76, n_cfg_overrides: 1, toolchain: Some(Version { major: 1, minor: 65, patch: 0 }), data_layout: Ok("e-m:o-i64:64-i128:128-n32:64-S128") })] [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394563, tv_nsec: 186971625 } handle_event(FetchWorkspace(End([Ok(Cargo { root: Some("rust-analyzer-test"), n_packages: 2, sysroot: true, n_rustc_compiler_crates: 0, n_rustc_cfg: 76, n_cfg_overrides: 1, toolchain: Some(Version { major: 1, minor: 65, patch: 0 }), data_layout: Ok("e-m:o-i64:64-i128:128-n32:64-S128") })]))) [INFO rust_analyzer::reload] will switch workspaces cause=fetched workspace [INFO rust_analyzer::reload] build scripts do not match the version of the active workspace [INFO rust_analyzer::reload] will fetch build data cause=workspace updated [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394563, tv_nsec: 187122166 } handle_event(FetchBuildData(Begin)) [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394563, tv_nsec: 187231333 } handle_event(Response(Response { id: RequestId(I32(6)), result: None, error: None })) [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394563, tv_nsec: 371738666 } handle_event(FetchBuildData(Report("building proc-macros: foo"))) [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394563, tv_nsec: 542921958 } handle_event(FetchBuildData(Report("building proc-macros: foo"))) [DEBUG rust_analyzer::main_loop] Instant { tv_sec: 394563, tv_nsec: 605121583 } handle_event(FetchBuildData(End(([Cargo { root: Some(\"rust-analyzer-test\"), n_packages: 2, sysroot: true, n_rustc_compiler_crates: 0, n_rustc_cfg: 76, n_cfg_overrides: 1, toolchain: Some(Version { major: 1, minor: 65, patch: 0 }), data_layout: Ok(\"e-m:o-i64:64-i128:128-n32:64-S128\") }], [Ok(WorkspaceBuildScripts { outputs: ArenaMap { v: [Some(BuildScriptOutput { cfgs: [], envs: [], out_dir: None, proc_macro_dylib_path: None }), Some(BuildScriptOutput { cfgs: [], envs: [], out_dir: None, proc_macro_dylib_path: None })], _ty: PhantomData> }, error: Some(\"error: failed to run custom build command for `foo v0.1.0 (/Users/mjk/rust-analyzer-test/foo)`\ \ Caused by:\ process didn't exit successfully: `/Users/mjk/rust-analyzer-test/target/debug/build/foo-248b943ec114af19/build-script-build` (exit status: 101)\ --- stderr\ thread 'main' panicked at 'can't build foo', foo/build.rs:2:5\ stack backtrace:\ 0: rust_begin_unwind\ at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5\ 1: core::panicking::panic_fmt\ at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14\ 2: build_script_build::main\ at ./build.rs:2:5\ 3: core::ops::function::FnOnce::call_once\ at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:248:5\ note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.\ \") })])))) [INFO rust_analyzer::reload] will switch workspaces cause=fetched build data [ERROR rust_analyzer::lsp_utils] failed to run build scripts: error: failed to run custom build command for `foo v0.1.0 (/Users/mjk/rust-analyzer-test/foo)` Caused by: process didn't exit successfully: `/Users/mjk/rust-analyzer-test/target/debug/build/foo-248b943ec114af19/build-script-build` (exit status: 101) --- stderr thread 'main' panicked at 'can't build foo', foo/build.rs:2:5 stack backtrace: 0: rust_begin_unwind at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5 1: core::panicking::panic_fmt at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14 2: build_script_build::main at ./build.rs:2:5 3: core::ops::function::FnOnce::call_once at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:248:5 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ```

(the full raw logs are here, but I reformatted them for ease of reading)

This is also the case if I set procMacro.enable = false, oddly enough – I see the same thing in the logs:

handle_event(FetchBuildData(Report("building proc-macros: foo")))

then the same panic as before.


I'm running in Neovim with rust-tools, but could try to reproduce in VSCode if that would be helpful!

rust-analyzer version: rust-analyzer 0.0.0 (f1b257f4e 2023-01-27)

rustc version: rustc 1.65.0 (897e37553 2022-11-02)

relevant settings:

{
  ["rust-analyzer"] = {
    files = {
      excludeDirs = { "foo" }
    }
  }
}
Veykril commented 1 year ago

you'll have to disable both proc-macros and build scripts for it skip running build scripts ( one requires the other currently).

I am not sure how well we can tackle this, since we run things on the top level virtual workspace here, so we might not be able to honor exclude dir in terms of cargo commands