From 43c171bf0872b2e11781d4d65765d9bad701cc44 Mon Sep 17 00:00:00 2001 From: vpochapuis Date: Mon, 22 Apr 2024 23:53:31 +0800 Subject: [PATCH 1/4] feat(workspace): Add Nix Shell build environment --- .vscode/settings.json | 3 +++ rust-toolchain.toml | 31 ++++++++++++++++++++++ shell.nix | 61 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 rust-toolchain.toml create mode 100644 shell.nix diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..786d4d3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix" +} \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..1d8a251 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,31 @@ +#:schema https://json.schemastore.org/rust-toolchain.json + +[toolchain] +channel = "stable" +# https://rust-lang.github.io/rustup/concepts/components.html +components = [ + "rust-src", # for rust-analyzer + "rust-analyzer", + "cargo", + "rustc", + "rustfmt", + "clippy", + "rust-docs", +] +targets = [ + # 64bits Linux Desktop + "x86_64-unknown-linux-gnu", + # Web Assembly + "wasm32-unknown-unknown", + # Android + "aarch64-linux-android", + "armv7-linux-androideabi", + # iOS + "aarch64-apple-ios", + "x86_64-apple-ios", + "aarch64-apple-ios-sim" + # 64bits RPI4 + # "aarch64-unknown-linux-gnu", + # 32bits RPI4 + # "armv7-unknown-linux-gnueabihf", +] diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..bcad910 --- /dev/null +++ b/shell.nix @@ -0,0 +1,61 @@ +# Cf: https://nixos.wiki/wiki/Rust + +# Variable and Imports definition +let + # Import overlay to install specific Rust versions + rust_overlay = import (fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"); + # Import the 23.11 stable Nixpkgs library and apply the rust packages overlay + pkgs = import + (fetchTarball + "https://github.com/nixos/nixpkgs/tarball/nixos-23.11" + ) + { overlays = [ rust_overlay ]; }; + # After importing the nixpkgs and applying the rust overlay we can customize our rust installation + rust = ( + # We use the toolchain and components defines in the `rust-toolchain.toml` file. This file needs to exist. + pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml + ); +in + +# Set all attributes of `pkgs` into our global scope +with pkgs; + +# Create our shell environment +mkShell rec { + # List all dependencies + nativeBuildInputs = with pkgs; [ + cargo-apk + cargo-audit + cargo-binstall + cargo-cache + cargo-make + cargo-nextest + cargo-tarpaulin + cargo-udeps + cargo-xbuild + clang + clippy + lld + nixpkgs-fmt + pkg-config + rust + trunk + typos + ]; + # List all necessary libraries + buildInputs = [ + alsa-lib + libxkbcommon + udev + vulkan-loader + wayland # To use the wayland feature + xorg.libX11 + xorg.libXcursor + xorg.libXi + xorg.libXrandr # To use the x11 feature + ]; + LIBCLANG_PATH = "${libclang.lib}/lib"; + RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library"; + # This is usually not recommended by the Nix community but is necessary for dynamic linking and quick iteration in Bevy builds + LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs; +} From e35e79c2b173008e4c3a74c7308b98a72e4c8e7d Mon Sep 17 00:00:00 2001 From: vpochapuis Date: Tue, 23 Apr 2024 22:46:10 +0800 Subject: [PATCH 2/4] remove conflicting clippy --- shell.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/shell.nix b/shell.nix index bcad910..9ba4c02 100644 --- a/shell.nix +++ b/shell.nix @@ -34,7 +34,6 @@ mkShell rec { cargo-udeps cargo-xbuild clang - clippy lld nixpkgs-fmt pkg-config From 398796067f3576d5a6c63cc594b83269b288e167 Mon Sep 17 00:00:00 2001 From: vpochapuis Date: Tue, 23 Apr 2024 23:45:16 +0800 Subject: [PATCH 3/4] Add nightly toolchain --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 1d8a251..b053cca 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,7 +1,7 @@ #:schema https://json.schemastore.org/rust-toolchain.json [toolchain] -channel = "stable" +channel = "nightly" # https://rust-lang.github.io/rustup/concepts/components.html components = [ "rust-src", # for rust-analyzer From 2fd48b63cec49d4953116a45030e998c7eb037f1 Mon Sep 17 00:00:00 2001 From: vpochapuis Date: Wed, 24 Apr 2024 21:42:48 +0800 Subject: [PATCH 4/4] Revert adding the nightly rust channel and add back stable channel --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index b053cca..1d8a251 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,7 +1,7 @@ #:schema https://json.schemastore.org/rust-toolchain.json [toolchain] -channel = "nightly" +channel = "stable" # https://rust-lang.github.io/rustup/concepts/components.html components = [ "rust-src", # for rust-analyzer