-
Notifications
You must be signed in to change notification settings - Fork 539
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
6 changed files
with
96 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "cppwinrt" | ||
version = "0.1.0" | ||
authors = ["Microsoft"] | ||
edition = "2021" | ||
rust-version = "1.60" | ||
license = "MIT OR Apache-2.0" | ||
description = "C++/WinRT" | ||
repository = "https://github.com/microsoft/windows-rs" | ||
readme = "readme.md" | ||
categories = ["os::windows-apis"] | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[package.metadata.docs.rs] | ||
default-target = "x86_64-pc-windows-msvc" | ||
targets = [] |
Binary file not shown.
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,31 @@ | ||
## C++/WinRT | ||
|
||
The [cppwinrt](https://crates.io/crates/cppwinrt) crate bundles the C++/WinRT compiler for use in Rust. | ||
|
||
* [Getting started](https://kennykerr.ca/rust-getting-started/) | ||
* [Samples](https://github.com/microsoft/windows-rs/tree/0.56.0/crates/samples) <!-- link to samples for upcoming release --> | ||
* [Releases](https://github.com/microsoft/windows-rs/releases) | ||
|
||
Start by adding the following to your Cargo.toml file: | ||
|
||
```toml | ||
[dependencies.cppwinrt] | ||
version = "0.1" | ||
``` | ||
|
||
Use `cppwinrt` function as needed: | ||
|
||
```rust | ||
fn main() { | ||
match cppwinrt::cppwinrt(["-help"]) { | ||
Ok(output) => println!("{output}"), | ||
Err(error) => println!("{error}"), | ||
}; | ||
} | ||
``` | ||
|
||
Source: | ||
|
||
* <https://github.com/microsoft/cppwinrt> | ||
* <https://www.nuget.org/packages/microsoft.windows.cppwinrt> | ||
* Version 2.0.240405.15 |
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,43 @@ | ||
/*! | ||
Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs> | ||
*/ | ||
|
||
const VERSION: &str = "2.0.240405.15"; | ||
|
||
/// Calls the C++/WinRT compiler with the given arguments. | ||
/// | ||
/// Use `cppwinrt["-help"]` for available options. | ||
pub fn cppwinrt<I, S>(args: I) -> Result<String, String> | ||
where | ||
I: IntoIterator<Item = S>, | ||
S: AsRef<std::ffi::OsStr>, | ||
{ | ||
let mut path = std::env::temp_dir(); | ||
path.push(format!("cppwinrt-{VERSION}.exe")); | ||
|
||
std::fs::write(&path, std::include_bytes!("../cppwinrt.exe")).unwrap(); | ||
let mut command = std::process::Command::new(&path); | ||
command.args(args); | ||
let output = command.output().expect("failed to run cppwinrt"); | ||
_ = std::fs::remove_file(path); | ||
|
||
if output.status.success() { | ||
Ok(String::from_utf8_lossy(&output.stdout).to_string()) | ||
} else { | ||
Err(String::from_utf8_lossy(&output.stderr).to_string()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::*; | ||
|
||
#[test] | ||
fn test() { | ||
let ok = cppwinrt(["-help"]).unwrap(); | ||
assert!(ok.contains(VERSION), "unexpected version"); | ||
|
||
let err = cppwinrt(["-invalid"]).unwrap_err(); | ||
assert!(err.contains("'-invalid' is not supported")); | ||
} | ||
} |
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