-
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
Refactor Kind
to carry target name in Target
#7425
Conversation
r? @Eh2406 (rust_highfive has picked a reviewer for you, use r? to override) |
Looks ok to me, but I am not confident in my understanding. |
So I've been thinking about renaming The other thing I was wondering about as I mentioned in #7421 is to wrap the requested target in a newtype struct to prevent misuse for json targets. I think the only misuse is in |
Alternatively we could optimize for the number of aka those sound like excellent suggestions, will do! |
Ok, updated! r? @ehuss |
☔ The latest upstream changes (presumably #7421) made this pull request unmergeable. Please resolve the merge conflicts. |
563569b
to
43f3952
Compare
@@ -81,18 +81,11 @@ impl FileType { | |||
impl TargetInfo { | |||
pub fn new( | |||
config: &Config, | |||
requested_target: &Option<String>, | |||
requested_kind: CompileKind, |
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'm having trouble unraveling why there are two CompileKind
s being passed in here. Can there just be 1 value passed in? There seems to be some dancing around in env_args
based on which is which. But BuildContext::target_info
shouldn't ever be used for a host-only build, so I don't know why it supports a requested_target=Host and a kind=Target.
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.
The rationale is basically that RUSTFLAGS
plus --target
shouldn't pass the flags to build scripts. This is needed here I think because we calculate TargetInfo
for both the host and target, right?
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.
Ah, I see now.
host_dylib_path: bcx.host_info.sysroot_libdir.clone(), | ||
target_dylib_path: bcx.target_info.sysroot_libdir.clone(), | ||
host_dylib_path: bcx.info(CompileKind::Host).sysroot_libdir.clone(), | ||
target_dylib_path: bcx.info(default_kind).sysroot_libdir.clone(), |
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.
In a world were cargo supports multiple targets, wouldn't this need to be a map?
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.
It would, yeah. Compilation
would need some larger refactorings to support multi-target builds for sure. I'm thinking those would probably want to happen if we were to ever expose this at the CLI level, but before then it may be premature to apply the refactorings here. I don't mind going either way though!
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.
No, I just wanted to make sure I was understanding it correctly.
} | ||
|
||
#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy, PartialOrd, Ord, Serialize)] | ||
pub struct CompileTarget { |
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 could use a brief doc comment explaining that it may be a target triple or path (absolute?) to a .json
file.
Also, I'm curious, did you consider making it an enum to differentiate the two? If it is an enum, it could pre-compute rustc_target
so it is not repeatedly recomputed.
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.
Comment added! I didn't actually consider using an enum
, but I was a bit overzealous in that I was trying to keep this the same size as an InternedString
. There's definitely not a great reason for that though.
I tried to remove the Copy
bound on this to store something like PathBuf
, but unfortunately that would require a good deal of work I think.
I'm sort of fine either way, I think having it encapsulated is fine for now, but I don't mind either way. Would you prefer to switch to an enum
?
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.
No, it was just a thought to simplify short_name
, but I don't think it is necessary.
☔ The latest upstream changes (presumably #7440) made this pull request unmergeable. Please resolve the merge conflicts. |
This commit is an internal refactoring of Cargo's compilation backend to eventually support compiling multiple target simultaneously. The original motivation for this came up in discussion of rust-lang#7297 and this has long been something I've intended to update Cargo for. Nothing in the backend currently exposes the ability to actually build multiple target simultaneously, but this should have no function change with respect to all current consumers. Eventually we'll need to refactor APIs of how you enter the compilation backend to compile for multiple targets.
Rename `Kind` to `CompileKind` to reflect that it's intended for compilation. Additionally change the `Target` variant to have a newtype `CompileTarget` instead of just being a raw string. This new `CompileTarget` type has a fallible constructor and handles custom json target files internally. Two accessors are available for `CompileTarget`, one is `rustc_target()` which goes straight to rustc and everything else uses `short_name()` which is the raw target or file stem for json files. The `short_name` is used everywhere in Cargo for all purposes like configuration, env vars, target directory naming, etc.
43f3952
to
f745ca7
Compare
@bors r+ |
📌 Commit f745ca7 has been approved by |
Refactor `Kind` to carry target name in `Target` This commit is an internal refactoring of Cargo's compilation backend to eventually support compiling multiple target simultaneously. The original motivation for this came up in discussion of #7297 and this has long been something I've intended to update Cargo for. Nothing in the backend currently exposes the ability to actually build multiple target simultaneously, but this should have no function change with respect to all current consumers. Eventually we'll need to refactor APIs of how you enter the compilation backend to compile for multiple targets.
☀️ Test successful - checks-azure |
This fixes an accidental regression from rust-lang#7425 where `PATH` was being augmented on Windows with the wrong search path for target/host libraries. This commit fixes the issue by simply always calculating the host/target library paths for `TargetInfo`, and then we explicitly use the same `TargetInfo` for filling out information in `Compilation`. Closes rust-lang#7475
Fix wrong directories in PATH on Windows This fixes an accidental regression from #7425 where `PATH` was being augmented on Windows with the wrong search path for target/host libraries. This commit fixes the issue by simply always calculating the host/target library paths for `TargetInfo`, and then we explicitly use the same `TargetInfo` for filling out information in `Compilation`. Closes #7475
This commit is an internal refactoring of Cargo's compilation backend to
eventually support compiling multiple target simultaneously. The
original motivation for this came up in discussion of #7297 and this has
long been something I've intended to update Cargo for. Nothing in the
backend currently exposes the ability to actually build multiple target
simultaneously, but this should have no function change with respect to
all current consumers. Eventually we'll need to refactor APIs of how you
enter the compilation backend to compile for multiple targets.