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..9ba4c02 --- /dev/null +++ b/shell.nix @@ -0,0 +1,60 @@ +# 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 + 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; +}