-
Notifications
You must be signed in to change notification settings - Fork 544
Refactor: Extract windows-find-tools #1531
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
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9d86d72
Create new workspace windows-registry
NobodyXu 6dda2e1
Rm src/windows mod
NobodyXu 5b2480c
cargo fmt
NobodyXu 813b364
Fix compilation on windows
NobodyXu 4715b62
Temporarily disable semver checks in CI due to false positive
NobodyXu 14422e4
Fix windows-registry testing
NobodyXu 0c0d718
Fix unexpected cfg for windows-registry
NobodyXu cc59ba9
Apply suggestions from code review
NobodyXu 28f891f
Replace From<windows_registry::Tool> for Tool with private method
NobodyXu 54e16da
Add README for windows-registry
NobodyXu cf68f05
Rename windows-registry to windows-find-tools since windows-registry …
NobodyXu 623fd8a
Fix crate name in windows-find-tools/README.md
NobodyXu 4df0111
Mark `windows_find_tools::Env` to be non-exhaustive and derive Debug …
NobodyXu 3f3e3f5
Rename windows-find-tools to find-msvc-tools
NobodyXu e75648e
Update README.md and crate doc
NobodyXu dcf029f
Update find-msvc-tools/README.md
NobodyXu 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
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,80 @@ | ||
//! Adapted from | ||
//! https://github.com/rust-lang/rust/blob/master/src/tools/generate-windows-sys/src/main.rs | ||
|
||
use std::{ | ||
fs, | ||
io::{BufWriter, Write as _}, | ||
}; | ||
|
||
use regex::Regex; | ||
|
||
/// This is printed to the file before the rest of the contents. | ||
const PRELUDE: &str = r#"// This file is autogenerated. | ||
// | ||
// To add bindings, edit windows_sys.lst then run: | ||
// | ||
// ``` | ||
// cd dev-tools/generate-windows-sys/ | ||
// cargo run | ||
// ```"#; | ||
|
||
const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); | ||
|
||
pub fn generate_bindings() { | ||
let filter: String = format!("{MANIFEST_DIR}/windows_sys.list"); | ||
let temp_file = tempfile::Builder::new() | ||
.suffix(".rs") | ||
.tempfile() | ||
.expect("failed to create temp file"); | ||
|
||
// Generate bindings. | ||
windows_bindgen::bindgen([ | ||
"--flat", | ||
"--sys", | ||
"--no-deps", | ||
"--out", | ||
temp_file.path().to_str().unwrap(), | ||
"--filter", | ||
"--etc", | ||
&filter, | ||
]) | ||
.unwrap(); | ||
|
||
let bindings = | ||
fs::read_to_string(temp_file.path()).expect("failed to read temp windows_sys.rs"); | ||
|
||
let mut f: BufWriter<fs::File> = fs::File::create(format!( | ||
"{MANIFEST_DIR}/../../find-msvc-tools/src/windows_sys.rs" | ||
)) | ||
.map(BufWriter::new) | ||
.expect("failed to create windows_sys.rs"); | ||
|
||
write!(&mut f, "{PRELUDE}\n{bindings}\n").unwrap(); | ||
|
||
let mut dll_names: Vec<&str> = Regex::new(r#"link!\("(.*)\.dll""#) | ||
.unwrap() | ||
.captures_iter(&bindings) | ||
.map(|caps| caps.extract().1) | ||
.map(|[dll_name]| dll_name) | ||
.filter(|dll_name| *dll_name != "kernel32") | ||
.collect(); | ||
|
||
if !dll_names.is_empty() { | ||
dll_names.sort_unstable(); | ||
dll_names.dedup(); | ||
|
||
for dll_name in dll_names { | ||
write!(&mut f, r#"#[link(name = "{dll_name}")]"#).unwrap(); | ||
f.write_all("\n".as_bytes()).unwrap(); | ||
} | ||
|
||
f.write_all(r#"extern "C" {}"#.as_bytes()).unwrap(); | ||
f.write_all("\n".as_bytes()).unwrap(); | ||
} | ||
|
||
f.write_all(r#"use super::windows_link;"#.as_bytes()) | ||
.unwrap(); | ||
f.write_all("\n".as_bytes()).unwrap(); | ||
|
||
f.into_inner().unwrap().sync_all().unwrap(); | ||
} |
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 |
---|---|---|
@@ -1,77 +1,3 @@ | ||
//! Adapted from | ||
//! https://github.com/rust-lang/rust/blob/master/src/tools/generate-windows-sys/src/main.rs | ||
|
||
use std::{ | ||
fs, | ||
io::{BufWriter, Write as _}, | ||
}; | ||
|
||
use regex::Regex; | ||
|
||
/// This is printed to the file before the rest of the contents. | ||
const PRELUDE: &str = r#"// This file is autogenerated. | ||
// | ||
// To add bindings, edit windows_sys.lst then run: | ||
// | ||
// ``` | ||
// cd generate-windows-sys/ | ||
// cargo run | ||
// ```"#; | ||
|
||
fn main() { | ||
let manifest_dir = env!("CARGO_MANIFEST_DIR"); | ||
let filter = format!("{manifest_dir}/windows_sys.list"); | ||
let temp_file = tempfile::Builder::new() | ||
.suffix(".rs") | ||
.tempfile() | ||
.expect("failed to create temp file"); | ||
|
||
// Generate bindings. | ||
windows_bindgen::bindgen([ | ||
"--flat", | ||
"--sys", | ||
"--no-deps", | ||
"--out", | ||
temp_file.path().to_str().unwrap(), | ||
"--filter", | ||
"--etc", | ||
&filter, | ||
]) | ||
.unwrap(); | ||
|
||
let bindings = | ||
fs::read_to_string(temp_file.path()).expect("failed to read temp windows_sys.rs"); | ||
|
||
let mut f = fs::File::create(format!("{manifest_dir}/../../src/windows/windows_sys.rs")) | ||
.map(BufWriter::new) | ||
.expect("failed to create windows_sys.rs"); | ||
|
||
write!(&mut f, "{PRELUDE}\n{bindings}\n").unwrap(); | ||
|
||
let mut dll_names: Vec<&str> = Regex::new(r#"link!\("(.*)\.dll""#) | ||
.unwrap() | ||
.captures_iter(&bindings) | ||
.map(|caps| caps.extract().1) | ||
.map(|[dll_name]| dll_name) | ||
.filter(|dll_name| *dll_name != "kernel32") | ||
.collect(); | ||
|
||
if !dll_names.is_empty() { | ||
dll_names.sort_unstable(); | ||
dll_names.dedup(); | ||
|
||
for dll_name in dll_names { | ||
write!(&mut f, r#"#[link(name = "{dll_name}")]"#).unwrap(); | ||
f.write_all("\n".as_bytes()).unwrap(); | ||
} | ||
|
||
f.write_all(r#"extern "C" {}"#.as_bytes()).unwrap(); | ||
f.write_all("\n".as_bytes()).unwrap(); | ||
} | ||
|
||
f.write_all(r#"use super::windows_link;"#.as_bytes()) | ||
.unwrap(); | ||
f.write_all("\n".as_bytes()).unwrap(); | ||
|
||
f.into_inner().unwrap().sync_all().unwrap(); | ||
gen_windows_sys_binding::generate_bindings(); | ||
} |
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,18 @@ | ||
[package] | ||
name = "find-msvc-tools" | ||
version = "0.1.0" | ||
edition = "2018" | ||
license = "MIT OR Apache-2.0" | ||
repository = "https://github.com/rust-lang/cc-rs" | ||
documentation = "https://docs.rs/find-msvc-tools" | ||
description = "Find windows-specific tools, read MSVC versions from the registry and from COM interfaces" | ||
keywords = ["build-dependencies"] | ||
categories = ["development-tools::build-utils"] | ||
rust-version = "1.63" | ||
|
||
|
||
[dependencies] | ||
|
||
[lints.rust] | ||
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(disable_clang_cl_tests)'] } | ||
|
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 @@ | ||
../LICENSE-APACHE |
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 @@ | ||
../LICENSE-MIT |
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,25 @@ | ||
# find-msvc-tools | ||
|
||
NobodyXu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> This crate is maintained by the library team, primarily for use by the `cc` crate and not intended for external use (except as a transitive dependency). This crate may make major changes to its APIs or be deprecated without warning. | ||
|
||
An internal use library for finding windows-specific tools, reading MSVC versions from the | ||
registry and from COM interfaces. | ||
|
||
Refer to the [documentation](https://docs.rs/find-msvc-tools) for detailed usage instructions. | ||
|
||
## License | ||
|
||
This project is licensed under either of | ||
|
||
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or | ||
https://www.apache.org/licenses/LICENSE-2.0) | ||
* MIT license ([LICENSE-MIT](LICENSE-MIT) or | ||
https://opensource.org/licenses/MIT) | ||
|
||
at your option. | ||
|
||
### Contribution | ||
|
||
Unless you explicitly state otherwise, any contribution transitively intentionally submitted | ||
for inclusion in find-msvc-tools by you, as defined in the Apache-2.0 license, shall be | ||
dual licensed as above, without any additional terms or conditions. |
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.
Uh oh!
There was an error while loading. Please reload this page.