Skip to content

Commit

Permalink
move Windows code into a module (#924)
Browse files Browse the repository at this point in the history
  • Loading branch information
Be-ing authored Jan 30, 2024
1 parent 46fdb0b commit 3aa67cc
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 34 deletions.
7 changes: 5 additions & 2 deletions dev-tools/gen-windows-sys-binding/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ const fn invalid_mut<T>(addr: usize) -> *mut T {
"#;

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

let mut f = fs::File::create("../src/windows_sys.rs")?;
let mut f = fs::File::create(format!("{manifest_dir}/../../src/windows/windows_sys.rs"))
.expect("failed to create windows_sys.rs");
f.write_all(PRELUDE.as_bytes())?;
f.write_all(bindings.as_bytes())?;
f.write_all(POSTLUDE.as_bytes())?;
Expand Down
21 changes: 4 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,10 @@ use std::sync::{Arc, Mutex};
mod os_pipe;
#[cfg(feature = "parallel")]
mod parallel;
// These modules are all glue to support reading the MSVC version from
// the registry and from COM interfaces
#[cfg(windows)]
mod registry;
#[cfg(windows)]
#[macro_use]
mod winapi;
#[cfg(windows)]
mod com;
#[cfg(windows)]
mod setup_config;
#[cfg(windows)]
mod vs_instances;
#[cfg(windows)]
mod windows_sys;

pub mod windows_registry;
mod windows;
// Regardless of whether this should be in this crate's public API,
// it has been since 2015, so don't break it.
pub use windows::find_tools as windows_registry;

mod command_helpers;
use command_helpers::*;
Expand Down
2 changes: 1 addition & 1 deletion src/os_pipe/windows.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::windows_sys::{CreatePipe, INVALID_HANDLE_VALUE};
use crate::windows::windows_sys::{CreatePipe, INVALID_HANDLE_VALUE};
use std::{fs::File, io, os::windows::prelude::*, ptr};

/// NOTE: These pipes do not support IOCP.
Expand Down
2 changes: 1 addition & 1 deletion src/parallel/job_token/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
io, ptr,
};

use crate::windows_sys::{
use crate::windows::windows_sys::{
OpenSemaphoreA, ReleaseSemaphore, WaitForSingleObject, FALSE, HANDLE, SEMAPHORE_MODIFY_STATE,
THREAD_SYNCHRONIZE, WAIT_ABANDONED, WAIT_FAILED, WAIT_OBJECT_0, WAIT_TIMEOUT,
};
Expand Down
2 changes: 1 addition & 1 deletion src/com.rs → src/windows/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#![allow(unused)]

use crate::{
use crate::windows::{
winapi::{IUnknown, Interface},
windows_sys::{
CoInitializeEx, SysFreeString, SysStringLen, BSTR, COINIT_MULTITHREADED, HRESULT, S_FALSE,
Expand Down
8 changes: 4 additions & 4 deletions src/windows_registry.rs → src/windows/find_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ pub fn find_vs_version() -> Result<VsVers, String> {

#[cfg(windows)]
mod impl_ {
use crate::com;
use crate::registry::{RegistryKey, LOCAL_MACHINE};
use crate::setup_config::SetupConfiguration;
use crate::vs_instances::{VsInstances, VswhereInstance};
use crate::windows::com;
use crate::windows::registry::{RegistryKey, LOCAL_MACHINE};
use crate::windows::setup_config::SetupConfiguration;
use crate::windows::vs_instances::{VsInstances, VswhereInstance};
use std::convert::TryFrom;
use std::env;
use std::ffi::OsString;
Expand Down
20 changes: 20 additions & 0 deletions src/windows/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! These modules are all glue to support reading the MSVC version from
//! the registry and from COM interfaces.
// This is used in the crate's public API, so don't use #[cfg(windows)]
pub mod find_tools;

#[cfg(windows)]
pub(crate) mod windows_sys;

#[cfg(windows)]
mod registry;
#[cfg(windows)]
#[macro_use]
mod winapi;
#[cfg(windows)]
mod com;
#[cfg(windows)]
mod setup_config;
#[cfg(windows)]
mod vs_instances;
2 changes: 1 addition & 1 deletion src/registry.rs → src/windows/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use crate::windows_sys::{
use crate::windows::windows_sys::{
RegCloseKey, RegEnumKeyExW, RegOpenKeyExW, RegQueryValueExW, ERROR_NO_MORE_ITEMS,
ERROR_SUCCESS, HKEY, HKEY_LOCAL_MACHINE, KEY_READ, KEY_WOW64_32KEY, REG_SZ,
};
Expand Down
2 changes: 1 addition & 1 deletion src/setup_config.rs → src/windows/setup_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![allow(bad_style)]
#![allow(unused)]

use crate::{
use crate::windows::{
com::{BStr, ComPtr},
winapi::{
IUnknown, IUnknownVtbl, Interface, LCID, LPCOLESTR, LPCWSTR, LPFILETIME, LPSAFEARRAY,
Expand Down
2 changes: 1 addition & 1 deletion src/vs_instances.rs → src/windows/vs_instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::convert::TryFrom;
use std::io::BufRead;
use std::path::PathBuf;

use crate::setup_config::{EnumSetupInstances, SetupInstance};
use crate::windows::setup_config::{EnumSetupInstances, SetupInstance};

pub enum VsInstance {
Com(SetupInstance),
Expand Down
10 changes: 5 additions & 5 deletions src/winapi.rs → src/windows/winapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::os::raw;

pub type wchar_t = u16;

pub use crate::windows_sys::{FILETIME, GUID, HRESULT, SAFEARRAY};
pub use crate::windows::windows_sys::{FILETIME, GUID, HRESULT, SAFEARRAY};

pub type REFIID = *const IID;
pub type IID = GUID;
Expand All @@ -37,7 +37,7 @@ macro_rules! DEFINE_GUID {
$name:ident, $l:expr, $w1:expr, $w2:expr,
$b1:expr, $b2:expr, $b3:expr, $b4:expr, $b5:expr, $b6:expr, $b7:expr, $b8:expr
) => {
pub const $name: $crate::winapi::GUID = $crate::winapi::GUID {
pub const $name: $crate::windows::winapi::GUID = $crate::windows::winapi::GUID {
data1: $l,
data2: $w1,
data3: $w2,
Expand Down Expand Up @@ -121,10 +121,10 @@ macro_rules! RIDL {
$l:expr, $w1:expr, $w2:expr,
$b1:expr, $b2:expr, $b3:expr, $b4:expr, $b5:expr, $b6:expr, $b7:expr, $b8:expr
) => (
impl $crate::winapi::Interface for $interface {
impl $crate::windows::winapi::Interface for $interface {
#[inline]
fn uuidof() -> $crate::winapi::GUID {
$crate::winapi::GUID {
fn uuidof() -> $crate::windows::winapi::GUID {
$crate::windows::winapi::GUID {
data1: $l,
data2: $w1,
data3: $w2,
Expand Down
File renamed without changes.

0 comments on commit 3aa67cc

Please sign in to comment.