Skip to content

Updated get_toolchain, it now retrieves active toolchain.#124

Open
ateraz13 wants to merge 1 commit into
emacs-rustic:mainfrom
ateraz13:main
Open

Updated get_toolchain, it now retrieves active toolchain.#124
ateraz13 wants to merge 1 commit into
emacs-rustic:mainfrom
ateraz13:main

Conversation

@ateraz13

Copy link
Copy Markdown

As per this issue, this pull requests updates the function which retrieves the active toolchain name as the previous approach is now outdated.

@mcklatz

mcklatz commented Jul 4, 2026

Copy link
Copy Markdown

Hi! What status of this PR, could you merge it?

@mcklatz

mcklatz commented Jul 4, 2026

Copy link
Copy Markdown

One issue with the current approach, plus a suggestion for a more
robust fix.

The current diff can double-output on older rustup

function get_toolchain {
    rustup show | sed -nr 's/(.*) \(default\)/\1/p' | head -n 1
    rustup show active-toolchain | awk '{print $1}'
}

If we keep the rustup-based approach, the old line should be replaced, I guess, like:

function get_toolchain {
    rustup show active-toolchain | awk '{print $1}'
}

But I guess better way try to resolve via rustc --print sysroot and skip parsing entirely

 LUA_FILTER="$HOME/.local/bin/rustic-doc-filter.lua"
-function get_toolchain {
-    rustup show | sed -nr 's/(.*) \(default\)/\1/p' | head -n 1
-}

 if [ "$1" = "" ] || [ "$1" = "--help"  ]; then
     MY_NAME="$(basename "$0")"
@@
 if [ "$DEST_DIR" = "" ]; then
     LIBRARY="$1"
-    TARGET="$(get_toolchain)"
-
-    ## Users can change the location of the rustup directory
-    RUSTUP_HOME="${RUSTUP_HOME:-$HOME/.rustup}"
-    ## Set
-    DOC_PATH="$RUSTUP_HOME/toolchains/$TARGET/share/doc/rust/html/$LIBRARY"
+
+    ## Resolve the active toolchain's documentation directory directly via
+    ## rustc.  This avoids parsing `rustup show` (whose output format changed:
+    ## the default toolchain is now tagged "(active, default)" instead of
+    ## "(default)") and also works for rustup-less, distro-packaged Rust.
+    SYSROOT="$(rustc --print sysroot)"
+    if [ -z "$SYSROOT" ]; then
+        echo "rustic-doc: could not determine rustc sysroot; is rustc on PATH?" >&2
+        exit 1
+    fi
+    DOC_PATH="$SYSROOT/share/doc/rust/html/$LIBRARY"
     DEST_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/emacs/rustic-doc/$LIBRARY"

     echo "Generating org files in: $DEST_DIR"
 fi

I could to open this as an alternative commit if you'd prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants