-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Warn when relying on default musl target static linkage behaviour #144513
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
61b9f03
to
2ee2447
Compare
This comment has been minimized.
This comment has been minimized.
This introduces a new lint, "musl_missing_crt_static" that warns when compiling code for a musl target that defaults to static linkage without explicitly specifying -Ctarget-feature=+crt-static. The targets will be changed to link dynamically by default in the future, after which this lint can be removed again. Signed-off-by: Jens Reidel <adrian@travitia.xyz>
2ee2447
to
6470b66
Compare
The job Click to see the possible cause of the failure (guessed by this bot)
|
@@ -5099,3 +5100,16 @@ declare_lint! { | |||
report_in_deps: true, | |||
}; | |||
} | |||
|
|||
declare_lint! { | |||
/// The `musl_missing_crt_static` lint detects when code is compiled for a target using musl libc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lint will be seen by a lot of people, many of which may not be familiar with the details of compiler flags. I think this lint documents here should spend more effort explaining exactly how to pass the flag (via RUSTFLAGS) and what exactly it means (what is libc, what are the differences between static and dynamic linkage, why is this change being made exactly etc) in an accessible way. I can write down such a text if you want to, or you can do it yourself.
The lint output should then contain a link to this documentation here in the rustc book.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I think there are a lot of projects that have just copied the --target
from somewhere because they heard that this makes a binary that works everywhere, without being familiar with the details of Rust compilation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively all these details can be in the blog post and we link to the blog post.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really mind where the details are, I think both ways are fine. However, before I write such a blog post, I'd like to know for how long we want to keep the lint around before we change the behavior, since I'd have to mention that in the blog post and it needs to be decided on either way, so better start that process now than later
r? @Noratrieb maybe, but feel free to reassign |
|
I have a small concern. Because of rust-lang/cargo#4423, when the host is musl and cross-compilation is used, |
The lint does not apply to proc macros, not sure about build scripts, I'll have to try it and see. |
This introduces a new lint, "musl_missing_crt_static" that warns when compiling code for a musl target that defaults to static linkage without explicitly specifying
-Ctarget-feature=+crt-static
.The targets will be changed to link dynamically by default in the future, after which this lint can be removed again.
See the accepted MCP rust-lang/compiler-team#422 which proposed this lint.
TODO: Decide on a deadline and write a blog post about this?
Example in action (on a
powerpc64le-unknown-linux-musl
host):The lint will not be emitted on targets that already default to dynamic linkage, like e.g. the loongarch64 targets.