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

Conversation

simlay
Copy link
Contributor

@simlay simlay commented Dec 28, 2023

Closes #194 and #193.

It's unclear if we want test these targets in CI. For one, these targets require the build-std nightly feature and for another, all targets for watchOS are tier 3 and tvOS are tier 3. They might sometimes break (as with tier 3 targets).

At this point, the thing I dislike about this implementation is that some parts imply that there are device targets for tvOS and watchOS and that's kinda not in planned (to me).

I elected to test watchOS and tvOS using just the test-ws/test-bin because it's simpler and I ended up with different errors in the test-ws/test-app pass tests.

I partially started this task with the goal of testing aarch64-apple-tvos-sim. I feel like I'm going crazy but I swear it was working but at moment of this writing, it fails on my machine. Yet, targets such as aarch64-apple-watchos-sim, x86_64-apple-watchos-sim and x86_64-apple-tvos all work. Free macOS github runners aren't apple silicon so we cannot test the aarch64 targets at the moment in CI. I think the existing tests should suffice.

@simlay simlay changed the title Rename ios module to apple Support tvOS and watchOS simulators Dec 28, 2023
@simlay simlay marked this pull request as ready for review January 2, 2024 00:41
Copy link

@briansmith briansmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we merge PR #206 and then rebase this on top of that PR. Then we can also add CI testing for this support, to ensure it works for both x86_64 and ARM64 hosts.

.travis.sh Outdated

if [ `uname` = Darwin ]
then
title "••••• Darwin: ios simulator tests •••••"
title "boot a simulator"
rustup target add x86_64-apple-ios;
RUNTIME_ID=$(xcrun simctl list runtimes | grep iOS | cut -d ' ' -f 7 | tail -1)
export SIM_ID=$(xcrun simctl create My-iphone7 com.apple.CoreSimulator.SimDeviceType.iPhone-8 $RUNTIME_ID)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's wrong. better to handle it in a separate PR.

.travis.sh Outdated
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
tests_sequence_unstable_target x86_64-apple-watchos-sim

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the M1 support PR, I suggest that we (automatically) use aarch64-apple-watchos-sim if the host is aarch64 and x86_64-apple-watchos-sim if the host is x86_64.

Perhaps we could extend the auto- mechanism to do this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what it will do if we use -d sim or '-d watchos-sim' actually. -d allows partial match. And if we are lucky the ios discovery code will only create an auto device for the matching architecture simulator...

And if it does not it may be desirable/easy to make it do so.

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree this is very useful to document and many people will want to copy-paste something like this into their own .cargo/config.toml. But perhaps we should have a separate PR for adding this example/documentation?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

.travis.sh Show resolved Hide resolved
.travis.sh Outdated

title "••••• Darwin: watchvos simulator tests •••••"
title "boot a simulator"
rustup toolchain add nightly --component rust-src;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the second time that the command is run.

Ok(build_bundle)
}

fn make_watchos_app(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like these two functions really duplicate a lot of make_ios_app. I think it would be easier to maintain if most of the commonality were factored out or if make_ios_app were renamed and parameterized over AppleSimulatorType so that it could handle all three cases.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda agree here, unless there is something I can't see.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I originally thought I might have to do more changes per simulator target so I just duplicated the functions. The bulk of the difference is now in the plist addition.

@@ -70,6 +70,63 @@ 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<()> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto regarding DRY. it is quite difficult to spot the differences between the three add_plist_to_*_app functions to understand what's different, and it would be easier to maintain this is we could have the common logic shared.

* Added CI tests for watchOS and tvOS
.travis.sh Outdated
Comment on lines 92 to 124
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 test -Zbuild-std pass \
&& ! $CARGO_DINGHY -d $1 -p $2 test -Zbuild-std fails \
&& ! $CARGO_DINGHY -d $1 -p $2 test -Zbuild-std \
)

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This additional function makes test_sequence, tests_sequence_aarch64_ios_sim, and tests_sequence_unstable_target which is pretty gross. Any suggestions?

Comment on lines +38 to +43
Some(AppleSimulatorType::Ios) | Some(AppleSimulatorType::Tvos) | None => {
writeln!(plist, "<key>UIRequiredDeviceCapabilities</key>")?;
writeln!(plist, "<array><string>{}</string></array>", arch)?;
writeln!(plist, "<key>UILaunchStoryboardName</key>")?;
writeln!(plist, "<string></string>")?;
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, these will diverge more I think. Today, I spent a bit of time diving into an audio microphone issue on cpal. I manually added micrphone to the UIRequiredDeviceCapabilities.

It's out of the scope of this PR but it'd be nice to have some possible permission options or maybe a custom Info.plist.

@kali
Copy link
Collaborator

kali commented Feb 22, 2024

OK, I think we're good here. Thanks for working on this and being patient with the review :)

@kali kali merged commit 121354f into sonos:main Feb 22, 2024
6 checks passed
@simlay simlay deleted the add-tvos-and-watchos branch February 22, 2024 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

watchOS simulator support
3 participants