-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
285 additions
and
263 deletions.
There are no files selected for viewing
This file contains 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 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 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,7 @@ | ||
[package] | ||
name = "windows_fmt" | ||
version = "0.0.0" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
windows_gen = { path = "../gen" } |
This file contains 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,60 @@ | ||
use std::ffi::OsStr; | ||
use std::io::Result; | ||
use std::io::Write; | ||
use std::path::*; | ||
use std::process::Command; | ||
use std::process::Stdio; | ||
|
||
fn format_file(file: &Path, pattern: &str) -> Result<()> { | ||
const SHIM: &str = "use format_build_macro::{"; | ||
|
||
let contents = std::fs::read(file)?; | ||
let contents = String::from_utf8(contents).expect("Failed to parse UTF-8"); | ||
|
||
// Replace macro call with our `use` pattern | ||
let contents = contents.replace(pattern, SHIM); | ||
|
||
// Spawn `rustfmt` and pipe string through it, instead of writing it to disk | ||
let mut child = Command::new("rustfmt") | ||
.stdin(Stdio::piped()) | ||
.stdout(Stdio::piped()) | ||
.spawn() | ||
.expect("Failed to spawn `rustfmt`"); | ||
let mut stdin = child.stdin.take().expect("Failed to open stdin"); | ||
stdin.write_all(contents.as_bytes())?; | ||
drop(stdin); | ||
|
||
// Read formatted output from `rustfmt` | ||
let output = child.wait_with_output().expect("Failed to read stdout"); | ||
let contents = String::from_utf8(output.stdout).expect("Failed to parse UTF-8"); | ||
|
||
// Some build macros contain a single item, where curly braces are removed. Those | ||
// cannot easily be formatted yet. | ||
if contents.contains(SHIM) { | ||
std::fs::write(file, contents.replace(SHIM, pattern))?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn walk_path(path: &Path) -> Result<()> { | ||
if path.is_dir() { | ||
for entry in path.read_dir()? { | ||
walk_path(&entry?.path())?; | ||
} | ||
} else if path.file_name() == Some(OsStr::new("build.rs")) { | ||
format_file(path, "windows::build! {")?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let dir = windows_gen::workspace_dir(); | ||
walk_path(&dir)?; | ||
|
||
format_file( | ||
&dir.join("crates/bindings/src/main.rs"), | ||
"let tokens = windows_macros::generate! {", | ||
) | ||
} |
This file contains 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 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,6 +1,6 @@ | ||
fn main() { | ||
windows::build!( | ||
Windows::Foundation::{MemoryBuffer, IMemoryBufferReference}, | ||
windows::build! { | ||
Windows::Foundation::{IMemoryBufferReference, MemoryBuffer}, | ||
Windows::Win32::System::WinRT::IMemoryBufferByteAccess, | ||
); | ||
}; | ||
} |
This file contains 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 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,6 +1,5 @@ | ||
fn main() { | ||
windows::build!( | ||
Windows::Win32::System::OleAutomation::BSTR, | ||
Windows::Win32::System::Com::CreateUri, | ||
); | ||
windows::build! { | ||
Windows::Win32::System::Com::CreateUri, Windows::Win32::System::OleAutomation::BSTR, | ||
}; | ||
} |
This file contains 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,6 +1,3 @@ | ||
fn main() { | ||
windows::build!( | ||
Windows::ApplicationModel::Core::*, | ||
Windows::UI::Core::*, | ||
); | ||
windows::build! {Windows::ApplicationModel::Core::*, Windows::UI::Core::*}; | ||
} |
This file contains 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,60 +1,22 @@ | ||
fn main() { | ||
windows::build!( | ||
Windows::Win32::Graphics::Direct3D12::*, | ||
Windows::Win32::Graphics::Dxgi::*, | ||
windows::build! { | ||
Windows::Win32::Graphics::Direct3D11::{ | ||
D3D_FEATURE_LEVEL_11_0, | ||
D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST | ||
D3D_FEATURE_LEVEL_11_0, D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST, | ||
}, | ||
Windows::Win32::Graphics::Direct3D12::*, | ||
Windows::Win32::Graphics::Dxgi::*, | ||
Windows::Win32::Graphics::Hlsl::*, | ||
Windows::Win32::System::SystemServices::{GetModuleHandleA, HINSTANCE, PSTR}, | ||
Windows::Win32::System::Threading::{CreateEventA, WaitForSingleObject}, | ||
Windows::Win32::System::WindowsProgramming::INFINITE, | ||
Windows::Win32::UI::DisplayDevices::RECT, | ||
Windows::Win32::UI::WindowsAndMessaging::{ | ||
AdjustWindowRect, | ||
CREATESTRUCTA, | ||
CreateWindowExA, | ||
CS_HREDRAW, | ||
CS_VREDRAW, | ||
CW_USEDEFAULT, | ||
DefWindowProcA, | ||
DispatchMessageA, | ||
GetWindowLongA, | ||
GetWindowLongPtrA, | ||
GWLP_USERDATA, | ||
IDC_ARROW, | ||
LoadCursorW, | ||
MSG, | ||
PeekMessageA, | ||
PM_REMOVE, | ||
PostQuitMessage, | ||
RegisterClassExA, | ||
SetWindowLongA, | ||
SetWindowLongPtrA, | ||
ShowWindow, | ||
SW_SHOW, | ||
TranslateMessage, | ||
WM_CREATE, | ||
WM_DESTROY, | ||
WM_KEYDOWN, | ||
WM_KEYUP, | ||
WM_PAINT, | ||
WM_QUIT, | ||
WNDCLASS_STYLES, | ||
WNDCLASSEXA, | ||
WS_OVERLAPPEDWINDOW, | ||
}, | ||
Windows::Win32::System::SystemServices::{ | ||
GetModuleHandleA, | ||
HINSTANCE, | ||
PSTR, | ||
}, | ||
Windows::Win32::System::Threading::{ | ||
CreateEventA, | ||
WaitForSingleObject | ||
}, | ||
Windows::Win32::System::WindowsProgramming::{ | ||
INFINITE | ||
}, | ||
Windows::Win32::UI::DisplayDevices::{ | ||
RECT | ||
AdjustWindowRect, CreateWindowExA, DefWindowProcA, DispatchMessageA, GetWindowLongA, | ||
GetWindowLongPtrA, LoadCursorW, PeekMessageA, PostQuitMessage, RegisterClassExA, | ||
SetWindowLongA, SetWindowLongPtrA, ShowWindow, TranslateMessage, CREATESTRUCTA, | ||
CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT, GWLP_USERDATA, IDC_ARROW, MSG, PM_REMOVE, | ||
SW_SHOW, WM_CREATE, WM_DESTROY, WM_KEYDOWN, WM_KEYUP, WM_PAINT, WM_QUIT, WNDCLASSEXA, | ||
WNDCLASS_STYLES, WS_OVERLAPPEDWINDOW, | ||
}, | ||
); | ||
}; | ||
} |
This file contains 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,5 +1,5 @@ | ||
fn main() { | ||
windows::build!( | ||
windows::build! { | ||
Windows::Win32::UI::WindowsAndMessaging::{EnumWindows, GetWindowTextW} | ||
); | ||
}; | ||
} |
This file contains 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,8 +1,8 @@ | ||
fn main() { | ||
windows::build!( | ||
windows::build! { | ||
Windows::Win32::System::Threading::{ | ||
CreateEventW, SetEvent, WaitForSingleObject, WAIT_OBJECT_0, | ||
}, | ||
Windows::Win32::System::WindowsProgramming::CloseHandle | ||
); | ||
Windows::Win32::System::WindowsProgramming::CloseHandle, | ||
}; | ||
} |
This file contains 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,5 +1,5 @@ | ||
fn main() { | ||
windows::build!( | ||
windows::build! { | ||
Windows::Win32::UI::WindowsAndMessaging::{MessageBoxA, MB_OK} | ||
); | ||
}; | ||
} |
This file contains 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,9 +1,9 @@ | ||
fn main() { | ||
windows::build!( | ||
Windows::Graphics::Imaging::{SoftwareBitmap, BitmapDecoder}, | ||
Windows::Media::Ocr::{OcrEngine, OcrResult}, | ||
Windows::Storage::{FileAccessMode, StorageFile}, | ||
windows::build! { | ||
Windows::Foundation::IAsyncOperation, | ||
Windows::Graphics::Imaging::{BitmapDecoder, SoftwareBitmap}, | ||
Windows::Media::Ocr::{OcrEngine, OcrResult}, | ||
Windows::Storage::Streams::IRandomAccessStream, | ||
); | ||
Windows::Storage::{FileAccessMode, StorageFile}, | ||
}; | ||
} |
This file contains 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,14 +1,12 @@ | ||
fn main() { | ||
windows::build!( | ||
Windows::Win32::Storage::FileSystem::{ | ||
CreateFileA, ReadFile, FILE_GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, | ||
FILE_FLAG_OVERLAPPED, | ||
}, | ||
Windows::Win32::System::SystemServices::GetOverlappedResult, | ||
Windows::Win32::System::Threading::{ | ||
CreateEventA, WaitForSingleObject, WAIT_OBJECT_0, | ||
}, | ||
Windows::Win32::System::Diagnostics::Debug::{GetLastError, ERROR_IO_PENDING}, | ||
Windows::Win32::System::WindowsProgramming::CloseHandle, | ||
); | ||
windows::build! { | ||
Windows::Win32::Storage::FileSystem::{ | ||
CreateFileA, ReadFile, FILE_FLAG_OVERLAPPED, FILE_GENERIC_READ, FILE_SHARE_READ, | ||
OPEN_EXISTING, | ||
}, | ||
Windows::Win32::System::Diagnostics::Debug::{GetLastError, ERROR_IO_PENDING}, | ||
Windows::Win32::System::SystemServices::GetOverlappedResult, | ||
Windows::Win32::System::Threading::{CreateEventA, WaitForSingleObject, WAIT_OBJECT_0}, | ||
Windows::Win32::System::WindowsProgramming::CloseHandle, | ||
}; | ||
} |
This file contains 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,10 +1,10 @@ | ||
fn main() { | ||
windows::build!( | ||
windows::build! { | ||
Windows::Foundation::Collections::IVector, | ||
Windows::Foundation::{IAsyncOperationWithProgress, Uri}, | ||
|
||
Windows::Web::Syndication::{ | ||
ISyndicationText, RetrievalProgress, SyndicationClient, SyndicationFeed, SyndicationItem, | ||
ISyndicationText, RetrievalProgress, SyndicationClient, SyndicationFeed, | ||
SyndicationItem, | ||
}, | ||
); | ||
}; | ||
} |
Oops, something went wrong.