Skip to content

Working with Nixos #26

@StealthyKamereon

Description

@StealthyKamereon

Hello,

I would like to make a plugin on Nixos but I'm facing problems.
I get the following error: unresolved extern crate on:

extern crate rustc_driver;
extern crate rustc_interface;
extern crate rustc_middle;
extern crate rustc_session;

However, if I cargo check everything compiles fine.

I have poured tens of hours trying to understand what's wrong. I would greatly appreciate if someone see's something I'm missing.

I hope this could serve as a documentation for other people using Nixos.

My environment is the following

shell.nix

{ nixpkgs ? import <nixpkgs> { }}:

let
  rustOverlay = builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz";
  pinnedPkgs = nixpkgs.fetchFromGitHub {
    owner  = "NixOS";
    repo   = "nixpkgs";
    rev    = "b3fcfcfabd01b947a1e4f36622bbffa3985bdac6";
    sha256 = "0va68ddkrqb6j349rsbkjhdq7m243kg9njcqhnx9p2sbrcl2g5l8";
  };
  pkgs = import pinnedPkgs {
    overlays = [ (import rustOverlay) ];
  };
  rust_pkg = pkgs.rust-bin.nightly."2024-05-20".default.override {
    extensions = ["rust-src" "rustc" "rustc-dev" "llvm-tools" "rust-analyzer" "cargo"];
  };
in
  pkgs.mkShell {
    buildInputs = with pkgs; [
      (
        rust_pkg
      )
      openssl
      pkg-config
      eza
      fd
    ];

    RUST_BACKTRACE = 1;
    RUST_SRC_PATH = "${rust_pkg}/lib/rustlib/src/rust/library";
  }

This allows to build all the required components.

Code

I have cloned the crates/rustc_plugin/examples/print-all-items example.
I made some tweaks that I feel relevant.
In Cargo.toml:

[dependencies]
- rustc_plugin = { path = "../.." }
+ rustc_plugin = "=0.10.0-nightly-2024-05-20"
env_logger = "0.10"

I also set the following setting in rust-analyzer's config:

rust_analyzer = {
  cargo = {
    features = "all",
  },
  rustc = { source = "discover" },
},

Thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions