Skip to content

Instantly share code, notes, and snippets.

@f0i
Last active September 21, 2020 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save f0i/2bbf5d05730a092449e8504bd163c236 to your computer and use it in GitHub Desktop.
Save f0i/2bbf5d05730a092449e8504bd163c236 to your computer and use it in GitHub Desktop.
$ nix-shell shell.nix
$ git clone https://github.com/gfx-rs/wgpu-rs
$ cd wgpu-rs
$ cargo run --example cube
Finished dev [unoptimized + debuginfo] target(s) in 0.07s
Running `target/debug/examples/cube`
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', examples/cube/../framework.rs:117:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
// full file: https://github.com/gfx-rs/wgpu-rs/blob/master/examples/framework.rs#L117
log::info!("Initializing the surface...");
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
let (size, surface) = unsafe {
let size = window.inner_size();
let surface = instance.create_surface(&window);
(size, surface)
};
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::Default,
compatible_surface: Some(&surface),
})
.await
.unwrap();
let optional_features = E::optional_features();
let required_features = E::required_features();
let adapter_features = adapter.features();
assert!(
adapter_features.contains(required_features),
"Adapter does not support required features for this example: {:?}",
required_features - adapter_features
);
let
# Look here for information about how pin version of nixpkgs
# → https://nixos.wiki/wiki/FAQ/Pinning_Nixpkgs
pinnedPkgs = import (builtins.fetchGit {
name = "nixpkgs-20.03";
url = "https://github.com/nixos/nixpkgs/";
ref = "refs/heads/release-20.03";
}) { };
# This allows overriding pkgs by passing `--arg pkgs ...`
in { pkgs ? pinnedPkgs }:
let
isOsX = builtins.currentSystem == "x86_64-darwin";
darwin-frameworks =
if isOsX then
with pkgs.darwin.apple_sdk.frameworks; [
AppKit
CoreFoundation
CoreServices
CoreVideo
Foundation
Metal
Security
]
else
[ ];
llvm = pkgs.llvm_10;
inputs = with pkgs; [
rustup
cargo
llvm
# libraries for llvm
libffi
libxml2
zlib
pkg-config x11 libffi libxml2 rlwrap cargo xorg.libXcursor wlroots libinput xorg.libXrandr
xorg.libXi
vulkan-tools
vulkan-loader
vulkan-headers
];
in pkgs.mkShell {
buildInputs = inputs ++ darwin-frameworks;
LLVM_SYS_100_PREFIX = "${llvm}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment