-
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
Pass compile mode to the custom build script #10126
Conversation
Closes rust-lang#4001 This PR adds code to track and pass compile mode to the build scripts. Since the unit's mode is always `RunCustomBuild`, I had to add tracking for the parent's compile mode, and pass it around. - [ ] env var naming. I used `CARGO_MODE`, but perhaps another name is better? - [ ] env var values naming. I used: `Test`, `Build`, `Check_test/Check`, `Bench`, `Doc_with_deps/Doc`, `Doctest`, `Docscrape`, `RunCustomBuild` - [ ] how to represent bool values for `Check` and `Doc`. I created two separate values, but perhaps the `test` and `deps` values should be ignored? - [ ] figure out why `cargo bench` sets env var to `Test` - [ ] add unit tests
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Eh2406 (or someone else) soon. Please see the contribution instructions for more information. |
nit: I think it would be better to use snake_case for these, the same way that they're named on the command line. I also think there doesn't need to be so many modes; just |
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 left a few suggestions, but I defer to Ehuss's expertise 😁 I did see that this doesn't have any dependency tracking - I think there needs to be some logic to rerun the build script when the root_mode changes.
} | ||
CompileMode::Bench => "Bench", | ||
CompileMode::Doc { deps } => { | ||
if deps { |
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 shouldn't matter to the build script, no dependencies will be built after it runs.
src/cargo/core/compiler/unit.rs
Outdated
@@ -52,6 +52,8 @@ pub struct UnitInner { | |||
pub kind: CompileKind, | |||
/// The "mode" this unit is being compiled for. See [`CompileMode`] for more details. | |||
pub mode: CompileMode, | |||
/// The "mode" of the root unit. Required when unit's mode is `CompileMode::RunCustomBuild` | |||
pub root_mode: CompileMode, |
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.
Rather than adding an additional field you don't always need, I think it might make sense to add a field to the RunCustomBuild unit:
enum CompileMode {
RunCustomBuild { root_mode: Box<CompileMode> },
}
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.
@jyn514 that's an awesome idea, thanks! One issue -- the enum implements Copy
trait which cannot be auto-implemented with the Box<>
. I wonder if i can get away with the ? Apparently Arc
insteadArc
doesn't support it either... Any suggestions?
@jyn514 thx again for the feedback, I switched to |
☔ The latest upstream changes (presumably #9992) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #10434) made this pull request unmergeable. Please resolve the merge conflicts. |
Closing as this PR has become a bit stale. Also, this appears to be a pretty major change that will be quite difficult to make as it will have an impact on every project using build scripts. Unfortunately the Cargo team doesn't have the capacity to accept new features of this nature at this time. |
Closes #4001
This PR adds code to track and pass compile mode to the build scripts. Since the unit's mode is always
RunCustomBuild
, I had to add tracking for the parent unit's compile mode, and pass it around.TODO:
CARGO_MODE
, but perhaps another name is better? (e.g.CARGO_CMD
,CARGO_COMMAND
, ... ?)test
,build
,check
,bench
,doc
,doctest
, anddocscrape
. The last two might need to be substituted withdoc
, or panic on them?Check
andDoc
modes be shown? Both values are currently ignored.cargo bench
sets env var totest