Start abigen

This commit is contained in:
Artemis Tosini 2024-09-12 23:43:29 +00:00
parent d92b6f2bac
commit ac065b60f7
Signed by: artemist
GPG key ID: ADFFE553DCBB831E
7 changed files with 112 additions and 1 deletions

3
.gitmodules vendored
View file

@ -1,3 +1,6 @@
[submodule "proto/proto"]
path = proto/proto
url = https://github.com/SteamDatabase/Protobufs
[submodule "abigen/proton"]
path = abigen/proton
url = https://github.com/ValveSoftware/Proton

37
Cargo.lock generated
View file

@ -197,6 +197,26 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clang"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84c044c781163c001b913cd018fc95a628c50d0d2dfea8bca77dad71edb16e37"
dependencies = [
"clang-sys",
"libc",
]
[[package]]
name = "clang-sys"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
dependencies = [
"glob",
"libc",
]
[[package]]
name = "color-eyre"
version = "0.6.3"
@ -552,6 +572,12 @@ version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "hashbrown"
version = "0.14.5"
@ -1955,6 +1981,17 @@ dependencies = [
"vapore-struct",
]
[[package]]
name = "vapore-abigen"
version = "0.1.0"
dependencies = [
"clang",
"color-eyre",
"env_logger",
"log",
"regex",
]
[[package]]
name = "vapore-client"
version = "0.0.0"

View file

@ -1,6 +1,7 @@
[workspace]
resolver = "2"
members = [
"abigen",
"client",
"lib",
"proto",

11
abigen/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "vapore-abigen"
edition = "2021"
version.workspace = true
[dependencies]
clang = { version = "2.0.0", features = ["clang_10_0"] }
color-eyre.workspace = true
env_logger.workspace = true
log.workspace = true
regex = "1.10.6"

1
abigen/proton Submodule

@ -0,0 +1 @@
Subproject commit 962bbc4e74dde0643a6edab7c845bc628601f23f

56
abigen/src/main.rs Normal file
View file

@ -0,0 +1,56 @@
use std::{collections::HashMap, env, path::PathBuf, vec};
use clang::{Entity, EntityKind};
use color_eyre::eyre;
use regex::Regex;
fn main() -> eyre::Result<()> {
env_logger::init();
color_eyre::install()?;
let re = Regex::new(r#"^#define\s*(STEAM[A-Z]*)_INTERFACE_VERSION\s*"([a-zA-Z0-9_]*)"$"#)?;
let lsteamclient_path =
PathBuf::from(env::var_os("PROTON_SOURCE").unwrap_or_else(|| "proton".into()))
.join("lsteamclient");
let clang = clang::Clang::new().unwrap();
let index = clang::Index::new(&clang, false, false);
let parsed = index
.parser(
lsteamclient_path
.join("steamworks_sdk_160")
.join("steam_api.h"),
)
.arguments(&["-x", "c++"])
.detailed_preprocessing_record(true)
.parse()?;
let mut classes = Vec::new();
// let mut interfaces = HashMap::new();
for child in parsed.get_entity().get_children() {
if child.get_kind() == EntityKind::ClassDecl {
let Some(class_name) = child.get_name() else {
continue;
};
if !class_name.starts_with("ISteam") {
continue;
};
if child.get_children().len() == 0 {
continue;
}
log::info!("Found class `{}`", class_name);
classes.push(class_name);
}
}
Ok(())
}

View file

@ -18,7 +18,7 @@
{
devShells.default =
with pkgs;
mkShell {
(mkShell.override { stdenv = llvmPackages.stdenv; }) {
packages = [
rustPackages.cargo
rustPackages.rustc
@ -27,6 +27,8 @@
protobuf
];
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";
RUST_SRC_PATH = "${rustPackages.rustPlatform.rustLibSrc}";
RUST_LOG = "debug,vapore=trace,vapore-client=trace";
RUST_BACKTRACE = "1";