Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install a Rust target for a specific rustup toolchain?

I am using rustc and cargo on my 64-bit Windows machine to compile a 32-bit application. This work fine when using the stable toolchain, but when I try to use the beta toolchain it fails.

The beta toolchain was successfully installed with rustup install beta. In the project folder there is a .cargo/config file containing the following lines:

[build]
target = "i686-pc-windows-msvc"

[target.i686-pc-windows-msvc]
rustflags = ["-Ctarget-feature=+crt-static"]

When running cargo +beta build the following error occurs:

error[E0463]: can't find crate for `core`
  |
  = note: the `i686-pc-windows-msvc` target may not be installed

I have tried running rustup target add i686-pc-windows-msvc to fix the issue but it didn't help; rustup target list even displays it as "installed". Possibly this command only adds the target for stable, and I couldn't find out how to specify the beta toolchain.

How can I add another (non-default) target for the beta toolchain?

like image 739
blerontin Avatar asked Nov 08 '18 14:11

blerontin


People also ask

What is Rustup toolchain?

rustup is a toolchain multiplexer. It installs and manages many Rust toolchains and presents them all through a single set of tools installed to ~/. cargo/bin . The rustc and cargo executables installed in ~/. cargo/bin are proxies that delegate to the real toolchain.

Where is Rust toolchain installed?

In the Rust development environment, all tools are installed to the ~/. cargo/bin. directory, and this is where you will find the Rust toolchain, including rustc , cargo , and rustup . Accordingly, it is customary for Rust developers to include this directory in their PATH environment variable.

Does Rust require Msvc?

No additional software installation is necessary for basic use of the GNU build. By default rustup on Windows configures Rust to target the MSVC ABI, that is a target triple of either i686-pc-windows-msvc , x86_64-pc-windows-msvc , or aarch64-pc-windows-msvc depending on the CPU architecture of the host Windows OS.

What does Rustup install?

Rustup can be used to install Rust and keep it updated. It also allows you to seamlessly switch between the stable, beta, and nightly Rust compilers and tooling.


1 Answers

Read the help for rustup target add:

$ rustup target add --help
rustup-target-add
Add a target to a Rust toolchain

USAGE:
    rustup target add [OPTIONS] <target>...

FLAGS:
    -h, --help    Prints help information

OPTIONS:
        --toolchain <toolchain>    Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
                                   `rustup help toolchain`

Thus you want:

rustup target add i686-pc-windows-msvc --toolchain beta

I believe it will add the target to the "current" toolchain by default, so you could also do:

rustup override set beta               # in your project directory
rustup target add i686-pc-windows-msvc #
cargo build                            # no more +beta

rustup target list even displays it as "installed"

Read the help for rustup target list:

$ rustup target list --help
rustup-target-list
List installed and available targets

USAGE:
    rustup target list [OPTIONS]

FLAGS:
    -h, --help    Prints help information

OPTIONS:
        --toolchain <toolchain>    Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
                                   `rustup help toolchain`

Thus you want:

rustup target list --toolchain beta
like image 83
Shepmaster Avatar answered Sep 19 '22 15:09

Shepmaster