Skip to content

Commit

Permalink
feat(core): prepare build for mobile targets (#4830)
Browse files Browse the repository at this point in the history
Co-authored-by: Yu-Wei Wu <wusyong9104@gmail.com>
  • Loading branch information
lucasfernog and Yu-Wei Wu committed Aug 2, 2022
1 parent 5cc1fd0 commit c04d034
Show file tree
Hide file tree
Showing 20 changed files with 376 additions and 259 deletions.
5 changes: 5 additions & 0 deletions .changes/build-platform-alias.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": patch
---

Create the `desktop` and `mobile` cfg aliases.
5 changes: 5 additions & 0 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
#[cfg(feature = "config-json5")]
println!("cargo:rerun-if-changed=tauri.conf.json5");

let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let mobile = target_os == "ios" || target_os == "android";
cfg_alias("desktop", !mobile);
cfg_alias("mobile", mobile);

let mut config = serde_json::from_value(tauri_utils::config::parse::read_from(
std::env::current_dir().unwrap(),
)?)?;
Expand Down
1 change: 1 addition & 0 deletions core/tauri-codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ fn png_icon<P: AsRef<Path>>(
Ok(icon)
}

#[cfg(any(windows, target_os = "macos", target_os = "linux"))]
fn find_icon<F: Fn(&&String) -> bool>(
config: &Config,
config_parent: &Path,
Expand Down
18 changes: 18 additions & 0 deletions core/tauri-runtime-wry/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

// creates a cfg alias if `has_feature` is true.
// `alias` must be a snake case string.
fn alias(alias: &str, has_feature: bool) {
if has_feature {
println!("cargo:rustc-cfg={}", alias);
}
}

fn main() {
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let mobile = target_os == "ios" || target_os == "android";
alias("desktop", !mobile);
alias("mobile", mobile);
}
6 changes: 3 additions & 3 deletions core/tauri-runtime-wry/src/global_shortcut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use std::{
use crate::{getter, Context, Message};

use tauri_runtime::{Error, GlobalShortcutManager, Result, UserEvent};
pub use wry::application::global_shortcut::ShortcutManager as WryShortcutManager;
use wry::application::{
#[cfg(desktop)]
pub use wry::application::{
accelerator::{Accelerator, AcceleratorId},
global_shortcut::GlobalShortcut,
global_shortcut::{GlobalShortcut, ShortcutManager as WryShortcutManager},
};

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

0 comments on commit c04d034

Please sign in to comment.