Skip to content

Provide commands to support using multiple uniffi packages #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
884 changes: 884 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "uniffi-swift-helper"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0"
cargo_metadata = "0.19"
clap = { version = "4.5", features = ["derive"] }
pathdiff = "0.2"
rinja = "0.3"
serde_json = "1.0"
toml = { version = "0.8", features = ["parse"] }
uniffi = "0.28"
uniffi_bindgen = "0.28"
79 changes: 79 additions & 0 deletions src/apple_platform.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use std::{fmt::Display, process::Command};

use crate::spm::DeploymentTargets;

#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum ApplePlatform {
MacOS,
#[allow(clippy::upper_case_acronyms)]
IOS,
TvOS,
WatchOS,
}

impl ApplePlatform {
pub fn all() -> Vec<Self> {
vec![Self::MacOS, Self::IOS, Self::TvOS, Self::WatchOS]
}

pub fn target_triples(&self) -> Vec<&'static str> {
match self {
Self::IOS => vec![
"aarch64-apple-ios",
"x86_64-apple-ios",
"aarch64-apple-ios-sim",
],
Self::MacOS => vec!["x86_64-apple-darwin", "aarch64-apple-darwin"],
Self::WatchOS => vec![
"arm64_32-apple-watchos",
"x86_64-apple-watchos-sim",
"aarch64-apple-watchos-sim",
],
Self::TvOS => vec!["aarch64-apple-tvos", "aarch64-apple-tvos-sim"],
}
}

pub fn requires_nightly_toolchain(&self) -> bool {
matches!(self, Self::TvOS | Self::WatchOS)
}

pub fn set_deployment_target_env(&self, command: &mut Command) {
let (key, value) = self.deployment_targets_env();
command.env(key, value);
}

fn deployment_targets_env(&self) -> (&'static str, &'static str) {
match self {
Self::IOS => ("IOS_DEPLOYMENT_TARGET", DeploymentTargets::ios()),
Self::MacOS => ("MACOSX_DEPLOYMENT_TARGET", DeploymentTargets::macos()),
Self::TvOS => ("TVOS_DEPLOYMENT_TARGET", DeploymentTargets::tvos()),
Self::WatchOS => ("WATCHOS_DEPLOYMENT_TARGET", DeploymentTargets::watchos()),
}
}
}

impl TryFrom<&str> for ApplePlatform {
type Error = anyhow::Error;

fn try_from(s: &str) -> std::result::Result<Self, anyhow::Error> {
match s {
"darwin" => Ok(ApplePlatform::MacOS),
"ios" => Ok(ApplePlatform::IOS),
"tvos" => Ok(ApplePlatform::TvOS),
"watchos" => Ok(ApplePlatform::WatchOS),
_ => anyhow::bail!("Unknown Apple platform: {}", s),
}
}
}

impl Display for ApplePlatform {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name = match self {
ApplePlatform::MacOS => "macos",
ApplePlatform::IOS => "ios",
ApplePlatform::TvOS => "tvos",
ApplePlatform::WatchOS => "watchos",
};
write!(f, "{}", name)
}
}
Loading