-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
cannot produce proc-macro when --target
is set on musl host toolchain
#7563
Comments
Fix building proc-macro crates on musl host when --target is specified.
AFAIK, rustc musl host fundamentally does not support proc-macros. Some more information may be found at rust-lang/rust#40174. |
Musl target does support proc-macros. The issue here is proc-macros are dylibs and Rust doesn't support linking dylibs to static CRT on targets other than Windows. Historically musl target links static CRT by default so one has to disable it with |
Oh, I think I see. I've never been able to get rustc musl to work on any system. Do you know, is there any information on how to get it to work? Whatever I've tried, I get all sorts of errors (symbol not found, |
@ehuss you need musl compiler (
You have probably installed musl host toolchain on glibc based linux, it's possible to run it there but sketchy. You'd have more luck running it on Alpine Linux or musl variant Void Linux. Slightly offtopic but I want you to understand what is going on: I don't know how to fix it, generally proc-macros always have to be compiled dynamically for host assuming it supports dylibs. Probably this has to be fixed in rustc itself but I don't remember that code well enough to tell for sure. |
On a fresh install of Alpine Linux, I get the exact same errors as other distros trying to run I just tried with the latest nightly, with the same result. Any ideas what I'm missing? This is using rustup to install. Do I need to install a special package? Are there dependencies I need to install? |
Maybe a bit overkill but installing
Using container in Docker/Podman is enough to try it BTW. |
Ah, adding |
Just ran into this and want to make sure I'm understanding this correctly -- it sure seems like it's impossible to build a static binary (or at least the closest we can get to it on linux w/ musl) if you have any dependency that uses macros? It seems like the only workaround is to dynamically link |
You don't need to use a MUSL host toolchain to target MUSL. |
~/.cargo/config OR |
Thanks @paul-sedun/@sfackler Maybe I wasn't clear about my misunderstanding -- it wasn't whether you needed musl installed or how to specifically to do it, but more about the fact if you choose to do use I'm going directly off what @mati865 said (reproduced below):
If I'm reading this correctly, then it means that at the moment Rust cannot generate the closest thing we have to a static binary on linux if the project being built uses macros. [EDIT] - Just trying to make sure this is clear but I'm not trying to slight rust here, just want to make sure that I arrived at the right conclusion. |
Compiling binary dynamically linked to musl on musl host (need RUSTFLAGS set) or binary statically linked to musl on glibc host will works. |
Thank you for the explanation, I think I understand now! |
…=nagisa,smaeul Don't use static crt by default when build proc-macro Don't check value of `crt-static` when build proc-macro crates, since they are always built dynamically. For more information, see rust-lang/cargo#7563 (comment) I hope this will fix issues about compiling `proc_macro` crates on musl host without bring more issues. Note: I can't test this on my musl host locally, because I encounter this issue when bootstraping from a beta snapshot. Fix rust-lang/cargo#7563
…=nagisa,smaeul Don't use static crt by default when build proc-macro Don't check value of `crt-static` when build proc-macro crates, since they are always built dynamically. For more information, see rust-lang/cargo#7563 (comment) I hope this will fix issues about compiling `proc_macro` crates on musl host without bring more issues. Note: I can't test this on my musl host locally, because I encounter this issue when bootstraping from a beta snapshot. Fix rust-lang/cargo#7563
Don't use static crt by default when build proc-macro Don't check value of `crt-static` when build proc-macro crates, since they are always built dynamically. For more information, see rust-lang/cargo#7563 (comment) I hope this will fix issues about compiling `proc_macro` crates on musl host without bring more issues. Note: I can't test this on my musl host locally, because I encounter this issue when bootstraping from a beta snapshot. Fix rust-lang/cargo#7563
…does not support these crate types from rust-lang/cargo#7563
I hit the same error message, and here's what worked for me to build a Rust Rocket app in a Dockerfile using Alpine and Rust nightly. I welcome feedback -- this is my first time trying Docker + Rust nightly + Alpine musl.
|
@joelparkerhenderson Any particular reason you set |
IIRC, I was attempting to stop dynamic linking related to release builds. IIRC, I was following rust-lang/rust#54243 and https://stackoverflow.com/questions/64737810/rust-building-a-statically-linked-binary-including-external-c-libraries |
Problem
On a musl based linux system , cross compilation will fail when using proc-macro
Steps
1.Cargo.toml:
2.src/main.rs:
Possible Solution(s)
Problem is : https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/build_context/target_info.rs#L406
proc-macro can't build without RUSTFLAGS=-C target-feature=-crt-static
Notes
Output of
cargo version
:cargo 1.40.0-nightly (5da4b4d47 2019-10-28)
The text was updated successfully, but these errors were encountered: