-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustc
cannot find crate if different target is used
#116562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Same behavior observed with |
The proc-macro must be compiled with the same target as the host |
@ehuss if I understand it correctly proc-macro is host library then? That is quite confusing I'd say. How would projects handle it correctly? If there's no option to pass "host triplet" I'd say it would be better to ignore |
Yes, the proc-macro is loaded into the compiler as a shared library, so it must match the same architecture. I recommend not passing |
It's all done through |
More broadly in a cross compilation workflow a proc macro should be built for the native (build) platform rather than the cross (host) one, which means that its rustc compiler must be defined in native mode. This should be fixed by meson in mesonbuild/meson#11714 which forced proc-macro to always be compiled as native, but it does require defining the native/cross platforms in the compilation environment which may be a contributing factor here. |
proc-macro is used directly by a host compiler so during its compilation target should match host triplet see: rust-lang/rust#116562 the easiest way to achieve this is to skip --target entirely as by default it will produce artifact matching host. since meson upstream prefers to use full blown cross-compilation for tiers without host tools: mesonbuild/meson#12353 let's patch meson ourselves for convinience to avoid it
I have a self build of
rust 1.73.0
onARM/Linux
configured to include two targets:armv7-unknown-linux-gnueabihf
(Tier 2 with host tools)thumbv7neon-unknown-linux-gnueabihf
(Tier 2 without host tools)When building recent
Mesa 23.2.1
for the latter target I've hit a build issue due to missing crate. The reduced reproducer is:my_proc_macros.rs
:lib.rs
:my_proc_macros.rs
is compiled to shared object:rustc --edition=2021 --crate-type proc-macro --target thumbv7neon-unknown-linux-gnueabihf --crate-name my_proc_macros -o libmy_proc_macros.so -C prefer-dynamic my_proc_macros.rs
while the
lib.rs
is compiled to static lib with use of above my_proc_macros:rustc --edition=2021 --crate-type staticlib --target thumbv7neon-unknown-linux-gnueabihf --crate-name app -o lib.a --extern my_proc_macros=libmy_proc_macros.so lib.rs
The latter errors out with:
However if I substitute target
thumbv7neon-unknown-linux-gnueabihf
witharmv7-unknown-linux-gnueabihf
all builds fine.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: