Skip to content

Commit 3aa67cc

Browse files
authored
move Windows code into a module (#924)
1 parent 46fdb0b commit 3aa67cc

File tree

12 files changed

+44
-34
lines changed

12 files changed

+44
-34
lines changed

dev-tools/gen-windows-sys-binding/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ const fn invalid_mut<T>(addr: usize) -> *mut T {
3535
"#;
3636

3737
fn main() -> io::Result<()> {
38+
let manifest_dir = env!("CARGO_MANIFEST_DIR");
3839
// Load the list of APIs
39-
let buffer = fs::read_to_string("windows_sys.list")?;
40+
let buffer = fs::read_to_string(format!("{manifest_dir}/windows_sys.list"))
41+
.expect("failed to read windows_sys.list");
4042
let names: Vec<&str> = buffer
4143
.lines()
4244
.filter_map(|line| {
@@ -53,7 +55,8 @@ fn main() -> io::Result<()> {
5355
let bindings =
5456
windows_bindgen::standalone_std(&names).replace("::core::ptr::invalid_mut", "invalid_mut");
5557

56-
let mut f = fs::File::create("../src/windows_sys.rs")?;
58+
let mut f = fs::File::create(format!("{manifest_dir}/../../src/windows/windows_sys.rs"))
59+
.expect("failed to create windows_sys.rs");
5760
f.write_all(PRELUDE.as_bytes())?;
5861
f.write_all(bindings.as_bytes())?;
5962
f.write_all(POSTLUDE.as_bytes())?;

src/lib.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,10 @@ use std::sync::{Arc, Mutex};
6969
mod os_pipe;
7070
#[cfg(feature = "parallel")]
7171
mod parallel;
72-
// These modules are all glue to support reading the MSVC version from
73-
// the registry and from COM interfaces
74-
#[cfg(windows)]
75-
mod registry;
76-
#[cfg(windows)]
77-
#[macro_use]
78-
mod winapi;
79-
#[cfg(windows)]
80-
mod com;
81-
#[cfg(windows)]
82-
mod setup_config;
83-
#[cfg(windows)]
84-
mod vs_instances;
85-
#[cfg(windows)]
86-
mod windows_sys;
87-
88-
pub mod windows_registry;
72+
mod windows;
73+
// Regardless of whether this should be in this crate's public API,
74+
// it has been since 2015, so don't break it.
75+
pub use windows::find_tools as windows_registry;
8976

9077
mod command_helpers;
9178
use command_helpers::*;

src/os_pipe/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::windows_sys::{CreatePipe, INVALID_HANDLE_VALUE};
1+
use crate::windows::windows_sys::{CreatePipe, INVALID_HANDLE_VALUE};
22
use std::{fs::File, io, os::windows::prelude::*, ptr};
33

44
/// NOTE: These pipes do not support IOCP.

src/parallel/job_token/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
io, ptr,
44
};
55

6-
use crate::windows_sys::{
6+
use crate::windows::windows_sys::{
77
OpenSemaphoreA, ReleaseSemaphore, WaitForSingleObject, FALSE, HANDLE, SEMAPHORE_MODIFY_STATE,
88
THREAD_SYNCHRONIZE, WAIT_ABANDONED, WAIT_FAILED, WAIT_OBJECT_0, WAIT_TIMEOUT,
99
};

src/com.rs renamed to src/windows/com.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#![allow(unused)]
99

10-
use crate::{
10+
use crate::windows::{
1111
winapi::{IUnknown, Interface},
1212
windows_sys::{
1313
CoInitializeEx, SysFreeString, SysStringLen, BSTR, COINIT_MULTITHREADED, HRESULT, S_FALSE,

src/windows_registry.rs renamed to src/windows/find_tools.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ pub fn find_vs_version() -> Result<VsVers, String> {
159159

160160
#[cfg(windows)]
161161
mod impl_ {
162-
use crate::com;
163-
use crate::registry::{RegistryKey, LOCAL_MACHINE};
164-
use crate::setup_config::SetupConfiguration;
165-
use crate::vs_instances::{VsInstances, VswhereInstance};
162+
use crate::windows::com;
163+
use crate::windows::registry::{RegistryKey, LOCAL_MACHINE};
164+
use crate::windows::setup_config::SetupConfiguration;
165+
use crate::windows::vs_instances::{VsInstances, VswhereInstance};
166166
use std::convert::TryFrom;
167167
use std::env;
168168
use std::ffi::OsString;

src/windows/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! These modules are all glue to support reading the MSVC version from
2+
//! the registry and from COM interfaces.
3+
4+
// This is used in the crate's public API, so don't use #[cfg(windows)]
5+
pub mod find_tools;
6+
7+
#[cfg(windows)]
8+
pub(crate) mod windows_sys;
9+
10+
#[cfg(windows)]
11+
mod registry;
12+
#[cfg(windows)]
13+
#[macro_use]
14+
mod winapi;
15+
#[cfg(windows)]
16+
mod com;
17+
#[cfg(windows)]
18+
mod setup_config;
19+
#[cfg(windows)]
20+
mod vs_instances;

src/registry.rs renamed to src/windows/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use crate::windows_sys::{
11+
use crate::windows::windows_sys::{
1212
RegCloseKey, RegEnumKeyExW, RegOpenKeyExW, RegQueryValueExW, ERROR_NO_MORE_ITEMS,
1313
ERROR_SUCCESS, HKEY, HKEY_LOCAL_MACHINE, KEY_READ, KEY_WOW64_32KEY, REG_SZ,
1414
};

src/setup_config.rs renamed to src/windows/setup_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#![allow(bad_style)]
99
#![allow(unused)]
1010

11-
use crate::{
11+
use crate::windows::{
1212
com::{BStr, ComPtr},
1313
winapi::{
1414
IUnknown, IUnknownVtbl, Interface, LCID, LPCOLESTR, LPCWSTR, LPFILETIME, LPSAFEARRAY,

src/vs_instances.rs renamed to src/windows/vs_instances.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::convert::TryFrom;
44
use std::io::BufRead;
55
use std::path::PathBuf;
66

7-
use crate::setup_config::{EnumSetupInstances, SetupInstance};
7+
use crate::windows::setup_config::{EnumSetupInstances, SetupInstance};
88

99
pub enum VsInstance {
1010
Com(SetupInstance),

0 commit comments

Comments
 (0)