From d677f73495b4a8dade5810255e1ece4b7d3f598a Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Fri, 19 May 2023 09:46:06 -0700 Subject: [PATCH] feat(ci): test mobile targets (#378) --- .github/workflows/test-rust.yml | 66 ++++++++++++++++--- plugins/authenticator/Cargo.toml | 2 + plugins/authenticator/src/lib.rs | 2 + plugins/autostart/src/lib.rs | 2 + .../ios/Sources/ClipboardPlugin.swift | 4 +- plugins/dialog/ios/Sources/DialogPlugin.swift | 6 +- plugins/global-shortcut/Cargo.toml | 2 + plugins/global-shortcut/src/lib.rs | 2 + plugins/positioner/src/lib.rs | 2 + plugins/single-instance/src/lib.rs | 2 + plugins/sql/src/lib.rs | 4 +- plugins/window-state/src/lib.rs | 2 + .../template/ios/Sources/ExamplePlugin.swift | 4 +- 13 files changed, 84 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test-rust.yml b/.github/workflows/test-rust.yml index 66254085..254fb503 100644 --- a/.github/workflows/test-rust.yml +++ b/.github/workflows/test-rust.yml @@ -126,28 +126,62 @@ jobs: fail-fast: false matrix: package: ${{ fromJSON(needs.changes.outputs.packages) }} - platform: [ubuntu-latest, macos-latest, windows-latest] + platform: + - { + target: x86_64-pc-windows-msvc, + os: windows-latest, + cross: false, + command: "test", + } + - { + target: x86_64-unknown-linux-gnu, + os: ubuntu-latest, + cross: false, + command: "test", + } + - { + target: x86_64-apple-darwin, + os: macos-latest, + cross: false, + command: "test", + } + - { + target: aarch64-apple-ios, + os: macos-latest, + cross: false, + command: "build", + } + - { + target: aarch64-linux-android, + os: ubuntu-latest, + cross: true, + command: "build", + } - runs-on: ${{ matrix.platform }} + runs-on: ${{ matrix.platform.os }} steps: - uses: actions/checkout@v3 - name: install webkit2gtk and libudev for [authenticator] - if: matrix.platform == 'ubuntu-latest' + if: contains(matrix.platform.target, 'unknown-linux') run: | sudo apt-get update sudo apt-get install -y libwebkit2gtk-4.0-dev libwebkit2gtk-4.1-dev libudev-dev - name: install openssl - if: ${{ matrix.platform == 'windows-latest' && contains(fromJSON('["tauri-plugin-http", "tauri-plugin-upload", "tauri-plugin-updater", "tauri-plugin-websocket", "tauri-plugin-authenticator"]'), matrix.package) }} + if: ${{ matrix.platform.os == 'windows-latest' && matrix.package == 'tauri-plugin-authenticator' }} run: | echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append vcpkg install openssl:x64-windows-static-md - uses: dtolnay/rust-toolchain@1.65.0 + with: + targets: ${{ matrix.platform.target }} - uses: Swatinem/rust-cache@v2 + with: + key: ${{ matrix.package }} - name: create dummy dist working-directory: examples/api @@ -155,16 +189,32 @@ jobs: - name: test ${{ matrix.package }} if: matrix.package != 'tauri-plugin-sql' - run: cargo test --package ${{ matrix.package }} --all-targets + uses: actions-rs/cargo@v1 + with: + use-cross: ${{ matrix.platform.cross }} + command: ${{ matrix.platform.command }} + args: --package ${{ matrix.package }} --target ${{ matrix.platform.target }} --all-targets - name: test ${{ matrix.package }} --all-features if: ${{ !contains(fromJSON('["tauri-plugin-http", "tauri-plugin-upload", "tauri-plugin-updater", "tauri-plugin-websocket", "tauri-plugin-sql"]'), matrix.package) }} - run: cargo test --package ${{ matrix.package }} --all-targets --all-features + uses: actions-rs/cargo@v1 + with: + use-cross: ${{ matrix.platform.cross }} + command: ${{ matrix.platform.command }} + args: --package ${{ matrix.package }} --target ${{ matrix.platform.target }} --all-targets --all-features - name: test ${{ matrix.package }} mysql if: matrix.package == 'tauri-plugin-sql' - run: cargo test --package ${{ matrix.package }} --all-targets --no-default-features --features mysql + uses: actions-rs/cargo@v1 + with: + use-cross: ${{ matrix.platform.cross }} + command: ${{ matrix.platform.command }} + args: --package ${{ matrix.package }} --target ${{ matrix.platform.target }} --all-targets --features mysql - name: test ${{ matrix.package }} postgres if: matrix.package == 'tauri-plugin-sql' - run: cargo test --package ${{ matrix.package }} --all-targets --no-default-features --features postgres + uses: actions-rs/cargo@v1 + with: + use-cross: ${{ matrix.platform.cross }} + command: ${{ matrix.platform.command }} + args: --package ${{ matrix.package }} --target ${{ matrix.platform.target }} --all-targets --features postgres diff --git a/plugins/authenticator/Cargo.toml b/plugins/authenticator/Cargo.toml index 7ee8fb22..c3ca03ca 100644 --- a/plugins/authenticator/Cargo.toml +++ b/plugins/authenticator/Cargo.toml @@ -15,6 +15,8 @@ serde_json = { workspace = true } tauri = { workspace = true } log = { workspace = true } thiserror = { workspace = true } + +[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies] authenticator = "0.3.1" once_cell = "1" sha2 = "0.10" diff --git a/plugins/authenticator/src/lib.rs b/plugins/authenticator/src/lib.rs index ef889e21..e1b488e0 100644 --- a/plugins/authenticator/src/lib.rs +++ b/plugins/authenticator/src/lib.rs @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT +#![cfg(not(any(target_os = "android", target_os = "ios")))] + mod auth; mod error; mod u2f; diff --git a/plugins/autostart/src/lib.rs b/plugins/autostart/src/lib.rs index 3a927782..cfdd5ccc 100644 --- a/plugins/autostart/src/lib.rs +++ b/plugins/autostart/src/lib.rs @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT +#![cfg(not(any(target_os = "android", target_os = "ios")))] + use auto_launch::{AutoLaunch, AutoLaunchBuilder}; #[cfg(target_os = "macos")] use log::info; diff --git a/plugins/clipboard/ios/Sources/ClipboardPlugin.swift b/plugins/clipboard/ios/Sources/ClipboardPlugin.swift index cde6fa52..dda6177b 100644 --- a/plugins/clipboard/ios/Sources/ClipboardPlugin.swift +++ b/plugins/clipboard/ios/Sources/ClipboardPlugin.swift @@ -37,6 +37,6 @@ class ClipboardPlugin: Plugin { } @_cdecl("init_plugin_clipboard") -func initPlugin(name: SRString, webview: WKWebView?) { - Tauri.registerPlugin(webview: webview, name: name.toString(), plugin: ClipboardPlugin()) +func initPlugin() -> Plugin { + return ClipboardPlugin() } diff --git a/plugins/dialog/ios/Sources/DialogPlugin.swift b/plugins/dialog/ios/Sources/DialogPlugin.swift index dd0756b3..0970c056 100644 --- a/plugins/dialog/ios/Sources/DialogPlugin.swift +++ b/plugins/dialog/ios/Sources/DialogPlugin.swift @@ -202,6 +202,6 @@ class DialogPlugin: Plugin { } @_cdecl("init_plugin_dialog") -func initPlugin(name: SRString, webview: WKWebView?) { - Tauri.registerPlugin(webview: webview, name: name.toString(), plugin: DialogPlugin()) -} \ No newline at end of file +func initPlugin() -> Plugin { + return DialogPlugin() +} diff --git a/plugins/global-shortcut/Cargo.toml b/plugins/global-shortcut/Cargo.toml index bf685739..927c4337 100644 --- a/plugins/global-shortcut/Cargo.toml +++ b/plugins/global-shortcut/Cargo.toml @@ -11,4 +11,6 @@ serde_json = { workspace = true } tauri = { workspace = true } log = { workspace = true } thiserror = { workspace = true } + +[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies] global-hotkey = "0.2.1" diff --git a/plugins/global-shortcut/src/lib.rs b/plugins/global-shortcut/src/lib.rs index 7c34fc21..4266de21 100644 --- a/plugins/global-shortcut/src/lib.rs +++ b/plugins/global-shortcut/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg(not(any(target_os = "android", target_os = "ios")))] + use std::{ collections::HashMap, str::FromStr, diff --git a/plugins/positioner/src/lib.rs b/plugins/positioner/src/lib.rs index ab8cc922..34492a34 100644 --- a/plugins/positioner/src/lib.rs +++ b/plugins/positioner/src/lib.rs @@ -9,6 +9,8 @@ //! //! Note: This requires attaching the Tauri plugin, *even* when using the trait extension only. +#![cfg(not(any(target_os = "android", target_os = "ios")))] + mod ext; pub use ext::*; diff --git a/plugins/single-instance/src/lib.rs b/plugins/single-instance/src/lib.rs index a2ff71af..f2ceb458 100644 --- a/plugins/single-instance/src/lib.rs +++ b/plugins/single-instance/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg(not(any(target_os = "android", target_os = "ios")))] + use tauri::{plugin::TauriPlugin, AppHandle, Manager, Runtime}; #[cfg(target_os = "windows")] diff --git a/plugins/sql/src/lib.rs b/plugins/sql/src/lib.rs index 378240b3..20153109 100644 --- a/plugins/sql/src/lib.rs +++ b/plugins/sql/src/lib.rs @@ -7,7 +7,9 @@ all(feature = "sqlite", feature = "postgres"), all(feature = "mysql", feature = "postgres") ))] -compile_error!("Only one database driver can be enabled. Use `default-features = false` and set the feature flag for the driver of your choice."); +compile_error!( + "Only one database driver can be enabled. Set the feature flag for the driver of your choice." +); #[cfg(not(any(feature = "sqlite", feature = "mysql", feature = "postgres")))] compile_error!( diff --git a/plugins/window-state/src/lib.rs b/plugins/window-state/src/lib.rs index 3eaf4c52..9fdb6d54 100644 --- a/plugins/window-state/src/lib.rs +++ b/plugins/window-state/src/lib.rs @@ -2,6 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT +#![cfg(not(any(target_os = "android", target_os = "ios")))] + use bitflags::bitflags; use serde::{Deserialize, Serialize}; use tauri::{ diff --git a/shared/template/ios/Sources/ExamplePlugin.swift b/shared/template/ios/Sources/ExamplePlugin.swift index 86140b74..5544d3bc 100644 --- a/shared/template/ios/Sources/ExamplePlugin.swift +++ b/shared/template/ios/Sources/ExamplePlugin.swift @@ -11,6 +11,6 @@ class ExamplePlugin: Plugin { } @_cdecl("init_plugin_{{ plugin_name_snake_case }}") -func initPlugin(name: SRString, webview: WKWebView?) { - Tauri.registerPlugin(webview: webview, name: name.toString(), plugin: ExamplePlugin()) +func initPlugin() -> Plugin { + return ExamplePlugin() }