Cannot install target with rustup-init but can add later

Hi All,

If I run

./rustup-init -y --no-modify-path --profile minimal \
    --default-toolchain $RUST_VERSION \
    --default-host armv7-linux-androideabi

it fails with error: target 'armv7-linux-androideabi' not found in channel.

But I can run

./rustup-init -y --no-modify-path --profile minimal \
    --default-toolchain $RUST_VERSION

rustup target add armv7-linux-androideabi

and it succeeds.

I tried a bunch of different RUST_VERSIONs, stable and nightly alike.

What gives?

[EDIT] I am running this on an amd64 host, i.e. I'm setting up a toolchain for cross-compilation.

there's no toolchain for android hosts, they are all tier 2 without host tools. you can only cross compile to these platforms. see the list:

https://doc.rust-lang.org/nightly/rustc/platform-support.html#tier-2-without-host-tools

https://doc.rust-lang.org/nightly/rustc/platform-support/android.html

Instead of --default-host use --target:

./rustup-init -y --no-modify-path --profile minimal \
    --default-toolchain $RUST_VERSION \
    --target armv7-linux-androideabi

Thank you for the reply.

I've read those pages, but apparently I do not understand what that means and how toolchains fall together.

I am only beginning to experiment with android builds, but previously I used to rustup target add arm7-unknown-linux-gnueabihf (another Tier 2 target) while running on amd64 and was able to build for that target just like I do for native, cross-compiling handled transparently by cargo and rustc.

From your answer I gather that if I wanted to install arm7-unknown-linux-gnueabihf as the only toolchain, I would have failed, just like with android. But why? What would be missing?

Is it because a native toolchain is always needed to compile procedural macros?

The Platform Support page mentions this as the distinction of targets with host tools:

Tier X targets with host tools additionally support running tools like rustc and cargo natively on the target

but that's not what I am trying to do.

[EDIT] Sorry, I only now realized that I've omitted this piece of information from my question: I'm setting up a cross-compilation toolchain on an amd64 host, not running rustup-init on Android.

Thank you, indeed this works!

The end result is the same as my two-step process though: I end up both with a native toolchain and the android toolchain.

Still, it's an improvement.

Yes. Proc macro must be compiled for host architecture which means you need toolchain which can do that.

Sometimes you may even have a choice: I can use aarch64-apple-darwin as my main toolchain or x86_64-apple-darwin but obviously Android toolchain couldn't be the main one (except if you are using Android for development).

Thanks, this makes sense.

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.