Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(workspace): Add Nix Shell build environment #112

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix"
}
31 changes: 31 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -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",
]
60 changes: 60 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -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;
}
Loading