From f35dd741aa46ac464f6229bebc72f8b11aead9bd Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Fri, 1 May 2020 00:22:00 -0400 Subject: [PATCH] Android support (#625) --- .github/workflows/ci.yml | 16 +++++++++++++++- README.md | 2 +- bors.toml | 1 + wgpu-core/src/device/trace.rs | 2 +- wgpu-core/src/instance.rs | 24 +++++++++++++++++++++--- wgpu-types/src/lib.rs | 6 +++--- 6 files changed, 42 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf93ffe92..804948f33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,7 @@ jobs: iOS Stable, MacOS Stable, MacOS Nightly, + Android Stable, Ubuntu Stable, Ubuntu Nightly, Windows Stable, @@ -41,6 +42,12 @@ jobs: build_command: cargo test additional_core_features: additional_player_features: + - os: ubuntu-18.04 + name: Android Stable + channel: stable + build_command: rustup target add aarch64-linux-android; cargo clippy --target aarch64-linux-android + additional_core_features: trace + additional_player_features: - os: ubuntu-18.04 name: Ubuntu Stable channel: stable @@ -67,13 +74,20 @@ jobs: additional_player_features: steps: - uses: actions/checkout@v2 + - if: matrix.name == 'Android Stable' + run: | + curl -LO https://dl.google.com/android/repository/android-ndk-r21b-linux-x86_64.zip + unzip -qq android-ndk-r21b-linux-x86_64.zip -d $GITHUB_WORKSPACE + export NDK_HOME_BIN=$GITHUB_WORKSPACE/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin + ln -s $NDK_HOME_BIN/aarch64-linux-android21-clang $NDK_HOME_BIN/aarch64-linux-android-clang + echo "::add-path::$NDK_HOME_BIN" - if: matrix.channel == 'nightly' name: Install latest nightly uses: actions-rs/toolchain@v1 with: toolchain: nightly override: true - - if: contains(matrix.build_command, 'clippy') + - if: matrix.channel == 'stable' run: rustup component add clippy - name: cargo clippy/test run: ${{ matrix.build_command }} diff --git a/README.md b/README.md index a16a36f76..98831d16e 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ If you are looking for the native implementation or bindings to the API in other ## Supported Platforms - API | Windows | Linux | macOS & iOS | + API | Windows 7/10 | Linux & Android | macOS & iOS | ----- | ------------------ | ------------------ | ------------------ | DX11 | :white_check_mark: | | | DX12 | :heavy_check_mark: | | | diff --git a/bors.toml b/bors.toml index a2311e04f..f83b5282a 100644 --- a/bors.toml +++ b/bors.toml @@ -2,6 +2,7 @@ status = [ "iOS Stable", "MacOS Stable", "MacOS Nightly", + "Android Stable", "Ubuntu Stable", "Ubuntu Nightly", "Windows Stable", diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index e34656cef..93efefbde 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -241,7 +241,7 @@ impl Trace { pub(crate) fn add(&mut self, action: Action) { match ron::ser::to_string_pretty(&action, self.config.clone()) { Ok(string) => { - let _ = write!(self.file, "{},\n", string); + let _ = writeln!(self.file, "{},", string); } Err(e) => { log::warn!("RON serialization failure: {:?}", e); diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 9819f42d3..0e7c0a10e 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -248,15 +248,25 @@ impl Global { .create_surface_from_nsview(h.ns_view, cfg!(debug_assertions)), } } - #[cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))] + #[cfg(all( + unix, + not(target_os = "android"), + not(target_os = "ios"), + not(target_os = "macos") + ))] Rwh::Xlib(h) => Surface { vulkan: self .instance .vulkan .as_ref() - .map(|inst| inst.create_surface_from_xlib(h.display as _, h.window as _)), + .map(|inst| inst.create_surface_from_xlib(h.display as _, h.window)), }, - #[cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))] + #[cfg(all( + unix, + not(target_os = "android"), + not(target_os = "ios"), + not(target_os = "macos") + ))] Rwh::Wayland(h) => Surface { vulkan: self .instance @@ -264,6 +274,14 @@ impl Global { .as_ref() .map(|inst| inst.create_surface_from_wayland(h.display, h.surface)), }, + #[cfg(target_os = "android")] + Rwh::Android(h) => Surface { + vulkan: self + .instance + .vulkan + .as_ref() + .map(|inst| inst.create_surface_android(h.a_native_window)), + }, #[cfg(windows)] Rwh::Windows(h) => Surface { vulkan: self diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index fc8318e5f..e9463199d 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -121,13 +121,13 @@ pub fn read_spirv(mut x: R) -> io::Result> { ))?; result.set_len(words); } - const MAGIC_NUMBER: u32 = 0x07230203; - if result.len() > 0 && result[0] == MAGIC_NUMBER.swap_bytes() { + const MAGIC_NUMBER: u32 = 0x0723_0203; + if !result.is_empty() && result[0] == MAGIC_NUMBER.swap_bytes() { for word in &mut result { *word = word.swap_bytes(); } } - if result.len() == 0 || result[0] != MAGIC_NUMBER { + if result.is_empty() || result[0] != MAGIC_NUMBER { return Err(io::Error::new( io::ErrorKind::InvalidData, "input missing SPIR-V magic number",