zdharma-continuum / zinit-annex-rust

Unmaintained mirror of zinit-zsh/z-a-rust
MIT License
3 stars 4 forks source link

"error: no override and no default toolchain" when using global rust #5

Closed twang817 closed 2 years ago

twang817 commented 2 years ago

As I understand it, rustup will install a private rustc and cargo per plugin. I wanted to use a global installation of rust:

zinit wait'0c' for \
    id-as'rust' \
    as'null' \
    sbin'bin/*' \
    rustup \
    atload'
        [[ ! -f "${ZINIT[COMPLETIONS_DIR]}/_cargo" ]] && zi creinstall -q rust
        export CARGO_HOME="$PWD"
        export RUSTUP_HOME="$PWD/rustup"
    ' \
        zdharma-continuum/null \
    ;

zinit wait'0c' for \
    id-as'rust-uq' \
    cargo'!uq' \
        zdharma-continuum/null \
    ;

When running, I get the error:

Downloading zdharma-continuum/null… (at label: rust-uq…)

Cloning into '/Users/Tommy.Wang/.dotfiles/zsh/plugins/rust-uq'...
▎ ███████████ OBJ: 100, PACK: 6/6, COMPR: 100%, REC: 100%
No files for compilation found.
Warning: ∞zinit-compile-plugin-hook hook returned with 1
rust annex: Instaling the requested crates...
+za-rust-atclone-handler:140> which cargo
/Users/Tommy.Wang/.dotfiles/zsh/polaris/bin/cargo
+za-rust-atclone-handler:141> echo RUSTUP_HOME:
RUSTUP_HOME:
+za-rust-atclone-handler:142> echo CARGO_HOME:
CARGO_HOME:
+za-rust-atclone-handler:143> cargo install --force --root /Users/Tommy.Wang/.dotfiles/zsh/plugins/rust-uq uq
error: no override and no default toolchain set
+za-rust-atclone-handler:144> set +x
rust annex: Created the uq shim.

I added some debug:

    (( ${#cargos} )) && {
        if [[ "$hook" = *atclone-<-> ]]; then
            print -P -- "%F{38}rust annex: %F{154}Instaling the requested crates...%f"
            if (( ${+ICE[rustup]} )) {
                local -x CARGO_HOME="$dir" RUSTUP_HOME="$dir/rustup" PATH="$dir/bin:$PATH"
                command $dir/bin/cargo install --force --root "$dir" "${cargos[@]}"
            } else {
                set -x
                which cargo
                echo RUSTUP_HOME: $RUSTUP_HOME
                echo CARGO_HOME: $CARGO_HOME
                cargo install --force --root "$dir" "${cargos[@]}"
                set +x
            }

I think the issue comes from the fact that RUSTUP_HOME and CARGO_HOME are not set for the duration of this script.

I removed the wait'0c' from the first zinit that installs rust globally, and it works again:

◣ ███████████ OBJ: 100, PACK: 6/6, COMPR: 100%, REC: 100%
No files for compilation found.
Warning: ∞zinit-compile-plugin-hook hook returned with 1
rust annex: Instaling the requested crates...
+za-rust-atclone-handler:140> which cargo
/Users/Tommy.Wang/.dotfiles/zsh/polaris/bin/cargo
+za-rust-atclone-handler:141> echo RUSTUP_HOME: /Users/Tommy.Wang/.dotfiles/zsh/plugins/rust/rustup
RUSTUP_HOME: /Users/Tommy.Wang/.dotfiles/zsh/plugins/rust/rustup
+za-rust-atclone-handler:142> echo CARGO_HOME: /Users/Tommy.Wang/.dotfiles/zsh/plugins/rust
CARGO_HOME: /Users/Tommy.Wang/.dotfiles/zsh/plugins/rust
+za-rust-atclone-handler:143> cargo install --force --root /Users/Tommy.Wang/.dotfiles/zsh/plugins/rust-uq uq
    Updating crates.io index
  Installing uq v0.1.2
   Compiling libc v0.2.112
   Compiling unicode-width v0.1.9
   Compiling ansi_term v0.12.1
   Compiling vec_map v0.8.2
   Compiling strsim v0.8.0
   Compiling bitflags v1.3.2
   Compiling textwrap v0.11.0
   Compiling atty v0.2.14
   Compiling clap v2.34.0
   Compiling uq v0.1.2
    Finished release [optimized] target(s) in 12.39s
  Installing /Users/Tommy.Wang/.dotfiles/zsh/plugins/rust-uq/bin/uq
   Installed package `uq v0.1.2` (executable `uq`)
warning: be sure to add `/Users/Tommy.Wang/.dotfiles/zsh/plugins/rust-uq/bin` to your PATH to be able to run the installed binaries
+za-rust-atclone-handler:144> set +x
rust annex: Created the uq shim.
twang817 commented 2 years ago

Also, noticed that this works too:

zinit wait'[[ -v CARGO_HOME && -v RUSTUP_HOME ]]' for \
    id-as'rust-uq' \
    cargo'!uq' \
        zdharma-continuum/null \
    ;
twang817 commented 2 years ago

After some consideration, I think this should be closed as not a bug -- but I think an addition to the README.md is worthwhile.