Skip to content

fix bindgen #116

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

Merged
merged 10 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from 9 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
1,683 changes: 242 additions & 1,441 deletions src/ffi/com_model.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/ffi/command.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(unused)]
#![allow(unused, nonstandard_style, deref_nullptr)]

use std::os::raw::*;

Expand Down
90 changes: 23 additions & 67 deletions src/ffi/cvar.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#![allow(unused, deref_nullptr)]
// bindgen halflife/common/cvardef.h --allowlist-type "cvar_s" -- --target=i686-unknown-linux-gnu
// -Ihalflife/{public,common,engine} -include mathlib.h -include const.h
// Keep everything before the generated part
// Change `cvar_s.name` and `cvars_s.string` to use type `*const ...` for code compatibility
// Remove `vec_t` and `vec3_t` and replace `vec3_t` with `[f32; 3]`

use std::mem::{align_of, size_of};
#![allow(unused, deref_nullptr, nonstandard_style)]

use std::mem::{align_of, offset_of, size_of};
use std::os::raw::*;
use std::ptr::null;

Expand All @@ -21,6 +27,11 @@ bitflags! {
}
}

/* automatically generated by rust-bindgen 0.71.1 */

// intentionally modify `name` and `strings` field to
// [`*const c_char`]
// instead of the generated [`*mut ...`]
#[repr(C)]
#[derive(Debug)]
pub struct cvar_s {
Expand All @@ -30,68 +41,13 @@ pub struct cvar_s {
pub value: f32,
pub next: *mut cvar_s,
}

#[cfg(target_arch = "x86")]
#[test]
fn bindgen_test_layout_cvar_s() {
assert_eq!(
size_of::<cvar_s>(),
20usize,
concat!("Size of: ", stringify!(cvar_s))
);
assert_eq!(
align_of::<cvar_s>(),
4usize,
concat!("Alignment of ", stringify!(cvar_s))
);
assert_eq!(
unsafe { &(*(null::<cvar_s>())).name as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(cvar_s),
"::",
stringify!(name)
)
);
assert_eq!(
unsafe { &(*(null::<cvar_s>())).string as *const _ as usize },
4usize,
concat!(
"Offset of field: ",
stringify!(cvar_s),
"::",
stringify!(string)
)
);
assert_eq!(
unsafe { &(*(null::<cvar_s>())).flags as *const _ as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(cvar_s),
"::",
stringify!(flags)
)
);
assert_eq!(
unsafe { &(*(null::<cvar_s>())).value as *const _ as usize },
12usize,
concat!(
"Offset of field: ",
stringify!(cvar_s),
"::",
stringify!(value)
)
);
assert_eq!(
unsafe { &(*(null::<cvar_s>())).next as *const _ as usize },
16usize,
concat!(
"Offset of field: ",
stringify!(cvar_s),
"::",
stringify!(next)
)
);
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
["Size of cvar_s"][size_of::<cvar_s>() - 20usize];
["Alignment of cvar_s"][align_of::<cvar_s>() - 4usize];
["Offset of field: cvar_s::name"][offset_of!(cvar_s, name) - 0usize];
["Offset of field: cvar_s::string"][offset_of!(cvar_s, string) - 4usize];
["Offset of field: cvar_s::flags"][offset_of!(cvar_s, flags) - 8usize];
["Offset of field: cvar_s::value"][offset_of!(cvar_s, value) - 12usize];
["Offset of field: cvar_s::next"][offset_of!(cvar_s, next) - 16usize];
};
Loading