-
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
Set the TARGET
env variable when running rustc
#12752
Conversation
The goal is to be able to do things differently in a proc macro depending on the target platform. It is already defined for build script and it would help to have it for macros as well. Closes: rust-lang#10714
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @epage (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
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.
Thanks for the PR, though I don't think this will merge at this moment. There are more considerations in #10714 (comment). Proc macros is a thing multiple teams in Rust get involved. We should perhaps consult other teams for other possibilities before making a decision.
@@ -383,6 +383,11 @@ fn fill_rustc_tool_env(mut cmd: ProcessBuilder, unit: &Unit) -> ProcessBuilder { | |||
cmd.env("CARGO_BIN_NAME", name); | |||
} | |||
cmd.env("CARGO_CRATE_NAME", unit.target.crate_name()); | |||
let target_triple = match &unit.kind { | |||
CompileKind::Host => host_triple, | |||
CompileKind::Target(t) => t.short_name(), |
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.
Should we use this instead so that local target JSON files are respected?
CompileKind::Target(t) => t.short_name(), | |
CompileKind::Target(t) => t.rustc_target(), |
Since #10714 is still stuck in "needs design", should this be marked as a draft or closed until the issues are worked out? |
I will go ahead and close this. It doesn't mean it is not worthy to solve this problem. The issue at this time needs a driver to solicit feedback and thought from teams and community. Your effort on this is much appreciated. Let us focus on the discussion first, and then we can revisit the implementation :) |
What does this PR try to resolve?
The goal is to be able to do things differently in a proc macro depending on the target platform. It is already defined for build script and it would help to have it for macros as well.
Closes: #10714
Additional information
I understand that the discussion in #10714 asks for a more structured way to get the target. But this change is really easy to make like this and is consistent with the way to do it in build.rs (I always get confused as to what env variable is defined where, and consistency helps here.) So I thought I'd make a PR anyway.