Skip to content

Commit

Permalink
Added compatibility trait for simulators and plist creation for tvos …
Browse files Browse the repository at this point in the history
…and watchos
  • Loading branch information
simlay committed Dec 30, 2023
1 parent 28b5c94 commit b887152
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 10 deletions.
74 changes: 67 additions & 7 deletions dinghy-lib/src/apple/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl AppleSimDevice {
&format!("{} to {}", build.runnable.id, self.id),
0,
);
let build_bundle = AppleSimDevice::make_app(project, build, runnable)?;
let build_bundle = self.make_app(project, build, runnable)?;
let _ = process::Command::new("xcrun")
.args(&["simctl", "uninstall", &self.id, "Dinghy"])
.log_invocation(2)
Expand Down Expand Up @@ -232,8 +232,12 @@ impl AppleSimDevice {
}
}

fn make_app(project: &Project, build: &Build, runnable: &Runnable) -> Result<BuildBundle> {
make_ios_app(project, build, runnable, "Dinghy")
fn make_app(&self, project: &Project, build: &Build, runnable: &Runnable) -> Result<BuildBundle> {
match self.sim_type {
AppleSimulatorType::Ios => make_ios_app(project, build, runnable, "Dinghy"),
AppleSimulatorType::Watchos => make_watchos_app(project, build, runnable, "Dinghy"),
AppleSimulatorType::Tvos => make_tvos_app(project, build, runnable, "Dinghy"),
}
}
}

Expand Down Expand Up @@ -340,9 +344,11 @@ impl DeviceCompatibility for IosDevice {

impl DeviceCompatibility for AppleSimDevice {
fn is_compatible_with_simulator_platform(&self, platform: &AppleDevicePlatform) -> bool {
platform.sim.is_some()
&& (platform.toolchain.rustc_triple == "x86_64-apple-ios"
|| platform.toolchain.rustc_triple == "aarch64-apple-ios-sim")
if let Some(sim) = &platform.sim {
self.sim_type == *sim
} else {
false
}
}
}

Expand All @@ -369,7 +375,61 @@ fn make_ios_app(
.split(" ")
.last()
.ok_or_else(|| anyhow!("empty magic"))?;
xcode::add_plist_to_app(&build_bundle, target, app_id)?;
xcode::add_plist_to_ios_app(&build_bundle, target, app_id)?;
Ok(build_bundle)
}

fn make_watchos_app(
project: &Project,
build: &Build,
runnable: &Runnable,
app_id: &str,
) -> Result<BuildBundle> {
use crate::project;
let build_bundle = make_remote_app_with_name(project, build, Some("Dinghy.app"))?;
project::rec_copy(&runnable.exe, build_bundle.bundle_dir.join("Dinghy"), false)?;
let magic = process::Command::new("file")
.arg(
runnable
.exe
.to_str()
.ok_or_else(|| anyhow!("path conversion to string: {:?}", runnable.exe))?,
)
.log_invocation(3)
.output()?;
let magic = String::from_utf8(magic.stdout)?;
let target = magic
.split(" ")
.last()
.ok_or_else(|| anyhow!("empty magic"))?;
xcode::add_plist_to_watchos_app(&build_bundle, target, app_id)?;
Ok(build_bundle)
}

fn make_tvos_app(
project: &Project,
build: &Build,
runnable: &Runnable,
app_id: &str,
) -> Result<BuildBundle> {
use crate::project;
let build_bundle = make_remote_app_with_name(project, build, Some("Dinghy.app"))?;
project::rec_copy(&runnable.exe, build_bundle.bundle_dir.join("Dinghy"), false)?;
let magic = process::Command::new("file")
.arg(
runnable
.exe
.to_str()
.ok_or_else(|| anyhow!("path conversion to string: {:?}", runnable.exe))?,
)
.log_invocation(3)
.output()?;
let magic = String::from_utf8(magic.stdout)?;
let target = magic
.split(" ")
.last()
.ok_or_else(|| anyhow!("empty magic"))?;
xcode::add_plist_to_tvos_app(&build_bundle, target, app_id)?;
Ok(build_bundle)
}

Expand Down
4 changes: 2 additions & 2 deletions dinghy-lib/src/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct SigningIdentity {
pub team: String,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub enum AppleSimulatorType {
Ios,
Watchos,
Expand Down Expand Up @@ -135,7 +135,7 @@ impl PlatformManager for WatchosManager {
format!("aarch64-apple-watchos-sim")
};
let simulator = if *arch == "x86_64-sim" || *arch == "aarch64-sim" {
Some(AppleSimulatorType::Tvos)
Some(AppleSimulatorType::Watchos)
} else {
None
};
Expand Down
121 changes: 120 additions & 1 deletion dinghy-lib/src/apple/xcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{fs, io, process};
use crate::utils::LogCommandExt;
use crate::BuildBundle;

pub fn add_plist_to_app(bundle: &BuildBundle, arch: &str, app_bundle_id: &str) -> Result<()> {
pub fn add_plist_to_ios_app(bundle: &BuildBundle, arch: &str, app_bundle_id: &str) -> Result<()> {
let mut plist = fs::File::create(bundle.bundle_dir.join("Info.plist"))?;
writeln!(plist, r#"<?xml version="1.0" encoding="UTF-8"?>"#)?;
writeln!(
Expand Down Expand Up @@ -69,6 +69,125 @@ pub fn add_plist_to_app(bundle: &BuildBundle, arch: &str, app_bundle_id: &str) -
*/
Ok(())
}
pub fn add_plist_to_tvos_app(bundle: &BuildBundle, arch: &str, app_bundle_id: &str) -> Result<()> {
let mut plist = fs::File::create(bundle.bundle_dir.join("Info.plist"))?;
writeln!(plist, r#"<?xml version="1.0" encoding="UTF-8"?>"#)?;
writeln!(
plist,
r#"<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">"#
)?;
writeln!(plist, r#"<plist version="1.0"><dict>"#)?;
writeln!(
plist,
"<key>CFBundleExecutable</key><string>Dinghy</string>",
)?;
writeln!(
plist,
"<key>CFBundleIdentifier</key><string>{}</string>",
app_bundle_id
)?;
writeln!(plist, "<key>UIRequiredDeviceCapabilities</key>")?;
writeln!(plist, "<array><string>{}</string></array>", arch)?;
writeln!(plist, "<key>CFBundleVersion</key>")?;
writeln!(plist, "<string>{}</string>", arch)?;
writeln!(plist, "<key>CFBundleShortVersionString</key>")?;
writeln!(plist, "<string>{}</string>", arch)?;
writeln!(plist, "<key>UILaunchStoryboardName</key>")?;
writeln!(plist, "<string></string>")?;
writeln!(plist, r#"</dict></plist>"#)?;
Ok(())
}

pub fn add_plist_to_watchos_app(bundle: &BuildBundle, arch: &str, app_bundle_id: &str) -> Result<()> {
let mut plist = fs::File::create(bundle.bundle_dir.join("Info.plist"))?;

let plist_data = r#"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>integration_test</string>
<key>CFBundleIdentifier</key>
<string>com.rust.tests</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>WatchSimulator</string>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>21R354</string>
<key>DTPlatformName</key>
<string>watchsimulator</string>
<key>DTPlatformVersion</key>
<string>10.0</string>
<key>DTSDKBuild</key>
<string>21R354</string>
<key>DTSDKName</key>
<string>watchsimulator10.0</string>
<key>DTXcode</key>
<string>1501</string>
<key>DTXcodeBuild</key>
<string>15A507</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<key>MinimumOSVersion~ipad</key>
<string>9.0</string>
<key>NSAccentColorName</key>
<string>AccentColor</string>
<key>UIDeviceFamily</key>
<array>
<integer>4</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>WKApplication</key>
<true/>
<key>WKWatchOnly</key>
<true/>
</dict>
</plist>"#;
write!(plist, "{plist_data}");
/*
writeln!(plist, r#"<?xml version="1.0" encoding="UTF-8"?>"#)?;
writeln!(
plist,
r#"<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">"#
)?;
writeln!(plist, r#"<plist version="1.0"><dict>"#)?;
writeln!(
plist,
"<key>CFBundleExecutable</key><string>Dinghy</string>",
)?;
writeln!(
plist,
"<key>CFBundleIdentifier</key><string>{}</string>",
app_bundle_id
)?;
writeln!(plist, "<key>UIRequiredDeviceCapabilities</key>")?;
writeln!(plist, "<array><string>{}</string></array>", arch)?;
writeln!(plist, "<key>CFBundleVersion</key>")?;
writeln!(plist, "<string>{}</string>", arch)?;
writeln!(plist, "<key>CFBundleShortVersionString</key>")?;
writeln!(plist, "<string>{}</string>", arch)?;
writeln!(plist, "<key>UILaunchStoryboardName</key>")?;
writeln!(plist, "<string></string>")?;
writeln!(plist, r#"</dict></plist>"#)?;
*/
Ok(())
}

pub fn sign_app(bundle: &BuildBundle, settings: &SignatureSettings) -> Result<()> {
debug!(
Expand Down
8 changes: 8 additions & 0 deletions test-ws/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[target.aarch64-apple-watchos-sim]
runner = "cargo run --manifest-path ../Cargo.toml --bin cargo-dinghy -- -p auto-watchos-aarch64-sim runner"

[target.aarch64-apple-tvos-sim]
runner = "cargo run --manifest-path ../Cargo.toml --bin cargo-dinghy -- -p auto-tvos-aarch64-sim runner"

[target.aarch64-apple-ios-sim]
runner = "cargo run --manifest-path ../Cargo.toml --bin cargo-dinghy -- -p auto-ios-aarch64-sim runner"

0 comments on commit b887152

Please sign in to comment.