Skip to content

Commit bfe97b2

Browse files
committed
[PM-29567] Fix dylint by putting the real dylint-link on PATH
cargo-dylint invokes dylint-link as rustc's linker, found by name on PATH. Running it via `cargo bin cargo-dylint` fails: cargo-run-bin prepends a shim directory to PATH, and the dylint-link shim re-runs `cargo bin dylint-link`, which resolves the project root from the current directory. During linking the cwd is inside support/lints or a dependency's source dir, none of which declare [workspace.metadata.bin], so the shim fails with "No binaries configured". Build the tools and invoke the cargo-dylint binary directly with the real dylint-link binary on PATH (via an absolute path, so it resolves regardless of which directory cargo-dylint links from). Build only the two tools dylint needs rather than `cargo bin --install`, which builds every pinned tool including some that don't compile on this toolchain (e.g. cross).
1 parent e178b73 commit bfe97b2

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

scripts/lint.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,32 @@ run_udeps() {
100100

101101
run_dylint() {
102102
require_cargo_bin
103-
cargo bin cargo-dylint --all -- --all-features --all-targets
103+
# cargo-dylint invokes `dylint-link` as rustc's linker, found by name on PATH.
104+
# Running cargo-dylint through `cargo bin` doesn't work: cargo-run-bin prepends
105+
# a shim directory to PATH whose dylint-link shim re-runs `cargo bin
106+
# dylint-link`, which fails from the directories rustc links in (support/lints
107+
# and each dependency's source dir, none of which declare
108+
# [workspace.metadata.bin]). So build the tools and invoke cargo-dylint
109+
# directly with the real dylint-link binary on PATH, using an absolute path so
110+
# it resolves no matter which directory cargo-dylint links from.
111+
#
112+
# Build only the two tools dylint needs rather than `cargo bin --install`,
113+
# which builds every pinned tool (including some that don't compile on this
114+
# toolchain, e.g. cross). `cargo bin` builds a tool on first use; the throwaway
115+
# invocations below just trigger those builds (dylint-link has no safe no-op
116+
# invocation, so its run is allowed to fail; the builds are verified by the
117+
# `find`s that follow).
118+
cargo bin cargo-dylint --help >/dev/null
119+
cargo bin dylint-link --help >/dev/null 2>&1 || true
120+
121+
local cargo_dylint dylint_link
122+
cargo_dylint="$(find "$REPO_ROOT/.bin" -type f -name cargo-dylint -not -path '*/.shims/*' -print -quit)"
123+
dylint_link="$(find "$REPO_ROOT/.bin" -type f -name dylint-link -not -path '*/.shims/*' -print -quit)"
124+
if [[ -z "$cargo_dylint" || -z "$dylint_link" ]]; then
125+
echo "Could not find cargo-dylint/dylint-link under .bin (build failed?)" >&2
126+
exit 1
127+
fi
128+
PATH="$(dirname "$dylint_link"):$PATH" "$cargo_dylint" dylint --all -- --all-features --all-targets
104129
}
105130

106131
run_doc() {

0 commit comments

Comments
 (0)