Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust-analyzer crashes on this project #4400

Open
VorpalBlade opened this issue Feb 20, 2023 · 6 comments
Open

rust-analyzer crashes on this project #4400

VorpalBlade opened this issue Feb 20, 2023 · 6 comments

Comments

@VorpalBlade
Copy link
Contributor

I cannot get rust-analyzer working in VS Code on this project. It seems to insist on needing selinux/selinux.h, which it doesn't seem that any package on Arch Linux provides (at least according to pacman -F, which searches for which package provides a file).

(Worth noting: I will not be installing SELinux outside the official distribution channels by hand or from the user provided packages on AUR, should that be required.)

I tried adding the following to the workspace settings, to prevent it from activating the selinux feature, but it made no difference:

    "rust-analyzer.cargo.features": [
        "unix"
    ]

The full error I get is:

[ERROR rust_analyzer::lsp_utils] failed to run build scripts:
error: failed to run custom build command for `selinux-sys v0.6.1`

Caused by:
  process didn't exit successfully: `/home/user/src/rust/coreutils/target/debug/build/selinux-sys-954ab2152425c9b2/build-script-build` (exit status: 101)
  --- stdout
  cargo:root=/home/user/src/rust/coreutils/target/debug/build/selinux-sys-b9d426a5e041f579/out
  cargo:rerun-if-env-changed=SELINUX_STATIC_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=SELINUX_STATIC_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_SELINUX_STATIC
  cargo:rerun-if-env-changed=SELINUX_STATIC
  cargo:rerun-if-env-changed=SELINUX_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=SELINUX_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_SELINUX_PATH
  cargo:rerun-if-env-changed=SELINUX_PATH
  cargo:rerun-if-env-changed=SELINUX_INCLUDE_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=SELINUX_INCLUDE_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_SELINUX_INCLUDE_DIR
  cargo:rerun-if-env-changed=SELINUX_INCLUDE_DIR
  cargo:rerun-if-env-changed=SELINUX_LIB_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=SELINUX_LIB_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_SELINUX_LIB_DIR
  cargo:rerun-if-env-changed=SELINUX_LIB_DIR
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_CC
  cargo:rerun-if-env-changed=CC
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  cargo:rerun-if-env-changed=CFLAGS
  OPT_LEVEL = Some("0")
  TARGET = Some("x86_64-unknown-linux-gnu")
  HOST = Some("x86_64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
  CC_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
  CC_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-gnu
  CFLAGS_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
  CFLAGS_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  OPT_LEVEL = Some("0")
  TARGET = Some("x86_64-unknown-linux-gnu")
  HOST = Some("x86_64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_x86_64-unknown-linux-gnu
  CC_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CC_x86_64_unknown_linux_gnu
  CC_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64-unknown-linux-gnu
  CFLAGS_x86_64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CFLAGS_x86_64_unknown_linux_gnu
  CFLAGS_x86_64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")

  --- stderr
  thread 'main' panicked at 'selinux-sys: Failed to find 'selinux/selinux.h': Kind(NotFound)', /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/selinux-sys-0.6.1/build.rs:224:10
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5
     1: core::panicking::panic_fmt
               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14
     2: core::result::unwrap_failed
               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/result.rs:1791:5
     3: core::result::Result<T,E>::expect
               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/result.rs:1070:23
     4: build_script_build::find_and_output_include_dir
               at ./build.rs:223:24
     5: build_script_build::main
               at ./build.rs:25:24
     6: core::ops::function::FnOnce::call_once
               at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/ops/function.rs:507:5
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

So how do I get past this so that rust-analyzer can work and I can contribute to this project?

@tertsdiepraam
Copy link
Member

That's unfortunate indeed. I've removed the selinux headers from my machine and narrowed the problem down to two utils: chcon and runcon. The problem is that for these utils, the selinux dependency is not optional, because that would make them useless, but the entire util is optional. However, because each util is a crate and rust-analyzer tries to analyze all crates in the workspace, rust-analyzer still fails on them. I'll get back to you once I have a solution (and if others have ideas in the meantime I'd love to hear them).

@tertsdiepraam
Copy link
Member

tertsdiepraam commented Feb 20, 2023

It turns out that cargo test --workspace also fails without the headers for similar reasons. Here's a relevant issue: rust-lang/cargo#11526

@tertsdiepraam
Copy link
Member

I couldn't find a way to do this, so I opened an issue at rust-analyzer. Hopefully they can build some solution for this!

@Joining7943
Copy link
Contributor

Maybe I can second a bit. As far as I can remember I solved this issue by installing the libselinux package from AUR, which includes the headers:

$ pacman -Ql libselinux
# ... a lot of stuff
libselinux /usr/include/selinux/
libselinux /usr/include/selinux/avc.h
libselinux /usr/include/selinux/context.h
libselinux /usr/include/selinux/get_context_list.h
libselinux /usr/include/selinux/get_default_type.h
libselinux /usr/include/selinux/label.h
libselinux /usr/include/selinux/restorecon.h
libselinux /usr/include/selinux/selinux.h
libselinux /usr/lib/
libselinux /usr/lib/libselinux.so
libselinux /usr/lib/libselinux.so.1
# ... and more stuff

I haven't tried but you may also get around the missing headers if you download just the headers and install them in /usr/include/selinux so you don't have all the other stuff installed with them.

@Benjscho
Copy link
Contributor

This can be resolved on Ubuntu by installing libselinux1-dev

@wanderinglethe
Copy link
Contributor

Thank you, I had the same problem with CLion (Rust Plugin) even with selinux feature disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants