Skip to content

Commit

Permalink
Upgrade to windows 0.51 (#3)
Browse files Browse the repository at this point in the history
* Upgrade to `windows 0.51`

* Go back to `api_gen` depending on `windows-bindgen`, `riddle` remains unpublished
  • Loading branch information
MarijnS95 committed Aug 26, 2023
1 parent 82b8d8c commit fa55fdb
Show file tree
Hide file tree
Showing 12 changed files with 373 additions and 602 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
((Resolve-Path "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\*\bin\Hostx64\x64")
| Sort-Object -Descending | Select -First 1).ToString() >> $env:GITHUB_PATH
- name: Generate
run: dotnet build .metadata
run: dotnet build .metadata
- name: Upload
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -57,4 +57,4 @@ jobs:
name: crate-source
path: src/
- name: Diff generated Rust code
run: test -z "$(git status --porcelain -- '!.windows')" || (echo "::error::Generated files are different, please regenerate with cargo run -p api_gen!"; git diff; false)
run: test -z "$(git status --porcelain -- '!.windows')" || (echo "::error::Generated files are different, please regenerate with cargo run -p api_gen!"; git status; false)
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ include = ["src", "LICENSE"]
[dependencies]
anyhow = "1"
libloading = "0.8"
# Autogenerated bindings reference `::windows_core` instead of `::windows::core`
windows-core = "0.51"

[dependencies.windows]
# TODO: Switch to windows-core when it is published
version = "0.48"
version = "0.51"
features = [
"implement",
"Win32_Foundation",
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Rust bindings for AMD's DirectX12 RGP markers

[![Actions Status](https://github.com/Traverse-Research/amd-ext-d3d-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/Traverse-Research/amd-ext-d3d-rs/actions/workflows/ci.yml)
[![Latest version](https://img.shields.io/crates/v/amd-ext-d3d.svg)](https://crates.io/crates/amd-ext-d3d)
[![Latest version](https://img.shields.io/crates/v/amd-ext-d3d.svg?logo=rust)](https://crates.io/crates/amd-ext-d3d)
[![Documentation](https://docs.rs/amd-ext-d3d/badge.svg)](https://docs.rs/amd-ext-d3d)
[![Lines of code](https://tokei.rs/b1/github/Traverse-Research/amd-ext-d3d-rs)](https://github.com/Traverse-Research/amd-ext-d3d-rs)
![MIT](https://img.shields.io/badge/license-MIT-blue.svg)
Expand All @@ -25,8 +25,10 @@ While [upstream documentation] details how to embed these calls into existing PI
```rust,no_run
use amd_ext_d3d::AmdExtD3DDevice;
use std::ffi::CStr;
use windows::core::CanInto;
use windows::Win32::Graphics::Direct3D12::{ID3D12Device, ID3D12GraphicsCommandList};
use windows::{
core::CanInto,
Win32::Graphics::Direct3D12::{ID3D12Device, ID3D12GraphicsCommandList},
};
let device: ID3D12Device = todo!("Open DirectX12 graphics device");
let cmd_list: ID3D12GraphicsCommandList = todo!("device.CreateCommandList(...)");
Expand Down
4 changes: 1 addition & 3 deletions api_gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ edition = "2021"
publish = false

[dependencies]
anyhow = "1"
windows-bindgen = "0.49"
windows-metadata = "0.49"
windows-bindgen = "0.51"
49 changes: 3 additions & 46 deletions api_gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,7 @@
use std::io::prelude::*;

use anyhow::{Context, Result};
use windows_metadata::reader::File;
use windows_bindgen::{bindgen, Result};

fn main() -> Result<()> {
let start = std::time::Instant::now();
let output_path = std::path::PathBuf::from("src");

let winmd_files = [
File::new(".windows/winmd/Amd.Ext.D3D.winmd")?,
File::new(".windows/winmd/Windows.Win32.winmd")?,
];

let _ = std::fs::remove_dir_all(output_path.join("Amd"));

for namespace in ["Amd", "Amd.Ext", "Amd.Ext.D3D"] {
let path = output_path.join(namespace.replace('.', "/"));
std::fs::create_dir_all(&path)?;
let tokens = windows_bindgen::component(namespace, &winmd_files);
let output = std::fs::File::create(path.join("mod.rs"))?;
fmt_tokens(&tokens, output).context("While formatting tokens")?;
}

println!("Took {:.1?}", start.elapsed());

Ok(())
}

fn fmt_tokens(tokens: &str, output: std::fs::File) -> Result<()> {
let mut child = std::process::Command::new("rustfmt")
.stdin(std::process::Stdio::piped())
.stdout(output)
.spawn()
.context("Failed to spawn `rustfmt`")?;

let mut stdin = child.stdin.take().context("Failed to open stdin")?;
stdin.write_all(tokens.as_bytes())?;
drop(stdin);

let output = child.wait_with_output()?;
let stderr = std::str::from_utf8(&output.stderr)?;
anyhow::ensure!(output.status.success(), "rustfmt failed: {}", stderr);

if !stderr.is_empty() {
eprintln!("rustfmt stderr: {}", stderr)
}

let log = bindgen(["--etc", "bindings.txt"])?;
println!("{}", log);
Ok(())
}
5 changes: 5 additions & 0 deletions bindings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--in .windows/winmd/
--out src/Amd.rs

--filter
Amd
2 changes: 1 addition & 1 deletion release.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sign-tag = true
publish = false

pre-release-replacements = [
{file="README.md", search="amd-ext-d3d = .*", replace="{{crate_name}} = \"{{version}}\""},
{ file = "README.md", search = "amd-ext-d3d = .*", replace = "{{crate_name}} = \"{{version}}\"" },
]

# cargo-release only allows using {{version}} in the commit title when creating one
Expand Down
Loading

0 comments on commit fa55fdb

Please sign in to comment.