Making rustfmt available in a custom toolchain

I have built a custom toolchain with a fairly standard config.toml. Its diff from the example config is this:

> diff config.toml.example config.toml
152c152
< #build-stage = 1
---
> build-stage = 2
186c186
< #target = ["x86_64-unknown-linux-gnu"]
---
> target = ["x86_64-apple-darwin", "x86_64-apple-ios-macabi"]
253c253
< #extended = false
---
> extended = true
258a259
> tools = ["cargo", "rls", "clippy", "rustfmt", "analysis", "src"]
392c393
< #debug-logging = rust.debug-assertions (boolean)
---
> debug-logging = true

I have built the toolchain with ./x.py build and it seems to have built everything I need.

~/code/rust/build/x86_64-apple-darwin > ls stage2/bin
 rustc   rustdoc
~/code/rust/build/x86_64-apple-darwin > ls stage2-tools-bin/
 cargo   cargo-credential-1password   cargo-credential-macos-keychain   clippy-driver   rls   rustfmt

I've linked this toolchain with ~/code/rust > rustup toolchain link myrust build/x86_64-apple-darwin/stage2, set it in my other project with rustup override set myrust, and tried to build it with cargo build --target x86_64-apple-ios-macabi

It gets farther than my previous attempts, but I get the following error while the build script gets run (trying to process gRPC proto files):

> cargo build --target x86_64-apple-ios-macabi
   Compiling hkrpc v0.1.0 (/Users/shaheen/code/hkserver)
   Compiling tonic v0.3.1
error: failed to run custom build command for `hkrpc v0.1.0 (/Users/shaheen/code/hkserver)`

Caused by:
  process didn't exit successfully: `/Users/shaheen/code/hkserver/target/debug/build/hkrpc-b73f14790ba0dcbe/build-script-build` (exit code: 1)
  --- stderr
  error: 'rustfmt' is not installed for the toolchain 'myrust'
  To install, run `rustup component add rustfmt --toolchain myrust`
warning: build failed, waiting for other jobs to finish...
error: build failed

How do I make rustfmt visible as part of the toolchain?

Did you try

rustup component add rustfmt --toolchain myrust

as shown in your errors?

that doesn’t work for a custom toolchain, though i did not notice/try the —toolchain option. will try that next.

I think you will need to use ./x.py install and then use rustup toolchain link for the installation dir. You can choose the installation location using the prefix option in the [install] section of config.toml.

note for the suggestion to specify --toolchain: it fails with error: myrust is a custom toolchain

installing the toolchain to a temporary location did work, though. thank you!

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.