Skip to content

Follow symlinks when scanning the sysroot for proc-macro dylibs - #23297

Merged
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
onlycs:follow-symlinks-proc-macro-dylibs
Sep 5, 2026
Merged

Follow symlinks when scanning the sysroot for proc-macro dylibs#23297
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
onlycs:follow-symlinks-proc-macro-dylibs

Conversation

@onlycs

@onlycs onlycs commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Problem

With a nix toolchain, every macro-generated TyCtxt query getter (tcx.mir_keys(()), e.g.) resolves to {unknown}. Three independent bugs cause this, one of which was fixed in 7015591, one with #23296, and one in this PR

symlinked proc-macro dylibs are skipped

WorkspaceBuildScripts::rustc_crates scans the target libdir for the prebuilt proc-macro dylibs (librustc_macros.so & co.) using DirEntry::file_type(), which does not follow symlinks. Nix sysroots symlink every file into place, so all dylibs were filtered out. Without rustc_macros, rustc_queries! never expands, the generated rustc_with_all_queries macro doesn't exist, and none of define_callbacks!'s output (those macro-generated query getters) is ever created.

The fix here was to just use fs::metadata which traverses symlinks.

AI disclosure

These changes were authored with AI assistance (Claude Code); the commits carry Co-Authored-By trailers. I have reviewed the changes, use them in a current project using a patched build, and can answer questions about them myself.

See also: #23251

Version Info

cargo: cargo 1.99.0-nightly (eb98b54bc 2026-08-11)

Toolchain: nightly-2026-08-14, components rustc-dev, llvm-tools-preview, rust-src.

Configuration (Zed, .zed/settings.json):

{
  "lsp": {
    "rust-analyzer": {
      "initialization_options": {
        "rustc": {
          "source": "discover"
        }
      }
    }
  }
}

The scan of the target libdir for rustc_macros & co. used
DirEntry::file_type(), which does not follow symlinks. Toolchains
assembled out of symlinks (e.g. by nix / oxalica's rust-overlay) link
every dylib into the sysroot, so all proc-macro dylibs were skipped. As a
result `rustc_queries!` never expanded for rustc_private projects and the
macro-generated TyCtxt query getters (`tcx.mir_keys(())` etc.) did not
resolve at all.

Use fs::metadata, which traverses symlinks, instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 4, 2026

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChayimFriedman2
ChayimFriedman2 added this pull request to the merge queue Sep 5, 2026
Merged via the queue into rust-lang:master with commit d81240f Sep 5, 2026
19 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 5, 2026
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.

3 participants