Skip to content

Commit c04d034

Browse files
lucasfernogYu-Wei Wu
andauthored
feat(core): prepare build for mobile targets (#4830)
Co-authored-by: Yu-Wei Wu <wusyong9104@gmail.com>
1 parent 5cc1fd0 commit c04d034

20 files changed

Lines changed: 376 additions & 259 deletions

File tree

.changes/build-platform-alias.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-build": patch
3+
---
4+
5+
Create the `desktop` and `mobile` cfg aliases.

core/tauri-build/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
203203
#[cfg(feature = "config-json5")]
204204
println!("cargo:rerun-if-changed=tauri.conf.json5");
205205

206+
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
207+
let mobile = target_os == "ios" || target_os == "android";
208+
cfg_alias("desktop", !mobile);
209+
cfg_alias("mobile", mobile);
210+
206211
let mut config = serde_json::from_value(tauri_utils::config::parse::read_from(
207212
std::env::current_dir().unwrap(),
208213
)?)?;

core/tauri-codegen/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ fn png_icon<P: AsRef<Path>>(
523523
Ok(icon)
524524
}
525525

526+
#[cfg(any(windows, target_os = "macos", target_os = "linux"))]
526527
fn find_icon<F: Fn(&&String) -> bool>(
527528
config: &Config,
528529
config_parent: &Path,

core/tauri-runtime-wry/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
// creates a cfg alias if `has_feature` is true.
6+
// `alias` must be a snake case string.
7+
fn alias(alias: &str, has_feature: bool) {
8+
if has_feature {
9+
println!("cargo:rustc-cfg={}", alias);
10+
}
11+
}
12+
13+
fn main() {
14+
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
15+
let mobile = target_os == "ios" || target_os == "android";
16+
alias("desktop", !mobile);
17+
alias("mobile", mobile);
18+
}

core/tauri-runtime-wry/src/global_shortcut.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use std::{
1616
use crate::{getter, Context, Message};
1717

1818
use tauri_runtime::{Error, GlobalShortcutManager, Result, UserEvent};
19-
pub use wry::application::global_shortcut::ShortcutManager as WryShortcutManager;
20-
use wry::application::{
19+
#[cfg(desktop)]
20+
pub use wry::application::{
2121
accelerator::{Accelerator, AcceleratorId},
22-
global_shortcut::GlobalShortcut,
22+
global_shortcut::{GlobalShortcut, ShortcutManager as WryShortcutManager},
2323
};
2424

2525
pub type GlobalShortcutListeners = Arc<Mutex<HashMap<AcceleratorId, Box<dyn Fn() + Send>>>>;

0 commit comments

Comments
 (0)