Skip to content

Commit b30c1b5

Browse files
committed
Document how to test with iOS/tvOS/watchOS/visionOS simulator
1 parent be01d87 commit b30c1b5

File tree

5 files changed

+51
-41
lines changed

5 files changed

+51
-41
lines changed

src/doc/rustc-dev-guide/src/tests/running.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,34 @@ results. The Docker image is set up to launch `remote-test-server` and the
339339
build tools use `remote-test-client` to communicate with the server to
340340
coordinate running tests (see [src/bootstrap/src/core/build_steps/test.rs]).
341341

342-
> **TODO**
343-
>
344-
> - Is there any support for using an iOS emulator?
342+
To run on the iOS/tvOS/watchOS/visionOS simulator, we can similarly treat it as
343+
a "remote" machine. A curious detail here is that the network is shared between
344+
the simulator instance and the host macOS, so we can use the local loopback
345+
address `127.0.0.1`. Something like the following should work:
346+
347+
```sh
348+
# Build the test server for the iOS simulator:
349+
./x build src/tools/remote-test-server --target aarch64-apple-ios-sim
350+
351+
# If you already have a simulator instance open, copy the device UUID from:
352+
xcrun simctl list devices booted
353+
UDID=01234567-89AB-CDEF-0123-456789ABCDEF
354+
355+
# Alternatively, create and boot a new simulator instance:
356+
xcrun simctl list runtimes
357+
xcrun simctl list devicetypes
358+
UDID=$(xcrun simctl create $CHOSEN_DEVICE_TYPE $CHOSEN_RUNTIME)
359+
xcrun simctl boot $UDID
360+
# See https://nshipster.com/simctl/ for details.
361+
362+
# Spawn the runner on port 12345:
363+
xcrun simctl spawn $UDID ./build/host/stage2-tools/aarch64-apple-ios-sim/release/remote-test-server -v --bind 127.0.0.1:12345
364+
365+
# In a new terminal, run tests via the runner:
366+
export TEST_DEVICE_ADDR="127.0.0.1:12345"
367+
./x test --host='' --target aarch64-apple-ios-sim --skip tests/debuginfo
368+
# FIXME(madsmtm): Allow debuginfo tests to work (maybe needs `.dSYM` folder to be copied to the target?).
369+
```
345370

346371
[armhf-gnu]: https://github.com/rust-lang/rust/tree/master/src/ci/docker/host-x86_64/armhf-gnu/Dockerfile
347372
[QEMU]: https://www.qemu.org/

src/doc/rustc/src/platform-support/apple-ios.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,19 @@ Rust programs can be built for these targets by specifying `--target`, if
6666
$ rustc --target aarch64-apple-ios your-code.rs
6767
```
6868

69+
Or if using Cargo and `-Zbuild-std`:
70+
```console
71+
$ cargo +nightly build -Zbuild-std --target armv7s-apple-ios
72+
```
73+
6974
The simulator variants can be differentiated from the variants running
7075
on-device with the `target_env = "sim"` cfg (or `target_abi = "sim"` before
7176
Rust CURRENT_RUSTC_VERSION).
7277

7378
```rust
7479
if cfg!(all(target_vendor = "apple", target_env = "sim")) {
7580
// Do something on the iOS/tvOS/visionOS/watchOS Simulator.
76-
} {
81+
} else {
7782
// Everything else, like Windows and non-Simulator iOS.
7883
}
7984
```
@@ -82,8 +87,15 @@ This is similar to the `TARGET_OS_SIMULATOR` define in C code.
8287

8388
## Testing
8489

85-
There is no support for running the Rust or standard library testsuite at the
86-
moment. Testing has mostly been done manually with builds of static libraries
87-
embedded into applications called from Xcode or a simulator.
90+
Running and testing your code naturally requires either an actual device
91+
running iOS, or the equivalent Xcode simulator environment. There exists
92+
several tools in the ecosystem for running a Cargo project on one of these.
93+
One of these tools is [`cargo-dinghy`]. [madsmtm/objc2#459] contains a more
94+
exhaustive list.
95+
96+
See also [testing on emulators in the `rustc-dev-guide`][test-sim] for
97+
instructions on running the standard library's test suite.
8898

89-
It hopefully will be possible to improve this in the future.
99+
[`cargo-dinghy`]: https://github.com/sonos/dinghy
100+
[madsmtm/objc2#459]: https://github.com/madsmtm/objc2/issues/459
101+
[test-sim]: https://rustc-dev-guide.rust-lang.org/tests/running.html#testing-on-emulators

src/doc/rustc/src/platform-support/apple-tvos.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,8 @@ Using the unstable `-Zbuild-std` with a nightly Cargo may also work.
6565

6666
## Building Rust programs
6767

68-
Rust programs can be built for these targets by specifying `--target`, if
69-
`rustc` has been built with support for them. For example:
70-
71-
```console
72-
$ rustc --target aarch64-apple-tvos your-code.rs
73-
```
68+
See [the instructions for iOS](./apple-ios.md#building-rust-programs).
7469

7570
## Testing
7671

77-
There is no support for running the Rust or standard library testsuite at the
78-
moment. Testing has mostly been done manually with builds of static libraries
79-
embedded into applications called from Xcode or a simulator.
80-
81-
It hopefully will be possible to improve this in the future.
72+
See [the instructions for iOS](./apple-ios.md#testing).

src/doc/rustc/src/platform-support/apple-visionos.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,11 @@ be fixed in [#124560](https://github.com/rust-lang/rust/pull/124560).
4646

4747
## Building Rust programs
4848

49-
Rust programs can be built for these targets by specifying `--target`, if
50-
`rustc` has been built with support for them. For example:
51-
52-
```console
53-
$ rustc --target aarch64-apple-visionos-sim your-code.rs
54-
```
49+
See [the instructions for iOS](./apple-ios.md#building-rust-programs).
5550

5651
## Testing
5752

58-
There is no support for running the Rust or standard library testsuite at the
59-
moment. Testing has mostly been done manually with builds of static libraries
60-
embedded into applications called from Xcode or a simulator.
61-
62-
It hopefully will be possible to improve this in the future.
53+
See [the instructions for iOS](./apple-ios.md#testing).
6354

6455
## Cross-compilation toolchains and C code
6556

src/doc/rustc/src/platform-support/apple-watchos.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,8 @@ Using the unstable `-Zbuild-std` with a nightly Cargo may also work.
5050

5151
## Building Rust programs
5252

53-
Rust programs can be built for these targets by specifying `--target`, if
54-
`rustc` has been built with support for them. For example:
55-
56-
```console
57-
$ rustc --target aarch64-apple-watchos-sim your-code.rs
58-
```
53+
See [the instructions for iOS](./apple-ios.md#building-rust-programs).
5954

6055
## Testing
6156

62-
There is no support for running the Rust or standard library testsuite at the
63-
moment. Testing has mostly been done manually with builds of static libraries
64-
embedded into applications called from Xcode or a simulator.
65-
66-
It hopefully will be possible to improve this in the future.
57+
See [the instructions for iOS](./apple-ios.md#testing).

0 commit comments

Comments
 (0)