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

[Merged by Bors] - Documentation: simplify NixOS dependencies #3527

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion .cargo/config_fast_builds
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
88 changes: 16 additions & 72 deletions docs/linux_dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,88 +63,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 <nixpkgs> { } }:
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 <nixpkgs> {} }:
with pkgs; mkShell {
nativeBuildInputs = [
pkgconfig
clang lld # To use lld linker
];
}
```

And enter it by just running `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
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
]}"'';
}
```

### 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`:
And enter it by just running `nix-shell`. You should be able compile bevy programms using `cargo` within this nix-shell.

``` diff
{ pkgs ? import <nixpkgs> { } }:
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

Expand Down