From 88f0b4190f77d215f13e88f826c6b5bf06cafe57 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 11 Nov 2024 21:52:30 +0200 Subject: [PATCH] fix(android): fix compile when `rwh_04` or `rwh_05` is active (#1012) * fix(android): fix compile when `rwh_04` or `rwh_05` is active closes #1011 * test features --- .github/workflows/ci.yml | 26 +++++++++----------------- Cargo.toml | 3 +++ src/platform_impl/android/mod.rs | 4 ++-- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a2ef204ee..c2674e529 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,13 +12,6 @@ jobs: - { id: windows, target: x86_64-pc-windows-msvc, os: windows-latest } # Ubuntu with default features - { id: ubuntu, target: x86_64-unknown-linux-gnu, os: ubuntu-latest } - # Ubuntu without features - - { - id: ubuntu-without-feat, - target: x86_64-unknown-linux-gnu, - os: ubuntu-latest, - options: --no-default-features, - } # macOS - { id: macos, target: x86_64-apple-darwin, os: macos-latest } # Android on Ubuntu @@ -30,13 +23,17 @@ jobs: } # iOS on Ubuntu - { id: ios, target: aarch64-apple-ios, os: macos-latest } + features: + - "" # default features + - "serde" # serde + default features + - "rwh_04,rwh_05,rwh_06" # rwh features env: RUST_BACKTRACE: 1 CARGO_INCREMENTAL: 0 RUSTFLAGS: "-C debuginfo=0" OPTIONS: ${{ matrix.platform.options }} - FEATURES: ${{ format(',{0}', matrix.platform.features ) }} + FEATURES: ${{ format(',{0}', matrix.features ) }} CMD: ${{ matrix.platform.cmd }} runs-on: ${{ matrix.platform.os }} @@ -59,11 +56,6 @@ jobs: sudo apt-get update sudo apt-get install -y libgtk-3-dev - - name: Install ayatana-libappindicator (ubuntu[default/tray] only) - if: matrix.platform.id == 'ubuntu' - run: | - sudo apt-get install -y libayatana-appindicator3-dev - - name: Install GCC Multilib if: (matrix.platform.os == 'ubuntu-latest') && contains(matrix.platform.target, 'i686') run: sudo apt-get install gcc-multilib @@ -93,18 +85,18 @@ jobs: - name: Build with all features enabled shell: bash - run: cargo $CMD build --verbose --target ${{ matrix.platform.target }} $OPTIONS --features serde,$FEATURES + run: cargo $CMD build --verbose --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES - name: Build tests with all features enabled shell: bash - run: cargo $CMD test --no-run --verbose --target ${{ matrix.platform.target }} $OPTIONS --features serde,$FEATURES + run: cargo $CMD test --no-run --verbose --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES - name: Run tests with all features enabled shell: bash if: ( !contains(matrix.platform.target, 'android') && !contains(matrix.platform.target, 'ios')) - run: cargo $CMD test --verbose --target ${{ matrix.platform.target }} $OPTIONS --features serde,$FEATURES + run: cargo $CMD test --verbose --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES - uses: dtolnay/rust-toolchain@nightly if: ( @@ -119,7 +111,7 @@ jobs: !contains(matrix.platform.target, 'android') && !contains(matrix.platform.target, 'ios')) shell: bash - run: cargo +nightly miri test --target ${{ matrix.platform.target }} $OPTIONS --features serde,$FEATURES + run: cargo +nightly miri test --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES test_tao_macros: runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index 933559e68..3436f9996 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,9 @@ targets = [ [features] default = [ "rwh_06" ] serde = [ "dep:serde", "dpi/serde" ] +rwh_04 = [ "dep:rwh_04" ] +rwh_05 = [ "dep:rwh_05" ] +rwh_06 = [ "dep:rwh_06" ] [workspace] members = [ "tao-macros" ] diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index 19d8e1b04..e489732db 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -700,7 +700,7 @@ impl Window { pub fn raw_window_handle_rwh_04(&self) -> rwh_04::RawWindowHandle { // TODO: Use main activity instead? let mut handle = rwh_04::AndroidNdkHandle::empty(); - if let Some(w) = ndk_glue::window_manager() { + if let Some(w) = ndk_glue::window_manager().as_ref() { handle.a_native_window = w.as_obj().as_raw() as *mut _; } else { panic!("Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events."); @@ -712,7 +712,7 @@ impl Window { pub fn raw_window_handle_rwh_05(&self) -> rwh_05::RawWindowHandle { // TODO: Use main activity instead? let mut handle = rwh_05::AndroidNdkWindowHandle::empty(); - if let Some(w) = ndk_glue::window_manager() { + if let Some(w) = ndk_glue::window_manager().as_ref() { handle.a_native_window = w.as_obj().as_raw() as *mut _; } else { panic!("Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events.");