feat(templates/bevy): add support for darwin, and use rust-analyzer-nightly for better type inference

This commit is contained in:
Ryan Yin
2024-09-22 23:56:20 +08:00
parent b82395d603
commit f85982c8ea

View File

@@ -4,20 +4,22 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
rust-overlay = { fenix = {
url = "github:oxalica/rust-overlay"; url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
}; };
outputs = { outputs = {
nixpkgs, nixpkgs,
rust-overlay, fenix,
... ...
}: let }: let
systems = [ systems = [
"x86_64-linux" "x86_64-linux"
"aarch64-linux" "aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
]; ];
# Helper function to generate a set of attributes for each system # Helper function to generate a set of attributes for each system
forAllSystems = func: (nixpkgs.lib.genAttrs systems func); forAllSystems = func: (nixpkgs.lib.genAttrs systems func);
@@ -25,29 +27,78 @@
devShells = forAllSystems (system: let devShells = forAllSystems (system: let
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
overlays = [(import rust-overlay)]; overlays = [fenix.overlays.default];
}; };
lib = pkgs.lib; lib = pkgs.lib;
in { in {
default = pkgs.mkShell rec { default = pkgs.mkShell rec {
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
pkg-config pkg-config
clang
# lld is much faster at linking than the default Rust linker
lld
]; ];
buildInputs = with pkgs; [ buildInputs = with pkgs;
udev [
alsa-lib # rust toolchain
vulkan-loader (pkgs.fenix.complete.withComponents [
xorg.libX11 "cargo"
xorg.libXcursor "clippy"
xorg.libXi "rust-src"
xorg.libXrandr # To use the x11 feature "rustc"
libxkbcommon "rustfmt"
wayland # To use the wayland feature ])
rust-analyzer-nightly
# rust toolchain ]
rust-analyzer # https://github.com/bevyengine/bevy/blob/v0.14.2/docs/linux_dependencies.md#nix
]; ++ (lib.optionals pkgs.stdenv.isLinux [
udev
alsa-lib
vulkan-loader
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libXrandr # To use the x11 feature
libxkbcommon
wayland # To use the wayland feature
])
# https://discourse.nixos.org/t/develop-shell-environment-setup-for-macos/11399
# https://github.com/NixOS/nixpkgs/blob/nixos-unstable-small/pkgs/os-specific/darwin/apple-sdk/frameworks.nix
++ (pkgs.lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
libiconv
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.ApplicationServices
darwin.apple_sdk.frameworks.CoreVideo
darwin.apple_sdk.frameworks.Carbon
darwin.apple_sdk.frameworks.AppKit
]);
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs; LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
COREAUDIO_SDK_PATH =
pkgs.lib.optionals
pkgs.stdenv.isDarwin
# The coreaudio-sys crate is configured to look for things in whatever the
# output of `xcrun --sdk macosx --show-sdk-path` is. However, this does not
# always contain the right frameworks, and it uses system versions instead of
# what we control via Nix. Instead of having to run a lot of extra scripts
# to set our systems up to build, we can just create a SDK directory with
# the same layout as the `MacOSX{version}.sdk` that XCode produces.
(pkgs.symlinkJoin {
name = "sdk";
paths = with pkgs.darwin.apple_sdk.frameworks; [
AudioToolbox
AudioUnit
CoreAudio
CoreAudioTypes
CoreFoundation
CoreMIDI
OpenAL
];
postBuild = ''
mkdir $out/System
mv $out/Library $out/System
'';
});
}; };
}); });
}; };