Rust: Difference between revisions

Artturin (talk | contribs)
FAQ: from a rustup toolchain file
Artturin (talk | contribs)
Custom Rust version: make cross compatible
Line 254: Line 254:
This will have the stable Rust compiler + the official formatter and linter inside the ephemeral shell. It'll also set the RUST_SRC_PATH environment variable to point to the right location, which tools, such as rust-analyzer, require to be set.
This will have the stable Rust compiler + the official formatter and linter inside the ephemeral shell. It'll also set the RUST_SRC_PATH environment variable to point to the right location, which tools, such as rust-analyzer, require to be set.


=== Custom Rust version ===
=== Custom Rust version or targets ===


<syntaxHighlight lang="nix">
<syntaxhighlight lang="nix">
/*
based on
https://discourse.nixos.org/t/how-can-i-set-up-my-rust-programming-environment/4501/9
*/
let
let
  rust_overlay = import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz");
  pkgs = import <nixpkgs> { overlays = [ rust_overlay ]; };
   rustVersion = "latest";
   rustVersion = "latest";
   #rustVersion = "1.62.0";
   #rustVersion = "1.62.0";
   rust = pkgs.rust-bin.stable.${rustVersion}.default.override {
   rust_overlay = import (
    extensions = [
    builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"
      "rust-src" # for rust-analyzer
  );
      "rust-analyzer"
  pkgs = import <nixpkgs> {
    overlays = [
      rust_overlay
      (_: prev: {
        my-rust = prev.rust-bin.stable.${rustVersion}.default.override {
          extensions = [
            "rust-src" # for rust-analyzer
            "rust-analyzer"
          ];
          #targets = [ "arm-unknown-linux-gnueabihf" ];
        };
      })
     ];
     ];
   };
   };
in
in
pkgs.mkShell {
pkgs.callPackage (
  buildInputs = [
  {
     rust
    mkShell,
  ] ++ (with pkgs; [
    hello,
    pkg-config
    my-rust,
     # other dependencies
    pkg-config,
     #gtk3
    openssl,
     #wrapGAppsHook
  }:
  ]);
  mkShell {
  RUST_BACKTRACE = 1;
    # host/target agnostic programs
}
    depsBuildBuild = [
</syntaxHighlight>
      hello
     ];
    # compilers & linkers & dependecy finding programs
    nativeBuildInputs = [
      my-rust
      pkg-config
     ];
     # libraries
     buildInputs = [
      openssl
    ];
    RUST_BACKTRACE = 1;
  }
) { }
 
</syntaxhighlight>


=== VSCode integration ===
=== VSCode integration ===