Skip to content

Commit

Permalink
Split out the checked enc2 variants under a enc2-chk feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Phantomical committed Feb 3, 2024
1 parent 8504646 commit 80a302a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ rust-version = "1.64"
enc2-m32-a32 = ["bindgen", "_internal-enc2"]
enc2-m64-a64 = ["bindgen", "_internal-enc2"]

# Enable the checked variants for the enc2 module of XED.
enc2-chk = ["bindgen", "_internal-enc2"]

# Generate bindings with bindgen at build-time instead of using the
# pregenerated bindings.
#
Expand Down
27 changes: 25 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ fn build_xed(_cc: &cc::Build) {
($variant:literal) => {
if cfg!(feature = $variant) {
println!("cargo:rustc-link-lib={linkty}=xed-{}", $variant);
println!("cargo:rustc-link-lib={linkty}=xed-chk-{}", $variant);

if cfg!(feature = "enc2-chk") {
println!("cargo:rustc-link-lib={linkty}=xed-chk-{}", $variant);
}
}
};
}
Expand Down Expand Up @@ -176,6 +179,10 @@ fn build_inline_shim(mut cc: cc::Build) {
cfg_define_enc2!("enc2-m32-a32");
cfg_define_enc2!("enc2-m64-a64");

if cfg!(feature = "enc2-chk") {
cc.define("XED_SYS_ENC2_CHK", None);
}

if cfg!(feature = "dylib") {
cc.define("XED_DLL", None);
}
Expand All @@ -195,7 +202,7 @@ fn build_bindgen() {

let dot_rs = out_dir.join("xed.rs");

let builder = bindgen::builder()
let mut builder = bindgen::builder()
.clang_arg("-I")
.clang_arg(out_dir.join("install/include").display().to_string())
.allowlist_type("xed3?_.*")
Expand All @@ -209,6 +216,22 @@ fn build_bindgen() {
.wrap_static_fns_path(out_dir.join("xed-static.c"))
.wrap_static_fns_suffix("_xed_sys_inline");

if cfg!(feater = "dylib") {
builder = builder.clang_arg("-DXED_DLL");
}

if cfg!(feature = "enc2-m32-a32") {
builder = builder.clang_arg("-DXED_SYS_ENC2_M32_A32");
}

if cfg!(feature = "enc2-m64-a64") {
builder = builder.clang_arg("-DXED_SYS_ENC2_M64_A64");
}

if cfg!(feature = "enc2-chk") {
builder = builder.clang_arg("-DXED_SYS_ENC2_CHK");
}

let bindings = builder
.header("xed.h")
.generate()
Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
//!
//! The generated static libraries also unfortunately have some duplicate
//! symbols so attempting to link both will result in linker errors. To make
//! the error less confusing this library will fail to compile if multiple
//! `enc2` features are enabled.
//! the error less confusing this library will fail to compile if both
//! `enc2-m64-a64` and `enc2-m32-a32` are enabled and the `dylib` feature is
//! not enabled.
//!
//! - `enc2-m64-a64` - Enable enc2 for 64-bit mode with 64-bit addresses.
//! - `enc2-m32-a32` - Enable enc2 for 32-bit mode with 32-bit addresses.
//! - `enc2-chk` - Enable checked variants of the of the enc2 functions. Note
//! that this feature does nothing unless you have enabled one of the other
//! enc2 features.
//!
//! [0]: crate::xed_tables_init
//! [1]: https://github.com/intelxed/xed/wiki/The-fast-encoder---enc2
Expand Down
12 changes: 8 additions & 4 deletions xed.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
#include "xed/xed-isa-set.h"

#ifdef XED_SYS_ENC2_M32_A32
#include "xed/xed-enc2-m32-a32.h"
#include "xed/xed-chk-enc2-m32-a32.h"
# include "xed/xed-enc2-m32-a32.h"
# ifdef XED_SYS_ENC2_CHK
# include "xed/xed-chk-enc2-m32-a32.h"
# endif
#endif

#ifdef XED_SYS_ENC2_M64_A64
#include "xed/xed-enc2-m64-a64.h"
#include "xed/xed-chk-enc2-m64-a64.h"
# include "xed/xed-enc2-m64-a64.h"
# ifdef XED_SYS_ENC2_CHK
# include "xed/xed-chk-enc2-m64-a64.h"
# endif
#endif

0 comments on commit 80a302a

Please sign in to comment.