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

Make debug_triple depend on target json file content rather than file path #98225

Merged
merged 2 commits into from
Jun 20, 2022

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jun 18, 2022

This ensures that changes to target json files will force a recompilation. And more importantly that moving the files doesn't force a recompilation.

This should fix Rust-for-Linux/linux#792 (cc @ojeda)

… path

This ensures that changes to target json files will force a
recompilation. And more importantly that moving the files doesn't force
a recompilation.
@bjorn3 bjorn3 added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-target-specs Area: Compile-target specifications labels Jun 18, 2022
@rust-highfive
Copy link
Collaborator

r? @nagisa

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive
Copy link
Collaborator

⚠️ Warning ⚠️

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 18, 2022
@rust-log-analyzer

This comment has been minimized.

@@ -2436,20 +2434,28 @@ impl TargetTriple {
/// Creates a target triple from the passed target path.
pub fn from_path(path: &Path) -> Result<Self, io::Error> {
let canonicalized_path = path.canonicalize()?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fine to remove this canonicalize operation now I think. The only difference would be that the triple would be the original file stem rather than the canonicalized one. This may be preferred in case of content addressed storage as the canonicalized name would be a non human readable hash.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@nagisa nagisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on the general direction. r=me, up to you what to do with the nits inline.

Comment on lines +2441 to +2444
(
Self::TargetJson { path_for_rustdoc: _, triple: l_triple, contents: l_contents },
Self::TargetJson { path_for_rustdoc: _, triple: r_triple, contents: r_contents },
) => l_triple == r_triple && l_contents == r_contents,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor style nit, consider:

Suggested change
(
Self::TargetJson { path_for_rustdoc: _, triple: l_triple, contents: l_contents },
Self::TargetJson { path_for_rustdoc: _, triple: r_triple, contents: r_contents },
) => l_triple == r_triple && l_contents == r_contents,
(l@Self::TargetJson { .. }, r@Self::TargetJson { .. }) => {
l.triple == r.triple && l.contents == r.contents
}

or, if the intent was to have this an exhaustive match, maybe something like this (though there isn’t much value in this…):

Suggested change
(
Self::TargetJson { path_for_rustdoc: _, triple: l_triple, contents: l_contents },
Self::TargetJson { path_for_rustdoc: _, triple: r_triple, contents: r_contents },
) => l_triple == r_triple && l_contents == r_contents,
(Self::TargetJson { path_for_rustdoc: _, triple, contents }, r@Self::TargetJson { .. }) => {
triple == r.triple && contents == r.contents
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or, if the intent was to have this an exhaustive match

Indeed

maybe something like this

Rustfmt puts that suggestion on four lines too.

compiler/rustc_target/src/spec/mod.rs Outdated Show resolved Hide resolved

impl<D: Decoder> Decodable<D> for TargetTriple {
fn decode(d: &mut D) -> Self {
match d.read_usize() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little sketchy. This could fail if the implementation of the encoder has overriden emit_enum_variant to output something else than usize… Though of course Decoder does not provide a better way 🤷

compiler/rustc_target/src/spec/mod.rs Outdated Show resolved Hide resolved
@bjorn3
Copy link
Member Author

bjorn3 commented Jun 19, 2022

Fixed all review comments apart from #98225 (comment)

@rust-log-analyzer

This comment was marked as resolved.

@nagisa
Copy link
Member

nagisa commented Jun 19, 2022

consider squashing the history somewhat before bors r=nagisaing this ^^

@bjorn3
Copy link
Member Author

bjorn3 commented Jun 19, 2022

@bors r=nagisa

@bors
Copy link
Contributor

bors commented Jun 19, 2022

📌 Commit b4b536d has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 19, 2022
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 19, 2022
…agisa

Make debug_triple depend on target json file content rather than file path

This ensures that changes to target json files will force a recompilation. And more importantly that moving the files doesn't force a recompilation.

This should fix Rust-for-Linux/linux#792 (cc `@ojeda)`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 20, 2022
Rollup of 4 pull requests

Successful merges:

 - rust-lang#95534 (Add `core::mem::copy` to complement `core::mem::drop`.)
 - rust-lang#97912 (Stabilize `Path::try_exists()` and improve doc)
 - rust-lang#98225 (Make debug_triple depend on target json file content rather than file path)
 - rust-lang#98257 (Fix typos in `IntoFuture` docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit bfa6cd9 into rust-lang:master Jun 20, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 20, 2022
@bjorn3 bjorn3 deleted the stable_target_json_hash branch June 20, 2022 07:59
Ericson2314 added a commit to alamgu/ledger-nanos-sdk that referenced this pull request Aug 25, 2022
The first change is to parse once, and then use an enum for the device.
This is hopefully a straightforward improvement.

The second change is to case on the OS name (leveraging LedgerHQ#38) instead of
the target name. The target "name" isn't so structured, and it is
unclear to what extent it should be anm exposed part of the target. (See
rust-lang/rust#98225 for example, where the
contents rather than json file path were used as a a key.)

With LedgerHQ#38 the device name is used for the OS field instead, and so we are
robust to confusing behavior around names.
yhql pushed a commit to LedgerHQ/ledger-device-rust-sdk that referenced this pull request Aug 29, 2022
The first change is to parse once, and then use an enum for the device.
This is hopefully a straightforward improvement.

The second change is to case on the OS name (leveraging #38) instead of
the target name. The target "name" isn't so structured, and it is
unclear to what extent it should be anm exposed part of the target. (See
rust-lang/rust#98225 for example, where the
contents rather than json file path were used as a a key.)

With #38 the device name is used for the OS field instead, and so we are
robust to confusing behavior around names.
rnestler added a commit to rnestler/archpkg-linux-rust that referenced this pull request May 23, 2023
This gives us some warnings, but allows to compile out-of-tree modules
since it fixes a bug with how the target triple is defined for a custom
target.json file. See rust-lang/rust#98225
superstar0402 added a commit to superstar0402/wea that referenced this pull request Aug 19, 2024
The first change is to parse once, and then use an enum for the device.
This is hopefully a straightforward improvement.

The second change is to case on the OS name (leveraging #38) instead of
the target name. The target "name" isn't so structured, and it is
unclear to what extent it should be anm exposed part of the target. (See
rust-lang/rust#98225 for example, where the
contents rather than json file path were used as a a key.)

With #38 the device name is used for the OS field instead, and so we are
robust to confusing behavior around names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-target-specs Area: Compile-target specifications S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Out-of-tree module failed to build if the kernel source path is different
6 participants