diff --git a/README.md b/README.md index 5a991e6..65715e9 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ spirv-to-dxil-rs builds a copy of spirv-to-dxil statically from Mesa. Many of th * [Meson](https://mesonbuild.com/) * A compatible C and C++ compiler * [MSVC 2019 16.11 or later](https://docs.mesa3d.org/install.html) is required to build on Windows. + * [clang](https://clang.llvm.org/) is required for Linux. * [Python 3.6](https://www.python.org/) or later. Lex and Yacc are not required. Additionally, [CMake 3.6](https://cmake.org/) or later is required to run the build script. diff --git a/spirv-to-dxil-sys/Cargo.toml b/spirv-to-dxil-sys/Cargo.toml index 5367c89..f19647e 100644 --- a/spirv-to-dxil-sys/Cargo.toml +++ b/spirv-to-dxil-sys/Cargo.toml @@ -13,6 +13,9 @@ keywords = ["SPIR-V", "DXIL"] bindgen = "0.63.0" cmake = "0.1" +[features] +included-bindings = [] + [package.metadata.docs.rs] targets = [] -features = ["docsrs"] \ No newline at end of file +features = ["included-bindings"] \ No newline at end of file diff --git a/spirv-to-dxil-sys/build.rs b/spirv-to-dxil-sys/build.rs index 8a40fcd..2051f51 100644 --- a/spirv-to-dxil-sys/build.rs +++ b/spirv-to-dxil-sys/build.rs @@ -9,7 +9,9 @@ fn main() { return; } - let cmake_dst = Config::new("native").build_target("mesa").build(); + let cmake_dst = Config::new("native") + .build_target("mesa") + .build(); let object_dst = cmake_dst.join("build/mesa/lib"); @@ -19,19 +21,26 @@ fn main() { if cfg!(target_os = "windows") { println!("cargo:rustc-link-lib=Version"); } + if cfg!(target_os = "linux") { + println!("cargo:rustc-link-lib=stdc++"); + } println!("cargo:rustc-link-search=native={}", object_dst.display()); println!("cargo:rustc-link-lib=static=spirv_to_dxil"); println!("cargo:rustc-link-lib=static=vulkan_util"); - let bindings = bindgen::Builder::default() - .header("native/wrapper.h") - .clang_arg(format!("-F{}", header_dst.display())) - .clang_arg(format!("-F{}", header_compiler_dst.display())) - .parse_callbacks(Box::new(bindgen::CargoCallbacks)) - .generate() - .expect("Unable to generate bindings"); - bindings - .write_to_file(out_dir.join("bindings.rs")) - .expect("Couldn't write bindings!"); + if !cfg!(feature = "included-bindings") { + let bindings = bindgen::Builder::default() + .header("native/wrapper.h") + .clang_arg(format!("-F{}", header_dst.display())) + .clang_arg(format!("-F{}", header_compiler_dst.display())) + .clang_arg(format!("-I{}", header_dst.display())) + .clang_arg(format!("-I{}", header_compiler_dst.display())) + .parse_callbacks(Box::new(bindgen::CargoCallbacks)) + .generate() + .expect("Unable to generate bindings"); + bindings + .write_to_file(out_dir.join("bindings.rs")) + .expect("Couldn't write bindings!"); + } } diff --git a/spirv-to-dxil-sys/src/lib.rs b/spirv-to-dxil-sys/src/lib.rs index 5518aac..0d8f461 100644 --- a/spirv-to-dxil-sys/src/lib.rs +++ b/spirv-to-dxil-sys/src/lib.rs @@ -2,12 +2,13 @@ #![allow(non_camel_case_types)] #![allow(non_snake_case)] +#[cfg(not(feature = "included-bindings"))] include!(concat!(env!("OUT_DIR"), "/bindings.rs")); -#[cfg(feature = "docsrs")] +#[cfg(feature = "included-bindings")] mod bindings; -#[cfg(feature = "docsrs")] +#[cfg(feature = "included-bindings")] pub use bindings::*; #[cfg(test)]