Target not supported but in list of supported targets

I'm trying to install the aarch64-apple-watchos and aarch64-apple-watchos-sim targets but when running rustup target add aarch64-apple-watchos I get the following error:

error: toolchain 'stable-aarch64-apple-darwin' does not support target 'aarch64-apple-watchos'
note: you can see a list of supported targets with `rustc --print=target-list`
note: if you are adding support for a new target to rustc itself, see https://rustc-dev-guide.rust-lang.org/building/new-target.html

But when I run rustc --print=target-list as it suggested, both aarch64-apple-watchos and aarch64-apple-watchos-sim are listed. So if they are in the list of supported targets, why does rustup say that that aren't when I try adding them?

Confusion about word “target”.

For a compiler “target” is “something I'm generating code for”.

For a rustup “target” is “something I'm installing compiler for”. For the compiler that wouldn't be “target”, for a compiler that would be “host”.

Because aarch64-apple-watchos is supported by Rust as target for the compiler compiler but not as host for the compiler you couldn't install native toolchain with rustup.

Rustc clearly explains that there are no toolchain for iOS, you may only cross-compile.

The *-apple-watchos target says the same "These targets are cross-compiled.".

In the chapter on Cross-Compilation in the Rustup Book is says "To compile to other platforms you must install other target platforms. This is done with the rustup target add command.".

Since I need to cross-compile, this is what I tried but it failed. Is there another way to cross compile that I've missed?

Sure. Just do that. Ensure that that you have Xcode with watchOS support and enabled with obvious

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

Then it should just work. At least it works for me:

$ cargo new hellowatch
    Creating binary (application) `hellowatch` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-------------------------------------------------------------------------------------------------------------------------------------------------------------
$ cd hellowatch
-------------------------------------------------------------------------------------------------------------------------------------------------------------
$ cargo build -Zbuild-std --target=arm64_32-apple-watchos
   Compiling compiler_builtins v0.1.109
   Compiling core v0.0.0 (/Users/khim/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core)
   Compiling libc v0.2.155
   Compiling memchr v2.5.0
   Compiling std v0.0.0 (/Users/khim/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std)
   Compiling rustc-std-workspace-core v1.99.0 (/Users/khim/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-co
re)
   Compiling alloc v0.0.0 (/Users/khim/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc)
   Compiling cfg-if v1.0.0
   Compiling adler v1.0.2
   Compiling rustc-demangle v0.1.24
   Compiling unwind v0.0.0 (/Users/khim/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/unwind)
   Compiling rustc-std-workspace-alloc v1.99.0 (/Users/khim/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-a
lloc)
   Compiling panic_abort v0.0.0 (/Users/khim/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/panic_abort)
   Compiling panic_unwind v0.0.0 (/Users/khim/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/panic_unwind)
   Compiling gimli v0.29.0
   Compiling hashbrown v0.14.5
   Compiling object v0.32.2
   Compiling std_detect v0.1.5 (/Users/khim/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/stdarch/crates/std_detect)
   Compiling miniz_oxide v0.7.3
   Compiling addr2line v0.22.0
   Compiling proc_macro v0.0.0 (/Users/khim/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/proc_macro)
   Compiling hellowatch v0.1.0 (/Users/khim/YACE/test/hellowatch)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 22.85s

That is not true. rustup target add installs the standard library of a given target to the current compiler toolchain. It doesn't install a new toolchain with a different host triple. For that you did have to use something like rustup toolchain install --force-non-host <toolchain-name>-<target>. The latter command is generally not really useful as your host likely isn't able to run rustc binaries compiled for a different target.

The issue here is that aarch64-apple-watchos is a tier 3 target, which means no precompiled standard library is available. As such -Zbuild-std is required instead.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.