Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,13 @@ jobs:
- uses: Swatinem/rust-cache@v2
- run: cargo fmt -- --check

semver-checks:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Check semver
uses: obi1kenobi/cargo-semver-checks-action@v2
#semver-checks:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v5
# - name: Check semver
# uses: obi1kenobi/cargo-semver-checks-action@v2

# Dummy job to have a stable name for the "all tests pass" requirement
tests-pass:
Expand All @@ -422,7 +422,7 @@ jobs:
- msrv
- clippy
- rustfmt
- semver-checks
#- semver-checks
if: always() # always run even if dependencies fail
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rust-version = "1.63"
[dependencies]
jobserver = { version = "0.1.30", default-features = false, optional = true }
shlex = "1.3.0"
find-msvc-tools = { version = "0.1.0", path = "find-msvc-tools" }

[target.'cfg(unix)'.dependencies]
# Don't turn on the feature "std" for this, see https://github.com/rust-lang/cargo/issues/4866
Expand All @@ -39,6 +40,7 @@ tempfile = "3"

[workspace]
members = [
"find-msvc-tools",
"dev-tools/cc-test",
"dev-tools/gen-target-info",
"dev-tools/gen-windows-sys-binding",
Expand Down
80 changes: 80 additions & 0 deletions dev-tools/gen-windows-sys-binding/src/lib.rs
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();
}
76 changes: 1 addition & 75 deletions dev-tools/gen-windows-sys-binding/src/main.rs
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();
}
18 changes: 18 additions & 0 deletions find-msvc-tools/Cargo.toml
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)'] }

1 change: 1 addition & 0 deletions find-msvc-tools/LICENSE-APACHE
1 change: 1 addition & 0 deletions find-msvc-tools/LICENSE-MIT
25 changes: 25 additions & 0 deletions find-msvc-tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# find-msvc-tools

> 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.
2 changes: 1 addition & 1 deletion src/windows/com.rs → find-msvc-tools/src/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// All files in the project carrying such notice may not be copied, modified, or distributed
// except according to those terms.

use crate::windows::{
use crate::{
winapi::{IUnknown, Interface},
windows_sys::{
CoInitializeEx, SysFreeString, SysStringLen, BSTR, COINIT_MULTITHREADED, HRESULT, S_FALSE,
Expand Down
Loading
Loading