You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"cannot produce proc-macro for crate as the target x86_64-unknown-linux-gnu does not support these crate types" with +crt-static #78210
% RUSTFLAGS="-C target-feature=+crt-static" cargo +nightly check
error: cannot produce proc-macro for `ctor v0.1.16` as the target `x86_64-unknown-linux-gnu` does not support these crate types
Version it worked on
It most recently worked on: rustc 1.48.0-beta.4 (fb94aa5 2020-10-20)
$ RUSTFLAGS='-C target-feature=+crt-static' cargo b
error: cannot produce proc-macro for `ctor v0.1.16 (/tmp/rust-ctor/ctor)` as the target `x86_64-unknown-linux-gnu` does not support these crate types
$ RUSTFLAGS='-C target-feature=+crt-static' cargo b --target x86_64-unknown-linux-gnu
Compiling libc v0.2.79
Compiling proc-macro2 v0.4.30
Compiling unicode-xid v0.1.0
Compiling proc-macro2 v1.0.23
Compiling syn v0.15.44
Compiling unicode-xid v0.2.0
Compiling syn v1.0.46
Compiling lazy_static v1.4.0
Compiling quote v0.6.13
Compiling quote v1.0.7
Compiling libc-print v0.1.14
Compiling dlopen_derive v0.1.4
Compiling dlopen v0.1.8
Compiling ctor v0.1.16 (/tmp/rust-ctor/ctor)
Compiling tests v0.1.0 (/tmp/rust-ctor/tests)
Finished dev [unoptimized + debuginfo] target(s) in 7.14s
cc @petrochenkov I assume it's expected that #69519 helped only the case with explicit (aka cross-compiled) target?
Reacted by Yohei Tamura, Alexei Pastuchov, Jens Eckervogt, Kirill, Matt Johnston, André-Marthin Helberg, bazizi, Lorenzo Rosa, Yang Yang, Brennan Kinney and 4 more
@mati865 #69519 introduced different defaults for crt-static for executables (yes) and proc-macros (no) (should apply to all dylibs really).
If -C target-feature=+crt-static is specified explicitly, then the compiler respects it and overrides the defaults, that's the compiler's job.
Then cargo comes into play. AFAIK, it applies RUSTFLAGS only to target if --target specified explicitly, and to both target and host otherwise. (I remember people complaining about this inconsistency.)
So it doesn't pass -C target-feature=+crt-static when compiling proc macro dependencies (which is correct in this case).
I think this is a problem that should be solved at the cargo's abstraction level, in general. Cargo should provide a way to set compiler options per-crate-type and per-build-target (per-crate), and may provide its own defaults (e.g. not pass +crt-static to proc macro crates).
Reacted by Mateusz Mikuła, Otavio Salvador, Josh Triplett, lafer, Alejandro González and Brennan Kinney
My biggest concern here is this looks like a regression from the user point of view; what can we currently do to workaround it until it is handled on the cargo's abtraction level, as suggested by @petrochenkov?
The regression seems to be because we're now trying to respect the new flag, which is then causing breakage.
@Mark-Simulacrum to be more clear, -C target-feature=+crt-static is not a new flag. It existed for a long long time but *-linux-gnu targets were ignoring it until recently.
changed the title [-]dynlib stopped building on nightly[/-][+]"cannot produce proc-macro for `crate` as the target `x86_64-unknown-linux-gnu` does not support these crate types" with +crt-static[/+]on Nov 15, 2020
I ran into this recently. Is there a way to provide a better error message? It wasn't obvious to me that I have to pass --target x86_64-unknown-linux-gnu when I want to statically link libc.
Reacted by PatrickChodowski, Andrew Rowson, Matt Johnston, pepa65, Dan Kov, Andrew Gunnerson, Alex Ellwein, alex , Eugene Glybin, eric-parker and 16 more
Activity
camelid commentedon Oct 21, 2020
Could you provide a reproduction?
camelid commentedon Oct 21, 2020
And also the version you're testing with?
otavio commentedon Oct 22, 2020
The nightly of 2020-10-20.
I'm out of computer now, so I can't. It seems to be related to proc macro use. I can try to cook a test case for it.
tesuji commentedon Oct 22, 2020
mati865 commentedon Oct 22, 2020
It did not really work but didn't produce the error since
+crt-staticwas no-op forlinux-gnu.Since #77386
+crt-staticnow properly links statically.I think I can add workaround for it.
mati865 commentedon Oct 22, 2020
It works with explicit target:
cc @petrochenkov I assume it's expected that #69519 helped only the case with explicit (aka cross-compiled) target?
petrochenkov commentedon Oct 22, 2020
@mati865
#69519 introduced different defaults for
crt-staticfor executables (yes) and proc-macros (no) (should apply to all dylibs really).If
-C target-feature=+crt-staticis specified explicitly, then the compiler respects it and overrides the defaults, that's the compiler's job.Then cargo comes into play. AFAIK, it applies
RUSTFLAGSonly to target if--targetspecified explicitly, and to both target and host otherwise. (I remember people complaining about this inconsistency.)So it doesn't pass
-C target-feature=+crt-staticwhen compiling proc macro dependencies (which is correct in this case).I think this is a problem that should be solved at the cargo's abstraction level, in general. Cargo should provide a way to set compiler options per-crate-type and per-build-target (per-crate), and may provide its own defaults (e.g. not pass
+crt-staticto proc macro crates).otavio commentedon Oct 23, 2020
My biggest concern here is this looks like a regression from the user point of view; what can we currently do to workaround it until it is handled on the cargo's abtraction level, as suggested by @petrochenkov?
7 remaining items
Mark-Simulacrum commentedon Nov 6, 2020
cc @XAMPPRocky for the relnotes label
mati865 commentedon Nov 6, 2020
@Mark-Simulacrum to be more clear,
-C target-feature=+crt-staticis not a new flag. It existed for a long long time but*-linux-gnutargets were ignoring it until recently.joshtriplett commentedon Nov 15, 2020
I do think we need a better solution for building statically in general.
Passing an explicit
--targetis a workaround. We should have better handling for host vs target, as @petrochenkov suggested.[-]dynlib stopped building on nightly[/-][+]"cannot produce proc-macro for `crate` as the target `x86_64-unknown-linux-gnu` does not support these crate types" with +crt-static[/+]Mark-Simulacrum commentedon Jan 21, 2021
I don't believe we're intending to fix this.
Aloso commentedon Apr 10, 2023
I ran into this recently. Is there a way to provide a better error message? It wasn't obvious to me that I have to pass
--target x86_64-unknown-linux-gnuwhen I want to statically link libc.Add target argument to test invocations
fix: clap_derive on linux
Pass the build target when invoking clippy
Rudxain commentedon Jun 17, 2024
Now that GH supports "Closing Reasons" this should be "Closed as Not Planned"
fix: resolve proc-macro cross-compilation issues with global RUSTFLAGS
Fix an issue appeared in gh action run