Fix crash when enabling optimizations

Due to generating rust style enums for slang enums that can contain
more variants than explicitly defined, the generated optimized code
probably trunkated the integer values of these additional variants.
Fix by using constified enums for these cases.
This commit is contained in:
Lauro Oyen
2024-07-13 22:32:03 +02:00
parent 85c4b2eb46
commit 3419fb03d9
2 changed files with 41 additions and 14 deletions

View File

@ -24,10 +24,16 @@ fn main() {
.allowlist_type("slang.*")
.allowlist_var("SLANG_.*")
.with_codegen_config(
bindgen::CodegenConfig::FUNCTIONS | bindgen::CodegenConfig::TYPES | bindgen::CodegenConfig::VARS,
bindgen::CodegenConfig::FUNCTIONS
| bindgen::CodegenConfig::TYPES
| bindgen::CodegenConfig::VARS,
)
.parse_callbacks(Box::new(ParseCallback {}))
.default_enum_style(bindgen::EnumVariation::Rust { non_exhaustive: true })
.default_enum_style(bindgen::EnumVariation::Rust {
non_exhaustive: false,
})
.constified_enum("SlangProfileID")
.constified_enum("SlangCapabilityID")
.vtable_generation(true)
.layout_tests(false)
.derive_copy(true)
@ -40,7 +46,8 @@ fn main() {
fn link_libraries(slang_dir: &Path) {
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("Couldn't determine target OS.");
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("Couldn't determine target architecture.");
let target_arch =
env::var("CARGO_CFG_TARGET_ARCH").expect("Couldn't determine target architecture.");
let target = match (&*target_os, &*target_arch) {
("windows", "x86") => "windows-x86",