Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Rust 1.67.0 and latest Mumble APIs #1

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository = "https://github.com/Dessix/rust-mumble-sys"

[dependencies]
collect_slice = "1.2.0"
parking_lot = { version = "~0.11", features = [ "nightly" ] }
parking_lot = { version = "~0.12", features = [ "nightly" ] }

[build-dependencies]
bindgen = { version = "~0.57.0" }
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
Rust bindings for the Mumble Client Plugin API.

## Usage

Preliminary:

- Install Clang

- Download the Mumble source code and create a symlink named `mumble_sources`
pointing to that directory (this crate extracts bindings from the source
code's `plugins/` directory); alternatively set the env variable `MUMBLE_HOME`
to that directory.

To use:

- Create a struct implementing `mumble_sys::traits::MumblePlugin`.

- Use [rust-ctor](https://crates.io/crates/ctor) to set an initializer
Expand Down
49 changes: 47 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(nll)]

#[macro_use]
extern crate const_format;
extern crate bindgen;
Expand Down Expand Up @@ -29,6 +27,33 @@ impl CustomCallbacks {
}
}

fn enum_name_handler(&self, original_variant_name: &str) -> Option<String> {
// Mumble introduced enum prefixes into their APIs after this wrapper
// was created. Rewrite them to match their initial expectations.
// https://github.com/mumble-voip/mumble/commit/e9f0f711956b7739c320cc2012ab4b6037ffbda5
let prefixed_mumble_enum_regex = regex::RegexBuilder::new(r"^MUMBLE_([A-Z]*?_.+)$")
.build()
.unwrap();

match original_variant_name {
// MUMBLE_TS_ is a special case---it was originally unprefixed.
x if x.starts_with("MUMBLE_TS_") => {
return Some(x["MUMBLE_TS_".len()..].into())
}
// MUMBLE_SK_ is a special case---it was originally partially prefixed.
x if x.starts_with("MUMBLE_SK_") => {
let suffix = &x["MUMBLE_".len()..];
return Some(format!("M{}", suffix).into())
}
x if x.starts_with("MUMBLE_") && prefixed_mumble_enum_regex.is_match(x) => {
return Some(prefixed_mumble_enum_regex.replace_all(x, "$1").into());
}
_ => {}
}

return Some(original_variant_name.into())
}

fn item_name_handler(&self, original_item_name: &str) -> Option<String> {
if original_item_name == "root" {
return Some("m".into());
Expand All @@ -38,6 +63,7 @@ impl CustomCallbacks {
.unwrap();
match original_item_name {
"Version" => return None,
"MumbleVersion" => return Some("Version".into()),
"MumbleStringWrapper" => return None,
"mumble_plugin_id_t" => return Some("PluginId".into()),
x if x.starts_with("MumbleAPI_") => return Some("MumbleAPI".into()),
Expand Down Expand Up @@ -100,6 +126,25 @@ impl bindgen::callbacks::ParseCallbacks for CustomCallbacks {
new_name
}

fn enum_variant_name(
&self,
_enum_name: Option<&str>,
original_variant_name: &str,
_variant_value: bindgen::callbacks::EnumVariantValue,
) -> Option<String> {
let new_name = self.enum_name_handler(original_variant_name);

println!(
"GEN NAME: {} = {}",
original_variant_name,
match &new_name {
Some(x) => x.as_str(),
None => original_variant_name,
}
);
new_name
}

fn include_file(&self, filename: &str) {
self.inner.include_file(filename)
}
Expand Down
Loading