Jump to content

Rust: Difference between revisions

565 bytes removed ,  29 April
Remove Rust Nightlies section. This section had no information that wasn't found on the rest of the page (only having two bullet points referring to other sections of the page). Instead, modify the page to elaborate more in the respective sections.
(fix links)
(Remove Rust Nightlies section. This section had no information that wasn't found on the rest of the page (only having two bullet points referring to other sections of the page). Instead, modify the page to elaborate more in the respective sections.)
 
(One intermediate revision by the same user not shown)
Line 76: Line 76:


A minimal example of the <code>rust-toolchain.toml</code>:
A minimal example of the <code>rust-toolchain.toml</code>:
<syntaxHighlight lang="toml">
<syntaxhighlight lang="toml">
[toolchain]
[toolchain]
channel = "stable"
channel = "stable" # This can also be "nightly" if you want a nightly rust
</syntaxHighlight>
                  # or nightly-20XX-XX-XX for a specific nightly.
</syntaxhighlight>


The important part is that this also works with complex setups using bindgen and precompiled C libraries. To add a new C library in the search path of bindgen and rustc edit the variables <code>BINDGEN_EXTRA_CLANG_ARGS</code> and <code>RUSTFLAGS</code>
The important part is that this also works with complex setups using bindgen and precompiled C libraries. To add a new C library in the search path of bindgen and rustc edit the variables <code>BINDGEN_EXTRA_CLANG_ARGS</code> and <code>RUSTFLAGS</code>
Line 99: Line 100:


# https://github.com/cachix/devenv/blob/main/examples/rust/devenv.nix and <code>devenv shell</code>
# https://github.com/cachix/devenv/blob/main/examples/rust/devenv.nix and <code>devenv shell</code>
== Rust Nightlies ==
# Use one of the overlays above,
# Or, use rustup


== Developing Rust projects using Nix ==
== Developing Rust projects using Nix ==
Line 250: Line 246:


You can use the [https://marketplace.visualstudio.com/items?itemName=arrterian.nix-env-selector arrterian.nix-env-selector] extension to enable your nix-shell inside VSCode and have these settings picked up by other extensions.
You can use the [https://marketplace.visualstudio.com/items?itemName=arrterian.nix-env-selector arrterian.nix-env-selector] extension to enable your nix-shell inside VSCode and have these settings picked up by other extensions.
=== Neovim Completion ===
Racer completion can be configured using the following snippet:
<syntaxHighlight lang="nix">
(neovim.override {
  configure = {
    customRC = ''
      if filereadable($HOME . "/.vimrc")
        source ~/.vimrc
      endif
      let $RUST_SRC_PATH = '${stdenv.mkDerivation {
        inherit (rustc) src;
        inherit (rustc.src) name;
        phases = ["unpackPhase" "installPhase"];
        installPhase = ''cp -r library $out'';
      }}'
    '';
    packages.nixbundle.start = with vimPlugins; [
      nvim-completion-manager
      nvim-cm-racer
    ];
  };
})
</syntaxHighlight>


== FAQ ==
== FAQ ==
Line 304: Line 274:
=== Building with a different Rust version than the one in Nixpkgs ===
=== Building with a different Rust version than the one in Nixpkgs ===


The following uses the [https://github.com/nix-community/fenix fenix] overlay and <code>makeRustPlatform</code> to build a crate with Rust nightly:
The following uses the [https://github.com/nix-community/fenix fenix] overlay and <code>makeRustPlatform</code> to build a crate with Rust Nightly:


<syntaxHighlight lang="nix">
<syntaxHighlight lang="nix">
3

edits