22

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?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
blerontin
  • 2,892
  • 5
  • 34
  • 60

2 Answers2

37

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
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
  • I only looked at `rustup target --help` before, didn't know there is more information to be requested for each sub-command. – blerontin Nov 08 '18 at 15:08
0

Apart of installing a new target described in the answer above, you might also need to setup your new installed target as a default target.

In order to check all available or installed targets you use:

rustup target list

You can also check your default target by executing:

rustup default

If you want to change the default target you can use the following command:

rustup default <YOUR_TARGET_NAME>

for example: rustup default stable-x86_64-pc-windows-msvc

Also if you need to change a default target to your specific directory, you can create a file with name rust-toolchain and include the target name as a content:

stable-x86_64-pc-windows-msvc

enter image description here

ADM-IT
  • 3,719
  • 1
  • 25
  • 26