Skip to content

Commit

Permalink
Make winit truly optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Aug 18, 2019
1 parent a47ff09 commit f30cb20
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ before_install:

script:
- cargo test
- (cd wgpu-native && cargo check --features local,glutin)
# TODO: Temporarily only test building the gl backend, properly test when it is usable from C
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then cd wgpu-native && cargo check --features winit-vulkan; fi
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then cargo check --release; fi
- if [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then cargo +nightly install cbindgen; fi
- if [[ $TRAVIS_RUST_VERSION == "nightly" ]] && [[ $TRAVIS_OS_NAME == "windows" ]]; then
Expand All @@ -72,5 +75,3 @@ script:
make example-compute example-triangle VERBOSE=1;
fi
- if [[ $TRAVIS_RUST_VERSION == "nightly" ]] && [[ $TRAVIS_OS_NAME != "windows" ]]; then make VERBOSE=1; fi
# TODO: Temporarily only test building the gl backend, properly test when it is usable from C
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then cd wgpu-native && cargo build --features local,gfx-backend-gl; fi
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions wgpu-native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ default = []
local = []
remote = ["serde"]
metal-auto-capture = ["gfx-backend-metal/auto-capture"]
window-winit = ["winit", "gfx-backend-empty/winit"]
winit-empty = ["winit", "gfx-backend-empty/winit"]
winit-vulkan = ["winit", "gfx-backend-vulkan/winit"]
winit-dx12 = ["winit", "gfx-backend-dx12/winit"]
winit-dx11 = ["winit", "gfx-backend-dx11/winit"]
winit-metal = ["winit", "gfx-backend-metal/winit"]
glutin = ["winit", "gfx-backend-gl/glutin"]

[dependencies]
arrayvec = "0.4"
Expand All @@ -29,12 +34,12 @@ copyless = "0.1"
lazy_static = "1.1.0"
log = "0.4"
hal = { package = "gfx-hal", version = "0.3.0" }
gfx-backend-empty = { version = "0.3.0", features = ["winit"] }
gfx-backend-vulkan = { version = "0.3.0", features = ["winit", "x11"], optional = true }
gfx-backend-dx11 = { version = "0.3.0", features = ["winit"], optional = true }
gfx-backend-dx12 = { version = "0.3.0", features = ["winit"], optional = true }
gfx-backend-metal = { version = "0.3.0", features = ["winit"], optional = true }
gfx-backend-gl = { version = "0.3.0", features = ["winit", "glutin"], optional = true }
gfx-backend-empty = { version = "0.3.0" }
gfx-backend-vulkan = { version = "0.3.0", features = ["x11"], optional = true }
gfx-backend-dx12 = { version = "0.3.0", optional = true }
gfx-backend-dx11 = { version = "0.3.0", optional = true }
gfx-backend-metal = { version = "0.3.0", optional = true }
gfx-backend-gl = { version = "0.3.0", optional = true }
parking_lot = { version = "0.9" }
rendy-memory = { git = "https://github.com/amethyst/rendy", rev = "db6adbe7454f52ebf559a38dd88580aa3ebbcaaf" }
rendy-descriptor = { git = "https://github.com/amethyst/rendy", rev = "db6adbe7454f52ebf559a38dd88580aa3ebbcaaf" }
Expand Down
14 changes: 7 additions & 7 deletions wgpu-native/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ pub extern "C" fn wgpu_create_instance() -> InstanceId {
HUB.instances.register_local(inst, &mut Token::root())
}

#[cfg(all(feature = "local", feature = "gfx-backend-gl"))]
#[cfg(all(feature = "local", feature = "glutin"))]
pub fn wgpu_create_gl_instance(windowed_context: back::glutin::RawContext<back::glutin::PossiblyCurrent>) -> InstanceId {
let raw = back::Surface::from_context(windowed_context);
let surface = SurfaceHandle::new(raw);
HUB.surfaces.register_local(surface, &mut Token::root())
}

#[cfg(all(feature = "window-winit", not(feature = "gfx-backend-gl")))]
#[cfg(all(feature = "local", feature = "winit", not(feature = "glutin")))]
#[no_mangle]
pub extern "C" fn wgpu_instance_create_surface_from_winit(
instance_id: InstanceId,
Expand Down Expand Up @@ -151,8 +151,7 @@ pub fn instance_create_surface_from_macos_layer(
}
}

#[cfg(not(feature = "gfx-backend-gl"))]
#[cfg(feature = "local")]
#[cfg(all(feature = "local", not(feature = "gfx-backend-gl")))]
#[no_mangle]
pub extern "C" fn wgpu_instance_create_surface_from_macos_layer(
instance_id: InstanceId,
Expand Down Expand Up @@ -190,8 +189,7 @@ pub fn instance_create_surface_from_windows_hwnd(
SurfaceHandle::new(raw)
}

#[cfg(not(feature = "gfx-backend-gl"))]
#[cfg(feature = "local")]
#[cfg(all(feature = "local", not(feature = "gfx-backend-gl")))]
#[no_mangle]
pub extern "C" fn wgpu_instance_create_surface_from_windows_hwnd(
instance_id: InstanceId,
Expand All @@ -218,11 +216,13 @@ pub fn instance_get_adapter(
let (instance_guard, _) = HUB.instances.read(token);
instance_guard[instance_id].enumerate_adapters()
};
#[cfg(feature = "gfx-backend-gl")]
#[cfg(feature = "glutin")]
let adapters = {
let (surface_guard, _) = HUB.surfaces.read(token);
surface_guard[instance_id].raw.enumerate_adapters()
};
#[cfg(all(feature = "glutin", not(feature = "gfx-backend-gl")))]
let adapters = Vec::<AdapterHandle>::new();

let (mut integrated_first, mut discrete_first, mut discrete_last, mut alternative) =
(None, None, None, None);
Expand Down
4 changes: 2 additions & 2 deletions wgpu-native/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(all(feature = "local", feature = "window-winit"))]
#[cfg(all(feature = "winit"))]
pub extern crate winit;

#[cfg(feature = "gfx-backend-dx11")]
Expand Down Expand Up @@ -44,7 +44,7 @@ pub use hal::pso::read_spirv;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[cfg(feature = "gfx-backend-gl")]
#[cfg(feature = "glutin")]
pub use back::glutin;

use std::{
Expand Down

0 comments on commit f30cb20

Please sign in to comment.