Skip to content

Commit 773d1ea

Browse files
authored
tc-rust.mk: Fix Rust target detection by moving checks to runtime (#6919)
Rust toolchain and target availability were previously evaluated using Makefile conditionals (ifeq), which are resolved at parse time and do not reflect runtime changes made by rustup commands. This caused incorrect behavior for non-standard Rust toolchains (e.g. qoriq), where the default rustup toolchain does not support the requested target (powerpc-unknown-linux-gnuspe), yet the Make logic still attempted to add it. The logic has been corrected by performing rustup toolchain and target availability checks at runtime in the shell, ensuring that targets are only added when supported by the selected Rust toolchain and avoiding invalid rustup invocations.
1 parent 9c51979 commit 773d1ea

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

mk/spksrc.tc-rust.mk

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,20 @@ rustc_target: $(PRE_RUSTC_TARGET) $(TC_LOCAL_VARS_RUST)
103103
$(MSG) "rustup default $(RUSTUP_DEFAULT_TOOLCHAIN)" ; \
104104
rustup default $(RUSTUP_DEFAULT_TOOLCHAIN) ; \
105105
flock -u 5
106-
ifeq ($(TC_RUSTUP_TOOLCHAIN),$(RUSTUP_DEFAULT_TOOLCHAIN))
107-
@$(MSG) "rustup target add $(RUST_TARGET)"
108-
rustup override set $(RUSTUP_DEFAULT_TOOLCHAIN)
109-
rustup target add $(RUST_TARGET)
110-
rustup show
111-
else
112-
@$(MSG) "Target $(RUST_TARGET) unavailable..."
106+
@$(MSG) "Checking Rust target $(RUST_TARGET) availability"
107+
@if rustup target list --toolchain $(TC_RUSTUP_TOOLCHAIN) 2>/dev/null | grep -q "^$(RUST_TARGET) (installed)" ; then \
108+
$(MSG) "Rust target already installed for $(TC_RUSTUP_TOOLCHAIN)" ; \
109+
rustup show ; \
110+
elif rustup target list --toolchain $(TC_RUSTUP_TOOLCHAIN) 2>/dev/null | grep -q "^$(RUST_TARGET)" ; then \
111+
$(MSG) "Installing Rust target $(RUST_TARGET) for $(TC_RUSTUP_TOOLCHAIN)" ; \
112+
$(MSG) "rustup override set $(RUSTUP_DEFAULT_TOOLCHAIN)" ; \
113+
rustup override set $(RUSTUP_DEFAULT_TOOLCHAIN) ; \
114+
$(MSG) "rustup target add $(RUST_TARGET)" ; \
115+
rustup target add $(RUST_TARGET) ; \
116+
rustup show ; \
117+
else \
118+
$(MSG) "Target $(RUST_TARGET) unavailable for $(TC_RUSTUP_TOOLCHAIN)" ; \
119+
fi
113120
ifeq ($(RUST_BUILD_TOOLCHAIN),1)
114121
@$(MSG) "Build rust target $(RUST_TARGET) from sources"
115122
@$(MSG) "Building Tier-3 rust target: $(RUST_TARGET)"
@@ -133,7 +140,6 @@ endif
133140
@$(MSG) "Building Tier 3 rust target: $(RUST_TARGET) - stage$(RUSTUP_DEFAULT_TOOLCHAIN_STAGE) complete"
134141
rustup show
135142
endif
136-
endif
137143

138144
post_rustc_target: $(RUSTC_TARGET)
139145

0 commit comments

Comments
 (0)