diff --git a/.cargo/config_fast_builds b/.cargo/config_fast_builds index eae5a85ea4..b92e77e958 100644 --- a/.cargo/config_fast_builds +++ b/.cargo/config_fast_builds @@ -4,7 +4,7 @@ # If you are using rust stable, remove the "-Zshare-generics=y" below. [target.x86_64-unknown-linux-gnu] -linker = "/usr/bin/clang" +linker = "clang" rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"] # NOTE: you must manually install https://github.com/michaeleisel/zld on mac. you can easily do this with the "brew" package manager: diff --git a/docs/linux_dependencies.md b/docs/linux_dependencies.md index 7ebc1e7ee1..aabc5835b2 100644 --- a/docs/linux_dependencies.md +++ b/docs/linux_dependencies.md @@ -65,88 +65,32 @@ sudo xbps-install -S pkgconf alsa-lib-devel libX11-devel eudev-libudev-devel ## NixOS -Add a `build.rs` file to your project containing: - -```rust -# build.rs - -fn main() { - if cfg!(target_os = "linux") { - println!("cargo:rustc-link-lib=vulkan"); - } -} -``` - -These packages provide the dependencies required to run a bevy project. They can be installed globally or via nix-shell. -Based on your global configuration it also might be necessary to allow unfree packages: - -```bash -nix-shell -p cargo pkgconfig udev alsaLib x11 xorg.libXcursor xorg.libXrandr xorg.libXi vulkan-tools vulkan-headers vulkan-loader vulkan-validation-layers -``` - -Alternatively, you can define `shell.nix` containing: +Add a `shell.nix` file to the root of the project containing: ```nix # shell.nix -{ pkgs ? import { } }: -with pkgs; -mkShell { - buildInputs = [ - cargo - pkgconfig udev alsaLib - x11 xorg.libXcursor xorg.libXrandr xorg.libXi - vulkan-tools vulkan-headers vulkan-loader vulkan-validation-layers +{ pkgs ? import {} }: +with pkgs; mkShell { + nativeBuildInputs = [ + pkgconfig + clang lld # To use lld linker ]; + buildInputs = [ + udev alsaLib vulkan-loader + x11 xorg.libXcursor xorg.libXrandr xorg.libXi # To use x11 feature + libxkbcommon wayland # To use wayland feature + ]; + shellHook = ''export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath [ + udev alsaLib vulkan-loader + libxkbcommon wayland # To use wayland feature + ]}"''; } ``` -And enter it by just running `nix-shell`. +And enter it by just running `nix-shell`. You should be able compile bevy programms using `cargo` within this nix-shell. -You should be able compile bevy programms using `cargo` within this nix-shell. - -### Fast compilation - -According to the Bevy getting started guide (for v0.5), you can enable fast compilation by add a Cargo config file and by adding `lld` and `clang`. As long as you add `clang` and `lld` to your environment, it should mostly work, but you'll still need to modify the Cargo config file so that it doesn't point to `/usr/bin/clang` anymore. - -Working off the above files, let's make the necessary changes. - -For `.cargo/config.toml`, change the path to the linker from `/usr/bin/clang` to `clang`: - -``` diff - [target.x86_64-unknown-linux-gnu] -- linker = "/usr/bin/clang" -+ linker = "clang" - rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"] -``` - -In `shell.nix`, add `lld` and `clang`: - -``` diff - buildInputs = [ - cargo - pkgconfig udev alsaLib lutris - x11 xorg.libXcursor xorg.libXrandr xorg.libXi - vulkan-tools vulkan-headers vulkan-loader vulkan-validation-layers -+ clang lld - ]; -``` - -### Building apps and using the GPU - -If you run into issues with building basic apps or activating the GPU ('thread 'main' panicked at 'Unable to find a GPU!'), then you may need to update your environment's `LD_LIBRARY_PATH`. To solve issues relating to missing `libudev.so.1` files, `alsa` drivers, and being unable to find a GPU, try updating the environment variable in your `shell.nix` by creating a `shellHook`: - -``` diff - { pkgs ? import { } }: - with pkgs; - mkShell { -+ shellHook = ''export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath [ -+ pkgs.alsaLib -+ pkgs.udev -+ pkgs.vulkan-loader -+ ]}"''; - buildInputs = [ -``` +Note that this template doesn't add Rust to the environment because there are many ways to do it, each with its pros and cons. For example, to use stable Rust from nixpkgs you can add `cargo` to `nativeBuildInputs`. ## Opensuse Tumbleweed