forked from linera-io/linera-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nix flake and
rustup
toolchain format update (linera-io#1162)
* Add newer-format rust-toolchain with WASM support The newer TOML `rust-toolchain.toml` format allows specifying more things about the compiler. Importantly, it allows us to require support for particular targets, like `wasm32-unknown-unknown`. We keep the legacy `rust-toolchain` file, in the legacy format, as it is depended upon by CI. rust-toolchain documentation: https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file * Add Nix develop environment with Rust and WASM support Reads the Rust toolchain specification from the rustup `rust-toolchain.toml` file, and uses it to provide a development environment for `linera-protocol` with required non-Rust dependencies and standard development tools (`rustfmt`).
- Loading branch information
Showing
8 changed files
with
268 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use flake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ | |
|
||
# VSCode | ||
.vscode | ||
/.direnv |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
{ | ||
inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; | ||
flake-parts.url = "github:hercules-ci/flake-parts"; | ||
systems.url = "github:nix-systems/default"; | ||
rust-overlay.url = "github:oxalica/rust-overlay"; | ||
|
||
# Dev tools | ||
treefmt-nix.url = "github:numtide/treefmt-nix"; | ||
}; | ||
|
||
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } { | ||
systems = import inputs.systems; | ||
imports = [ | ||
inputs.treefmt-nix.flakeModule | ||
]; | ||
perSystem = { config, self', pkgs, lib, system, rust-overlay, ... }: | ||
let | ||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); | ||
nonRustDeps = with pkgs; [ | ||
libclang.lib | ||
libiconv | ||
openssl | ||
protobuf | ||
pkg-config | ||
nodejs | ||
]; | ||
rustToolchain = (pkgs.rust-bin.fromRustupToolchainFile | ||
./rust-toolchain.toml); | ||
rustPlatform = pkgs.makeRustPlatform { | ||
rustc = rustToolchain; | ||
cargo = rustToolchain; | ||
}; | ||
in { | ||
_module.args.pkgs = import inputs.nixpkgs { | ||
inherit system; | ||
overlays = [ (import inputs.rust-overlay) ]; | ||
}; | ||
|
||
# Rust dev environment | ||
devShells.default = pkgs.mkShell { | ||
inputsFrom = [ | ||
config.treefmt.build.devShell | ||
]; | ||
shellHook = '' | ||
# For rust-analyzer 'hover' tooltips to work. | ||
export RUST_SRC_PATH=${rustToolchain.availableComponents.rust-src} | ||
export LIBCLANG_PATH=${pkgs.libclang.lib}/lib | ||
export PATH=$PWD/target/release:~/.cargo/bin:$PATH | ||
''; | ||
buildInputs = nonRustDeps; | ||
nativeBuildInputs = with pkgs; [ | ||
rustToolchain | ||
rust-analyzer | ||
]; | ||
}; | ||
|
||
# Add your auto-formatters here. | ||
# cf. https://numtide.github.io/treefmt/ | ||
treefmt.config = { | ||
projectRootFile = "flake.nix"; | ||
programs = { | ||
nixpkgs-fmt.enable = true; | ||
rustfmt.enable = true; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../rust-toolchain.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[toolchain] | ||
channel = "1.72.0" | ||
components = [ "rustfmt", "rustc-dev", "rust-src" ] | ||
targets = [ "wasm32-unknown-unknown" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default |