Skip to content

cli: replay hotpatch links with the env rustc gave the linker - #5850

Open
aron-intframe wants to merge 1 commit into
DioxusLabs:mainfrom
aron-intframe:cli/capture-linker-env
Open

aron-intframe wants to merge 1 commit into
DioxusLabs:mainfrom
aron-intframe:cli/capture-linker-env

Conversation

@aron-intframe

Copy link
Copy Markdown

Fixes #4911

Description

dx serve --hot-patch replays the fat/thin link with env_clear() plus the env captured by the rustc wrapper. But rustc gives its linker child vars the rustc process never has: on windows LIB/INCLUDE/PATH from find_msvc_tools (rustc_codegen_ssa/back/linker.rs, get_linker), plus the sysroot tool dirs on PATH and LC_ALL/VSLANG. Outside a VS developer prompt LIB only exists there, so the replayed rust-lld can't open kernel32.lib. Inside the prompt LIB is in the shell env, so the wrapper captured it by accident.

This captures std::env::vars() in the linker interception next to the link args (link_env.json, DX_LINK_ENV_FILE) and prefers it for the replay. The linux-only PATH re-add stays as the fallback for caches without a capture.

Measured on linux with rustc 1.97.1 calling the patched dx as -Clinker: the captured env has LC_ALL=C, VSLANG=1033 and two rustlib/<host>/bin entries on PATH that the wrapper env lacks. No windows host here, so not verified end to end; the windows playwright hotpatch job is the real check.

User-Facing Changes

dx serve --hot-patch should work from a regular terminal on windows. One more file in the session cache.

Tests

3 unit tests in build/link.rs (replay prefers the captured env, fallback without one, file round trip); the first fails with the old behaviour. cargo test -p dioxus-cli --bin dx 164/164, fmt clean, clippy unchanged.

…ioxusLabs#4911)

rustc hands its linker child env vars the rustc process itself never has:
`LIB`/`INCLUDE`/`PATH` from MSVC tool discovery on windows, the sysroot tool
dirs on `PATH`, `LC_ALL`/`VSLANG`. dx replayed fat/thin links with the env
captured by the rustc wrapper, so outside a VS developer prompt `LIB` was
missing and rust-lld could not open `kernel32.lib` and friends.

Capture `std::env::vars()` in the linker interception next to the link args
(`link_env.json`, `DX_LINK_ENV_FILE`) and prefer it when replaying. The
linux-only `PATH` patch stays as the fallback for caches without a capture.

This branch has not been deployed

No deployments
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.

dx serve --hot-patch on Windows 11 cannot generate binary outside of VS command prompt

1 participant