Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

ogoffart
Copy link

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.

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
@rustbot
Copy link
Collaborator

rustbot commented Sep 29, 2023

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-documenting-cargo-itself Area: Cargo's documentation S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 29, 2023
Copy link
Member

@weihanglo weihanglo left a 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(),
Copy link
Member

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?

Suggested change
CompileKind::Target(t) => t.short_name(),
CompileKind::Target(t) => t.rustc_target(),

@epage
Copy link
Contributor

epage commented Sep 29, 2023

Since #10714 is still stuck in "needs design", should this be marked as a draft or closed until the issues are worked out?

@weihanglo
Copy link
Member

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 :)

@weihanglo weihanglo closed this Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-documenting-cargo-itself Area: Cargo's documentation S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access target triplet of artifact from proc macros
4 participants