Skip to content
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

Support tvOS and watchOS simulators #203

Merged
merged 8 commits into from
Feb 22, 2024
Merged
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
76 changes: 70 additions & 6 deletions .travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -x

title() {
set +x
echo -e '\n\033[1;33m '$@' \033[0m\n'
echo -e '\n\033[1;33m '$@' \033[0m\n'
set -x
}

Expand Down Expand Up @@ -40,7 +40,7 @@ tests_sequence() {
&& ! $CARGO_DINGHY -d $1 test fails \
&& ! $CARGO_DINGHY -d $1 test \
)

title "testing from project directory"
( \
cd test-ws/test-app \
Expand All @@ -49,7 +49,7 @@ tests_sequence() {
&& ! $CARGO_DINGHY -d $1 test fails \
&& ! $CARGO_DINGHY -d $1 test \
)

title "test from workspace directory with project filter"
( \
cd test-ws \
Expand All @@ -69,7 +69,7 @@ tests_sequence_aarch64_ios_sim() {
&& ! $CARGO_DINGHY -d $1 -p auto-ios-aarch64-sim test fails \
&& ! $CARGO_DINGHY -d $1 -p auto-ios-aarch64-sim test \
)

title "testing from project directory"
( \
cd test-ws/test-app \
Expand All @@ -78,7 +78,7 @@ tests_sequence_aarch64_ios_sim() {
&& ! $CARGO_DINGHY -d $1 -p auto-ios-aarch64-sim test fails \
&& ! $CARGO_DINGHY -d $1 -p auto-ios-aarch64-sim test \
)

title "test from workspace directory with project filter"
( \
cd test-ws \
Expand All @@ -89,6 +89,39 @@ tests_sequence_aarch64_ios_sim() {
)
}

tests_sequence_unstable_target() {
# There's something odd with using the .cargo/config runner attribute and
# workspaces when the runner uses `cargo run --manifest-path ../Cargo.toml
# --bin cargo-dinghy ...`
title "testing from project directory for rust target $1 on device $2"
title "testing from workspace directory"
( \
cd test-ws \
&& cargo clean \
&& $CARGO_DINGHY -d $1 -p $2 +nightly test -Zbuild-std pass \
&& ! $CARGO_DINGHY -d $1 -p $2 +nightly test -Zbuild-std fails \
&& ! $CARGO_DINGHY -d $1 -p $2 +nightly test -Zbuild-std \
)

title "testing from project directory"
( \
cd test-ws/test-app \
&& cargo clean \
&& $CARGO_DINGHY -d $1 -p $2 +nightly test -Zbuild-std pass \
&& ! $CARGO_DINGHY -d $1 -p $2 +nightly test -Zbuild-std fails \
&& ! $CARGO_DINGHY -d $1 -p $2 +nightly test -Zbuild-std \
)

title "test from workspace directory with project filter"
( \
cd test-ws \
&& cargo clean \
&& $CARGO_DINGHY -d $1 -p $2 +nightly test -p test-app -Zbuild-std pass \
&& ! $CARGO_DINGHY -d $1 -p $2 +nightly test -p test-app -Zbuild-std fails \
&& ! $CARGO_DINGHY -d $1 -p $2 +nightly test -p test-app -Zbuild-std \
)
}


if [ `uname` = Darwin ]
then
Expand Down Expand Up @@ -124,6 +157,37 @@ then
rustup target add aarch64-apple-ios
tests_sequence $device
fi

title "••••• Darwin: tvos simulator tests •••••"
title "boot a simulator"

# *-apple-{tvos,watchos}[-sim] require `-Zbuild-std`
rustup toolchain add nightly --component rust-src;
simlay marked this conversation as resolved.
Show resolved Hide resolved
TVOS_RUNTIME_ID=$(xcrun simctl list runtimes | grep tvOS | cut -d ' ' -f 7 | tail -1)
export TV_SIM_ID=$(xcrun simctl create My-4ktv com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-3rd-generation-4K $TVOS_RUNTIME_ID)

xcrun simctl boot $TV_SIM_ID
if [ "$(uname -m)" = "arm64" ]; then
tests_sequence_unstable_target ${TV_SIM_ID} auto-tvos-aarch64-sim
else
# The x86 tvOS simulator tripple does not end in -sim.
tests_sequence_unstable_target ${TV_SIM_ID} auto-tvos-x86_64
fi
xcrun simctl delete $TV_SIM_ID

title "••••• Darwin: watchvos simulator tests •••••"
title "boot a simulator"
WATCHOS_RUNTIME_ID=$(xcrun simctl list runtimes | grep watchOS | cut -d ' ' -f 7 | tail -1)
export WATCHOS_SIM_ID=$(xcrun simctl create My-apple-watch com.apple.CoreSimulator.SimDeviceType.Apple-Watch-SE-44mm-2nd-generation $WATCHOS_RUNTIME_ID)

xcrun simctl boot $WATCHOS_SIM_ID
if [ "$(uname -m)" = "arm64" ]; then
tests_sequence_unstable_target ${WATCHOS_SIM_ID} auto-watchos-aarch64-sim
else
tests_sequence_unstable_target ${WATCHOS_SIM_ID} auto-watchos-x86_64-sim
fi
xcrun simctl delete $WATCHOS_SIM_ID
rustup default stable
else
if [ -n "$ANDROID_SDK_ROOT" ]
then
Expand All @@ -150,7 +214,7 @@ else
echo no | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager create avd -n testdinghy -k "system-images;android-24;default;armeabi-v7a"
$EMULATOR @testdinghy -no-audio -no-boot-anim -no-window -accel on -gpu off &
timeout 180 $ANDROID_SDK_ROOT/platform-tools/adb wait-for-device

export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/22.1.7171670

tests_sequence android
Expand Down
52 changes: 29 additions & 23 deletions dinghy-lib/src/ios/device.rs → dinghy-lib/src/apple/device.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::xcode;
use super::{xcode, AppleSimulatorType};
use crate::device::make_remote_app_with_name;
use crate::errors::*;
use crate::ios::IosPlatform;
use crate::apple::AppleDevicePlatform;
use crate::project::Project;
use crate::utils::LogCommandExt;
use crate::utils::{get_current_verbosity, user_facing_log};
Expand All @@ -27,10 +27,11 @@ pub struct IosDevice {
}

#[derive(Clone, Debug)]
pub struct IosSimDevice {
pub struct AppleSimDevice {
pub id: String,
pub name: String,
pub os: String,
pub sim_type: AppleSimulatorType,
}

unsafe impl Send for IosDevice {}
Expand Down Expand Up @@ -76,7 +77,7 @@ impl IosDevice {
.last()
.ok_or_else(|| anyhow!("no app id ?"))?;

let build_bundle = make_ios_app(project, build, runnable, &app_id)?;
let build_bundle = make_apple_app(project, build, runnable, &app_id, None)?;

super::xcode::sign_app(&build_bundle, &signing)?;
Ok(build_bundle)
Expand Down Expand Up @@ -191,7 +192,7 @@ impl Device for IosDevice {
}
}

impl IosSimDevice {
impl AppleSimDevice {
fn install_app(
&self,
project: &Project,
Expand All @@ -203,7 +204,7 @@ impl IosSimDevice {
&format!("{} to {}", build.runnable.id, self.id),
0,
);
let build_bundle = IosSimDevice::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 @@ -231,12 +232,12 @@ impl IosSimDevice {
}
}

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> {
make_apple_app(project, build, runnable, "Dinghy", Some(&self.sim_type))
}
}

impl Device for IosSimDevice {
impl Device for AppleSimDevice {
fn clean_app(&self, _build_bundle: &BuildBundle) -> Result<()> {
unimplemented!()
}
Expand Down Expand Up @@ -312,11 +313,11 @@ impl Display for IosDevice {
}
}

impl Display for IosSimDevice {
impl Display for AppleSimDevice {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
Ok(fmt.write_str(
format!(
"IosSimDevice {{ \"id\": \"{}\", \"name\": {}, \"os\": {} }}",
"AppleSimDevice {{ \"id\": \"{}\", \"name\": {}, \"os\": {} }}",
self.id, self.name, self.os
)
.as_str(),
Expand All @@ -325,8 +326,8 @@ impl Display for IosSimDevice {
}

impl DeviceCompatibility for IosDevice {
fn is_compatible_with_ios_platform(&self, platform: &IosPlatform) -> bool {
if platform.sim {
fn is_compatible_with_simulator_platform(&self, platform: &AppleDevicePlatform) -> bool {
if platform.sim.is_some() {
return false;
}

Expand All @@ -337,19 +338,22 @@ impl DeviceCompatibility for IosDevice {
}
}

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

fn make_ios_app(
fn make_apple_app(
project: &Project,
build: &Build,
runnable: &Runnable,
app_id: &str,
sim_type: Option<&AppleSimulatorType>,
) -> Result<BuildBundle> {
use crate::project;
let build_bundle = make_remote_app_with_name(project, build, Some("Dinghy.app"))?;
Expand All @@ -368,11 +372,12 @@ 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_app(&build_bundle, target, app_id, sim_type)?;
Ok(build_bundle)
}

fn launch_app(dev: &IosSimDevice, app_args: &[&str], _envs: &[&str]) -> Result<()> {

fn launch_app(dev: &AppleSimDevice, app_args: &[&str], _envs: &[&str]) -> Result<()> {
use std::io::Write;
let dir = ::tempdir::TempDir::new("mobiledevice-rs-lldb")?;
let tmppath = dir.path();
Expand All @@ -397,6 +402,7 @@ fn launch_app(dev: &IosSimDevice, app_args: &[&str], _envs: &[&str]) -> Result<(
.log_invocation(1)
.output()?;
let launch_output = String::from_utf8_lossy(&launch_output.stdout);
debug!("xcrun simctl launch output: {:?}", launch_output);

// Output from the launch command should be "Dinghy: $PID" which is after the 8th character.
let dinghy_pid = launch_output.split_at(8).1;
Expand Down Expand Up @@ -458,12 +464,12 @@ fn launch_app(dev: &IosSimDevice, app_args: &[&str], _envs: &[&str]) -> Result<(
);
}
} else {
panic!("Failed to get the exit status line from lldb: {:?}", output);
panic!("Failed to get the exit status line from lldb: {}", output);
}
}

fn launch_lldb_simulator(
dev: &IosSimDevice,
dev: &AppleSimDevice,
installed: &str,
args: &[&str],
envs: &[&str],
Expand Down
File renamed without changes.
Loading