forked from cart/glsl-to-spirv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly skips optional dependencies pending rust-lang/cargo#7914 More extensible for addition of new platforms
- Loading branch information
Showing
45 changed files
with
425 additions
and
435 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/target | ||
**/*.rs.bk | ||
Cargo.lock | ||
.cargo/config | ||
.cargo/config | ||
glslang_actual_builder/glslang/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "glslang"] | ||
path = glslang | ||
path = glslang_actual_builder/glslang | ||
url = https://github.com/KhronosGroup/glslang.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Submodule glslang
deleted from
bcf6a2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "glslang_actual_builder" | ||
version = "0.1.0" | ||
authors = ["Pierre Krieger <pierre.krieger1708@gmail.com>", "The vulkano contributors", "Carter Anderson <mcanders1@gmail.com>", "Nicholas Rishel <rishel.nick@gmail.com>", "Martin Krisnanto Putra <grygrflzr@hotmail.com>"] | ||
description = "Internal builder" | ||
repository = "https://github.com/cart/glsl-to-spirv" | ||
license = "MIT/Apache-2.0" | ||
build = "build.rs" | ||
categories = ["rendering::graphics-api"] | ||
edition = "2018" | ||
|
||
[features] | ||
default = [] | ||
build-from-source = ["cmake", "cc"] | ||
|
||
[build-dependencies] | ||
cmake = { version = "0.1.45", optional = true } | ||
cc = { version = "1.0.66", features = ["parallel"], optional = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
use std::path::Path; | ||
|
||
fn main() { | ||
let target: &str = &std::env::var("TARGET").unwrap(); | ||
let cargo_dir = Path::new(env!("CARGO_MANIFEST_DIR")); | ||
let bin_dir = match target { | ||
"x86_64-pc-windows-msvc" => cargo_dir.join("build/windows"), | ||
"x86_64-unknown-linux-gnu" => cargo_dir.join("build/linux"), | ||
"x86_64-apple-darwin" => cargo_dir.join("build/osx"), | ||
"aarch64-linux-android" => cargo_dir.join("build/android-arm64-v8a"), | ||
"armv7-linux-androideabi" => cargo_dir.join("build/android-armeabi-v7a"), | ||
"i686-pc-windows-msvc" => build::build_libraries(), | ||
_ => panic!("Unsupported target {}", target), | ||
}; | ||
|
||
// Link order matters, make sure dependants are linked before their dependencies. | ||
println!("cargo:rustc-link-search={}", bin_dir.to_str().unwrap()); | ||
println!("cargo:rustc-link-lib=glslang.glsltospirv"); | ||
println!("cargo:rustc-link-lib=HLSL.glsltospirv"); | ||
println!("cargo:rustc-link-lib=OGLCompiler.glsltospirv"); | ||
println!("cargo:rustc-link-lib=OSDependent.glsltospirv"); | ||
println!("cargo:rustc-link-lib=SPIRV.glsltospirv"); | ||
println!("cargo:rustc-link-lib=SPVRemapper.glsltospirv"); | ||
if target.contains("x86_64-unknown-linux-gnu") || target.contains("x86_64-apple-darwin") { | ||
println!("cargo:rustc-link-lib=SPIRV-Tools-opt.glsltospirv"); | ||
println!("cargo:rustc-link-lib=SPIRV-Tools.glsltospirv"); | ||
} | ||
if target.contains("android") { | ||
println!("cargo:rustc-link-lib=c++_shared"); | ||
} | ||
} | ||
|
||
#[cfg(feature = "build-from-source")] | ||
mod build { | ||
extern crate cmake; | ||
|
||
use std::path::Path; | ||
use std::path::PathBuf; | ||
|
||
const COMMON_FILES: &[&str] = &[ | ||
"glslang", | ||
"HLSL", | ||
"OGLCompiler", | ||
"OSDependent", | ||
"SPIRV", | ||
"SPVRemapper", | ||
]; | ||
|
||
/// Build target libraries if required, | ||
/// and returns the location of library files | ||
pub fn build_libraries() -> PathBuf { | ||
// Prepare directories | ||
let cargo_dir = Path::new(env!("CARGO_MANIFEST_DIR")); | ||
let source_dir = cargo_dir.join("glslang"); | ||
|
||
let out_dir_env = std::env::var("OUT_DIR").unwrap().clone(); | ||
let out_dir = Path::new(&out_dir_env); | ||
let install_dir = out_dir.join("install"); | ||
let library_dir = install_dir.join("lib"); | ||
|
||
// Re-use libraries if they exist | ||
if library_dir.exists() { | ||
return library_dir; | ||
} | ||
|
||
// Check glslang folder is initialized | ||
let cmakelists = source_dir.join("CMakeLists.txt"); | ||
if !cmakelists.exists() { | ||
panic!("Please make sure the glslang submodule is initialized"); | ||
} | ||
|
||
// Set up "install" subdirectory | ||
match std::fs::create_dir_all(&install_dir) { | ||
Ok(_) => {} | ||
Err(err) => panic!("Unable to create directory: {:?}", err), | ||
} | ||
|
||
// Configure and run build | ||
cmake::Config::new(&source_dir) | ||
.define("CMAKE_INSTALL_PREFIX", &install_dir) | ||
.define("ENABLE_GLSLANG_BINARIES", "OFF") | ||
.profile("Release") | ||
.build_target("install") | ||
.build(); | ||
|
||
// Rename library files | ||
COMMON_FILES.iter().for_each(|file| { | ||
match std::fs::copy( | ||
library_dir.join(file).with_extension("lib"), | ||
library_dir.join(file).with_extension("glsltospirv.lib"), | ||
) { | ||
Ok(_) => {} | ||
Err(err) => panic!("Error renaming glslang libaries: {}", err), | ||
} | ||
}); | ||
|
||
return library_dir; | ||
} | ||
} | ||
|
||
#[cfg(not(feature = "build-from-source"))] | ||
mod build { | ||
use std::path::PathBuf; | ||
|
||
/// Build target libraries if required, | ||
/// and returns the location of library files | ||
pub fn build_libraries() -> PathBuf { | ||
panic!("This platform must build glslang from source."); | ||
} | ||
} |
Oops, something went wrong.