-
Notifications
You must be signed in to change notification settings - Fork 124
chore: update cargo-wdk templates to use latest crate versions #573
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
Merged
+145
−13
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6f2c016
Initial plan
Copilot cb786ad
Update template versions and add version validation test
Copilot 56ce8bb
Add copyright header to template_versions_test.rs
Copilot 3fa7426
Replace Rust test with PowerShell script and workflow
Copilot 4eef7d5
Remove toml dependency that's no longer needed
Copilot 5d31951
Read versions from workspace dependencies instead of package sections
Copilot 0f1ef99
Merge branch 'main' into copilot/update-cargo-wdk-templates
gurry ab53273
Migrate template version checks to version-checks.yaml workflow
Copilot f25e3b5
Remove blank line and simplify template version checks
Copilot d388767
Update .github/workflows/version-checks.yaml
gurry 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| // Copyright (c) Microsoft Corporation | ||
| // License: MIT OR Apache-2.0 | ||
| //! Test to verify that template Cargo.toml files use the correct versions | ||
| //! from the workspace configuration. | ||
|
|
||
| use std::{collections::HashMap, path::PathBuf}; | ||
|
|
||
| use cargo_metadata::MetadataCommand; | ||
| use toml::Value; | ||
|
|
||
| /// Get the workspace versions from the root Cargo.toml | ||
| fn get_workspace_versions() -> HashMap<String, String> { | ||
| let metadata = MetadataCommand::new() | ||
| .manifest_path("../../Cargo.toml") | ||
| .exec() | ||
| .expect("Failed to get cargo metadata"); | ||
|
|
||
| let mut versions = HashMap::new(); | ||
|
|
||
| // Get workspace dependencies | ||
| let workspace_root = metadata.workspace_root.as_std_path(); | ||
| let cargo_toml_path = workspace_root.join("Cargo.toml"); | ||
| let cargo_toml_content = | ||
| std::fs::read_to_string(&cargo_toml_path).expect("Failed to read workspace Cargo.toml"); | ||
| let cargo_toml: Value = | ||
| toml::from_str(&cargo_toml_content).expect("Failed to parse workspace Cargo.toml"); | ||
|
|
||
| if let Some(workspace) = cargo_toml.get("workspace") { | ||
| if let Some(deps) = workspace.get("dependencies") { | ||
| if let Some(deps_table) = deps.as_table() { | ||
| for (name, value) in deps_table { | ||
| if name.starts_with("wdk") { | ||
| if let Some(version) = value.get("version") { | ||
| if let Some(version_str) = version.as_str() { | ||
| versions.insert(name.clone(), version_str.to_string()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| versions | ||
| } | ||
|
|
||
| /// Parse a template Cargo.toml and extract dependency versions | ||
| fn get_template_versions(template_path: PathBuf) -> HashMap<String, String> { | ||
| let template_content = | ||
| std::fs::read_to_string(&template_path).expect("Failed to read template file"); | ||
| let template_toml: Value = | ||
| toml::from_str(&template_content).expect("Failed to parse template TOML"); | ||
|
|
||
| let mut versions = HashMap::new(); | ||
|
|
||
| // Check build-dependencies | ||
| if let Some(build_deps) = template_toml.get("build-dependencies") { | ||
| if let Some(build_deps_table) = build_deps.as_table() { | ||
| for (name, value) in build_deps_table { | ||
| if name.starts_with("wdk") { | ||
| if let Some(version_str) = value.as_str() { | ||
| versions.insert(name.clone(), version_str.to_string()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Check dependencies | ||
| if let Some(deps) = template_toml.get("dependencies") { | ||
| if let Some(deps_table) = deps.as_table() { | ||
| for (name, value) in deps_table { | ||
| if name.starts_with("wdk") { | ||
| if let Some(version_str) = value.as_str() { | ||
| versions.insert(name.clone(), version_str.to_string()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| versions | ||
| } | ||
|
|
||
| #[test] | ||
| fn kmdf_template_versions_match_workspace() { | ||
| let workspace_versions = get_workspace_versions(); | ||
| let template_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| .join("templates") | ||
| .join("kmdf") | ||
| .join("Cargo.toml.tmp"); | ||
| let template_versions = get_template_versions(template_path); | ||
|
|
||
| // KMDF template should have: wdk-build, wdk, wdk-alloc, wdk-panic, wdk-sys | ||
| for (dep_name, template_version) in &template_versions { | ||
| let workspace_version = workspace_versions | ||
| .get(dep_name) | ||
| .unwrap_or_else(|| panic!("Dependency {dep_name} not found in workspace")); | ||
| assert_eq!( | ||
| template_version, workspace_version, | ||
| "KMDF template: {dep_name} version mismatch. Template has {template_version}, \ | ||
| workspace has {workspace_version}" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn umdf_template_versions_match_workspace() { | ||
| let workspace_versions = get_workspace_versions(); | ||
| let template_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| .join("templates") | ||
| .join("umdf") | ||
| .join("Cargo.toml.tmp"); | ||
| let template_versions = get_template_versions(template_path); | ||
|
|
||
| // UMDF template should have: wdk-build, wdk, wdk-sys | ||
| for (dep_name, template_version) in &template_versions { | ||
| let workspace_version = workspace_versions | ||
| .get(dep_name) | ||
| .unwrap_or_else(|| panic!("Dependency {dep_name} not found in workspace")); | ||
| assert_eq!( | ||
| template_version, workspace_version, | ||
| "UMDF template: {dep_name} version mismatch. Template has {template_version}, \ | ||
| workspace has {workspace_version}" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn wdm_template_versions_match_workspace() { | ||
| let workspace_versions = get_workspace_versions(); | ||
| let template_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| .join("templates") | ||
| .join("wdm") | ||
| .join("Cargo.toml.tmp"); | ||
| let template_versions = get_template_versions(template_path); | ||
|
|
||
| // WDM template should have: wdk-build, wdk, wdk-alloc, wdk-panic, wdk-sys | ||
| for (dep_name, template_version) in &template_versions { | ||
| let workspace_version = workspace_versions | ||
| .get(dep_name) | ||
| .unwrap_or_else(|| panic!("Dependency {dep_name} not found in workspace")); | ||
| assert_eq!( | ||
| template_version, workspace_version, | ||
| "WDM template: {dep_name} version mismatch. Template has {template_version}, workspace \ | ||
| has {workspace_version}" | ||
| ); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.