-
Notifications
You must be signed in to change notification settings - Fork 126
feat: add manifest options support for cargo build invocations #656
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
Open
svasista-ms
wants to merge
5
commits into
microsoft:main
Choose a base branch
from
svasista-ms:648-support-locked-option
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6bfd1d0
feat: add manifest options support for cargo build invocations
svasista-ms 311b721
fix: modify `get_cargo_metadata_at_path` to accept additional command…
svasista-ms 7e630a2
Merge branch 'microsoft:main' into 648-support-locked-option
svasista-ms d243ea1
feat: add support for additional cargo manifest options in README and…
svasista-ms b57d075
fix: allow clippy warning for too many arguments in clean_build_and_v…
svasista-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,12 +69,17 @@ Options: | |
| --sample Build sample class driver project | ||
| -h, --help Print help | ||
|
|
||
| Manifest Options: | ||
| --locked Require Cargo.lock is up to date | ||
| --offline Run without accessing the network | ||
| --frozen Require Cargo.lock and cache are up to date | ||
|
|
||
| Verbosity: | ||
| -v, --verbose... Increase logging verbosity | ||
| -q, --quiet... Decrease logging verbosity | ||
| ``` | ||
|
|
||
| `build` takes a number of inputs specifying build profile (`dev` or `release`), target architecture (`amd64` or `arm64`), a flag enabling signature verification and a flag indicating a sample driver along with verbosity flags. | ||
| `build` takes a number of inputs specifying build profile (`dev` or `release`), target architecture (`amd64` or `arm64`), a flag enabling signature verification and a flag indicating a sample driver along with verbosity flags. It also accepts the cargo manifest flags `--locked`, `--offline` and `--frozen`, which are forwarded to the underlying `cargo` invocations (e.g. `cargo build`, `cargo metadata`). | ||
|
|
||
| When the command completes the packaged driver artifacts are emitted at the path `target\<profile>\<project-name>-package`. | ||
|
|
||
|
|
@@ -113,3 +118,9 @@ If the `--verify-signature` flag is provided, the signatures are verified after | |
| ```pwsh | ||
| cargo wdk build --target-arch amd64 | ||
| ``` | ||
|
|
||
| - To build a driver project with a strict, reproducible dependency lockfile (e.g. for CI), navigate to the root of the project and run: | ||
|
|
||
| ```pwsh | ||
| cargo wdk build --locked | ||
| ``` | ||
|
Comment on lines
+121
to
+126
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is example is not needed. We don't need to add examples for every commandline line arg |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ use wdk_build::CpuArchitecture; | |
| #[double] | ||
| use crate::providers::exec::CommandExec; | ||
| use crate::{ | ||
| actions::{Profile, build::error::BuildTaskError, to_target_triple}, | ||
| actions::{ManifestOptions, Profile, build::error::BuildTaskError, to_target_triple}, | ||
| providers::error::CommandError, | ||
| trace, | ||
| }; | ||
|
|
@@ -27,6 +27,7 @@ pub struct BuildTask<'a> { | |
| profile: Option<&'a Profile>, | ||
| target_arch: Option<CpuArchitecture>, | ||
| verbosity_level: clap_verbosity_flag::Verbosity, | ||
| manifest_options: ManifestOptions, | ||
| manifest_path: PathBuf, | ||
| command_exec: &'a CommandExec, | ||
| working_dir: &'a Path, | ||
|
|
@@ -41,6 +42,8 @@ impl<'a> BuildTask<'a> { | |
| /// * `profile` - An optional profile for the build | ||
| /// * `target_arch` - The target architecture for the build | ||
| /// * `verbosity_level` - The verbosity level for logging | ||
| /// * `manifest_options` - Cargo manifest options (`--locked`, `--frozen`, | ||
| /// `--offline`) to forward to the underlying `cargo build` invocation | ||
| /// * `command_exec` - The command execution provider | ||
| /// | ||
| /// # Returns | ||
|
|
@@ -54,6 +57,7 @@ impl<'a> BuildTask<'a> { | |
| profile: Option<&'a Profile>, | ||
| target_arch: Option<CpuArchitecture>, | ||
| verbosity_level: clap_verbosity_flag::Verbosity, | ||
| manifest_options: ManifestOptions, | ||
| command_exec: &'a CommandExec, | ||
| ) -> Self { | ||
| assert!( | ||
|
|
@@ -66,6 +70,7 @@ impl<'a> BuildTask<'a> { | |
| profile, | ||
| target_arch, | ||
| verbosity_level, | ||
| manifest_options, | ||
| manifest_path: working_dir.join("Cargo.toml"), | ||
| command_exec, | ||
| working_dir, | ||
|
|
@@ -109,6 +114,7 @@ impl<'a> BuildTask<'a> { | |
| args.push("--target".to_string()); | ||
| args.push(to_target_triple(target_arch)); | ||
| } | ||
| args.extend(self.manifest_options.cargo_args().map(String::from)); | ||
| if let Some(flag) = trace::get_cargo_verbose_flags(self.verbosity_level) { | ||
| args.push(flag.to_string()); | ||
| } | ||
|
|
@@ -149,7 +155,7 @@ mod tests { | |
|
|
||
| use super::*; | ||
| use crate::{ | ||
| actions::Profile, | ||
| actions::{ManifestOptions, Profile}, | ||
| providers::{error::CommandError, exec::MockCommandExec}, | ||
| }; | ||
|
|
||
|
|
@@ -168,6 +174,7 @@ mod tests { | |
| Some(&profile), | ||
| target_arch, | ||
| verbosity_level, | ||
| ManifestOptions::default(), | ||
| &command_exec, | ||
| ); | ||
|
|
||
|
|
@@ -201,6 +208,7 @@ mod tests { | |
| profile.as_ref(), | ||
| target_arch, | ||
| verbosity_level, | ||
| ManifestOptions::default(), | ||
| &command_exec, | ||
| ); | ||
| } | ||
|
|
@@ -257,6 +265,7 @@ mod tests { | |
| Some(&profile), | ||
| Some(target_arch), | ||
| verbosity, | ||
| ManifestOptions::default(), | ||
| &mock, | ||
| ); | ||
|
|
||
|
|
@@ -298,6 +307,7 @@ mod tests { | |
| None, | ||
| None, | ||
| clap_verbosity_flag::Verbosity::default(), | ||
| ManifestOptions::default(), | ||
| &mock, | ||
| ); | ||
|
|
||
|
|
@@ -339,6 +349,7 @@ mod tests { | |
| None, | ||
| None, | ||
| clap_verbosity_flag::Verbosity::default(), | ||
| ManifestOptions::default(), | ||
| &mock, | ||
| ); | ||
|
|
||
|
|
@@ -356,4 +367,98 @@ mod tests { | |
| ); | ||
| assert_eq!(io_err.kind(), std::io::ErrorKind::NotFound); | ||
| } | ||
|
|
||
| #[test] | ||
| fn run_forwards_manifest_options_to_cargo_invocations_in_build_task() { | ||
| let working_dir = PathBuf::from("C:/abs/driver"); | ||
| let manifest_options = ManifestOptions { | ||
| frozen: true, | ||
| locked: true, | ||
| offline: true, | ||
| }; | ||
| let mut expected_stdout = br#"{"reason":"build-finished","success":true}"#.to_vec(); | ||
| expected_stdout.push(b'\n'); | ||
| let expected_stdout_for_mock = expected_stdout.clone(); | ||
|
|
||
| let mut mock = MockCommandExec::new(); | ||
| mock.expect_run() | ||
| .withf(|command, args, _env, _wd| { | ||
| command == "cargo" | ||
| && args.contains(&"--frozen") | ||
| && args.contains(&"--locked") | ||
| && args.contains(&"--offline") | ||
| && { | ||
| // Confirm fixed ordering: locked before offline before frozen | ||
| let locked_idx = args.iter().position(|a| *a == "--locked").unwrap(); | ||
| let offline_idx = args.iter().position(|a| *a == "--offline").unwrap(); | ||
| let frozen_idx = args.iter().position(|a| *a == "--frozen").unwrap(); | ||
|
Comment on lines
+391
to
+394
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does order matter? |
||
| locked_idx < offline_idx && offline_idx < frozen_idx | ||
| } | ||
| }) | ||
| .return_once(move |_, _, _, _| { | ||
| Ok(Output { | ||
| status: ExitStatus::default(), | ||
| stdout: expected_stdout_for_mock, | ||
| stderr: Vec::new(), | ||
| }) | ||
| }); | ||
|
|
||
| let task = BuildTask::new( | ||
| "my-driver", | ||
| &working_dir, | ||
| None, | ||
| None, | ||
| clap_verbosity_flag::Verbosity::default(), | ||
| manifest_options, | ||
| &mock, | ||
| ); | ||
|
|
||
| task.run() | ||
| .expect("expected an iterator over parsed cargo message objects") | ||
| .collect::<std::result::Result<Vec<_>, _>>() | ||
| .expect("expected valid cargo messages"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn run_forwards_locked_only_when_only_locked_is_set() { | ||
| let working_dir = PathBuf::from("C:/abs/driver"); | ||
| let manifest_options = ManifestOptions { | ||
| locked: true, | ||
| ..ManifestOptions::default() | ||
| }; | ||
| let mut expected_stdout = br#"{"reason":"build-finished","success":true}"#.to_vec(); | ||
| expected_stdout.push(b'\n'); | ||
| let expected_stdout_for_mock = expected_stdout.clone(); | ||
|
|
||
| let mut mock = MockCommandExec::new(); | ||
| mock.expect_run() | ||
| .withf(|command, args, _env, _wd| { | ||
| command == "cargo" | ||
| && args.contains(&"--locked") | ||
| && !args.contains(&"--frozen") | ||
| && !args.contains(&"--offline") | ||
| }) | ||
| .return_once(move |_, _, _, _| { | ||
| Ok(Output { | ||
| status: ExitStatus::default(), | ||
| stdout: expected_stdout_for_mock, | ||
| stderr: Vec::new(), | ||
| }) | ||
| }); | ||
|
|
||
| let task = BuildTask::new( | ||
| "my-driver", | ||
| &working_dir, | ||
| None, | ||
| None, | ||
| clap_verbosity_flag::Verbosity::default(), | ||
| manifest_options, | ||
| &mock, | ||
| ); | ||
|
|
||
| task.run() | ||
| .expect("expected an iterator over parsed cargo message objects") | ||
| .collect::<std::result::Result<Vec<_>, _>>() | ||
| .expect("expected valid cargo messages"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Slightly shorter