Skip to content

Commit

Permalink
Remove bindgen as build dependency for adlx (#8)
Browse files Browse the repository at this point in the history
* Make binding generation an optinal feature

Use --features=bindgen

* Introduce api-gen crate

* Remove placeholder code from api-gen/lib.rs

* Add ADLX as submodule

* Remove checked in SDK files

* Fix wrapper.h

* Move ADLX to vendor/

* Submodule, api_gen rework (#9)

* Submodule, api_gen rework

* Renormalize line endings before `git diff`

* ci: Work around `regex` compilation failure in MSRV check

* Cleanup

* Fix clippy error

* Revert crate name back to adlx

* Fix error in example

---------

Co-authored-by: Marijn Suijten <[email protected]>
  • Loading branch information
KYovchevski and MarijnS95 authored Jan 29, 2024
1 parent 7e2e970 commit d02e393
Show file tree
Hide file tree
Showing 52 changed files with 6,317 additions and 25,528 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,27 @@ jobs:
- name: Generate minimal-version dependencies
run: cargo -Zminimal-versions generate-lockfile
- uses: dtolnay/[email protected]
- name: Upgrade to [email protected]
# Workaround for:
# https://github.com/rust-lang/regex/issues/931
# https://github.com/rust-lang/rust-bindgen/pull/2714
run: cargo update -p regex --precise 1.5.1
- name: Cargo check
run: cargo check --workspace --all-targets

generate:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Checkout submodule
# Manually update submodules with --checkout because they are configured with update=none and will be skipped otherwise
run: git submodule update --recursive --init --force --checkout
- name: Run generator
run: cargo r -p api_gen
- name: Normalize line endings
run: |
git add --renormalize -u
git reset
- name: Diff autogen result
shell: bash
run: test -z "$(git status --porcelain)" || (echo "::error::Generated files are different, please regenerate with cargo run -p api_gen!"; git diff; false)
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[submodule "ADLX"]
path = vendor/ADLX
url = https://github.com/GPUOpen-LibrariesAndSDKs/ADLX
depth = 1
update = none
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ keywords = ["amd", "adlx", "gpu"]
anyhow = "1.0.79"
libloading = "0.8"

[build-dependencies]
bindgen = "0.69.2"
[workspace]
members = [
"api_gen"
]
8 changes: 8 additions & 0 deletions api_gen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "api_gen"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies]
bindgen = "0.69.2"
21 changes: 21 additions & 0 deletions api_gen/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::path::Path;

fn main() {
let crate_root = Path::new(env!("CARGO_MANIFEST_DIR"));

let header_path = crate_root.join("wrapper.h");

let bindings = bindgen::Builder::default()
.header(header_path.to_string_lossy())
.clang_arg(format!(
"-I{}",
crate_root.join("../vendor/ADLX/SDK/Include/").display()
))
.allowlist_item("I?ADLX\\w+")
.generate()
.expect("failed to generate adlx bindings");

bindings
.write_to_file(crate_root.join("../src/ffi.rs"))
.expect("Couldn't write bindings!");
}
6 changes: 6 additions & 0 deletions api_gen/wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <ADLX.h>

// Interfaces to generate bindings for
#include <ISystem1.h>
#include <IPerformanceMonitoring.h>
#include <IPerformanceMonitoring1.h>
17 changes: 0 additions & 17 deletions build.rs

This file was deleted.

2 changes: 1 addition & 1 deletion examples/system.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Open the ADLX library, retrieve [`adlx::adlx::system::System`], and call a simple function on it
use adlx::{gpu::Gpu1, helper::AdlxHelper, interface::Interface};
use adlx::helper::AdlxHelper;
use anyhow::Result;

fn main() -> Result<()> {
Expand Down
175 changes: 0 additions & 175 deletions src/adlx/sdk/ADLXHelper/Windows/C/ADLXHelper.c

This file was deleted.

Loading

0 comments on commit d02e393

Please sign in to comment.