Skip to content

Commit

Permalink
Skip build process for prebuilt libraries
Browse files Browse the repository at this point in the history
Libraries were built ahead-of-time for the following platforms:
- x86_64-pc-windows-msvc
- x86_64-unknown-linux-gnu
- x86_64-apple-darwin
- aarch64-linux-android
- armv7-linux-androideabi

Libraries are built from source for the following platform(s):
- i686-pc-windows-msvc
  • Loading branch information
GrygrFlzr committed Jan 5, 2021
1 parent e4ac0b5 commit 9ee8a3c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 25 deletions.
64 changes: 64 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[target.x86_64-pc-windows-msvc.glslang]
rustc-link-search = ["build/windows"]
rustc-link-lib = [
"HLSL.glsltospirv",
"OGLCompiler.glsltospirv",
"OSDependent.glsltospirv",
"SPIRV.glsltospirv",
"SPVRemapper.glsltospirv",
"glslang.glsltospirv"
]

[target.x86_64-unknown-linux-gnu.glslang]
rustc-link-search = ["build/linux"]
rustc-link-lib = [
"HLSL.glsltospirv",
"OGLCompiler.glsltospirv",
"OSDependent.glsltospirv",
"SPIRV.glsltospirv",
"SPVRemapper.glsltospirv",
"glslang.glsltospirv",
# linux and macOS-specific libraries
"SPIRV-Tools-opt.glsltospirv",
"SPIRV-Tools.glsltospirv"
]

[target.x86_64-apple-darwin.glslang]
rustc-link-search = ["build/osx"]
rustc-link-lib = [
"HLSL.glsltospirv",
"OGLCompiler.glsltospirv",
"OSDependent.glsltospirv",
"SPIRV.glsltospirv",
"SPVRemapper.glsltospirv",
"glslang.glsltospirv",
# linux and macOS-specific libraries
"SPIRV-Tools-opt.glsltospirv",
"SPIRV-Tools.glsltospirv"
]

[target.aarch64-linux-android.glslang]
rustc-link-search = ["build/android-arm64-v8a"]
rustc-link-lib = [
"HLSL.glsltospirv",
"OGLCompiler.glsltospirv",
"OSDependent.glsltospirv",
"SPIRV.glsltospirv",
"SPVRemapper.glsltospirv",
"glslang.glsltospirv",
# android-specific libraries
"c++_shared"
]

[target.armv7-linux-androideabi.glslang]
rustc-link-search = ["build/android-armeabi-v7a"]
rustc-link-lib = [
"HLSL.glsltospirv",
"OGLCompiler.glsltospirv",
"OSDependent.glsltospirv",
"SPIRV.glsltospirv",
"SPVRemapper.glsltospirv",
"glslang.glsltospirv",
# android-specific libraries
"c++_shared"
]
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "bevy-glsl-to-spirv"
version = "0.2.2"
authors = ["Pierre Krieger <[email protected]>", "The vulkano contributors", "Carter Anderson <[email protected]>", "Nicholas Rishel <[email protected]>"]
authors = ["Pierre Krieger <[email protected]>", "The vulkano contributors", "Carter Anderson <[email protected]>", "Nicholas Rishel <[email protected]>", "Martin Krisnanto Putra <[email protected]>"]
description = "Deprecated. This crate is a temporary measure until native rust shader compilation like https://github.com/gfx-rs/naga lands."
repository = "https://github.com/cart/glsl-to-spirv"
license = "MIT/Apache-2.0"
build = "build/build.rs"
categories = ["rendering::graphics-api"]
edition = "2018"
links = "glslang"

[build-dependencies]
cmake = "0.1.45"
Expand Down
37 changes: 13 additions & 24 deletions build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,10 @@ const COMMON_FILES: &[&str] = &[
];

fn main() {
let target = env::var("TARGET").unwrap();
let mut bin_dir = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
bin_dir.push("build");

if target.contains("x86_64-pc-windows-msvc") {
bin_dir.push("windows");
} else if target.contains("i686-pc-windows-msvc") {
bin_dir = build_windows_i686();
} else if target.contains("x86_64-unknown-linux-gnu") {
bin_dir.push("linux");
} else if target.contains("x86_64-apple-darwin") {
bin_dir.push("osx");
} else if target.contains("android") {
if target.contains("aarch64") {
bin_dir.push("android-arm64-v8a");
} else if target.contains("armv7") {
bin_dir.push("android-armeabi-v7a");
} else {
panic!("Missing Android target support {}", target);
}
} else {
panic!("Missing target support {}", target);
let target: &str = &env::var("TARGET").unwrap();
let bin_dir = match target {
"i686-pc-windows-msvc" => build_libraries(),
_ => panic!("Missing target support {}", target),
};

// Link order matters, make sure dependents are linked before their dependencies.
Expand All @@ -56,7 +38,8 @@ fn main() {
}
}

fn build_windows_i686() -> PathBuf {
/// Build target libraries and returns the path they're in
pub fn build_libraries() -> PathBuf {
// Prepare directories
let cargo_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let source_dir = cargo_dir.join("glslang");
Expand All @@ -71,6 +54,12 @@ fn build_windows_i686() -> PathBuf {
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(_) => {}
Expand All @@ -92,7 +81,7 @@ fn build_windows_i686() -> PathBuf {
library_dir.join(file).with_extension("glsltospirv.lib"),
) {
Ok(_) => {}
Err(err) => panic!("Error copying glslang libaries: {}", err),
Err(err) => panic!("Error renaming glslang libaries: {}", err),
}
});

Expand Down

0 comments on commit 9ee8a3c

Please sign in to comment.