-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from GrygrFlzr/i686-win-compile
Build various target libraries from source
- Loading branch information
Showing
47 changed files
with
472 additions
and
325 deletions.
There are no files selected for viewing
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,4 @@ | ||
/target | ||
**/*.rs.bk | ||
Cargo.lock | ||
.cargo/config | ||
.cargo/config |
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 | ||
[submodule "glslang_actual_builder/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
[package] | ||
name = "bevy-glsl-to-spirv" | ||
version = "0.2.0" | ||
authors = ["Pierre Krieger <pierre.krieger1708@gmail.com>", "The vulkano contributors", "Carter Anderson <mcanders1@gmail.com>", "Nicholas Rishel <rishel.nick@gmail.com>"] | ||
version = "0.2.2" | ||
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 = "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" | ||
|
||
[dependencies] | ||
# Default panic message handling | ||
glslang_actual_builder = { path = "glslang_actual_builder", default-features = false } | ||
|
||
# Supported Platforms | ||
[target.x86_64-pc-windows-msvc.dependencies] | ||
glslang_actual_builder = { path = "glslang_actual_builder", default-features = false } | ||
|
||
[target.x86_64-unknown-linux-gnu.dependencies] | ||
glslang_actual_builder = { path = "glslang_actual_builder", default-features = false } | ||
|
||
[target.x86_64-apple-darwin.dependencies] | ||
glslang_actual_builder = { path = "glslang_actual_builder", default-features = false } | ||
|
||
[target.aarch64-linux-android.dependencies] | ||
glslang_actual_builder = { path = "glslang_actual_builder", default-features = false } | ||
|
||
[target.armv7-linux-androideabi.dependencies] | ||
glslang_actual_builder = { path = "glslang_actual_builder", default-features = false } | ||
|
||
[target.i686-pc-windows-msvc.dependencies] | ||
glslang_actual_builder = { path = "glslang_actual_builder", features = ["build-from-source"] } | ||
|
||
[target.x86_64-pc-windows-gnu.dependencies] | ||
glslang_actual_builder = { path = "glslang_actual_builder", features = ["build-from-source"] } | ||
|
||
[target.i686-pc-windows-gnu.dependencies] | ||
glslang_actual_builder = { path = "glslang_actual_builder", features = ["build-from-source"] } |
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,116 @@ | ||
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").join("windows"), | ||
"x86_64-unknown-linux-gnu" => cargo_dir.join("build").join("linux"), | ||
"x86_64-apple-darwin" => cargo_dir.join("build").join("osx"), | ||
"aarch64-linux-android" => cargo_dir.join("build").join("android-arm64-v8a"), | ||
"armv7-linux-androideabi" => cargo_dir.join("build").join("android-armeabi-v7a"), | ||
"i686-pc-windows-msvc" => build::build_libraries(&target), | ||
"x86_64-pc-windows-gnu" => build::build_libraries(&target), | ||
"i686-pc-windows-gnu" => build::build_libraries(&target), | ||
_ => 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"); | ||
} | ||
if target.ends_with("-pc-windows-gnu") { | ||
println!("cargo:rustc-link-lib=dylib=stdc++"); | ||
} | ||
} | ||
|
||
#[cfg(feature = "build-from-source")] | ||
mod build { | ||
use std::path::Path; | ||
use std::path::PathBuf; | ||
|
||
/// Build target libraries if required, | ||
/// and returns the location of library files | ||
pub fn build_libraries(_target: &str) -> 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(); | ||
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 let Ok(mut entry) = library_dir.read_dir() { | ||
if entry.next().is_some() { | ||
// a file exists in the path | ||
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), | ||
} | ||
|
||
// Common configuration | ||
let mut config = cmake::Config::new(&source_dir); | ||
config | ||
.define("CMAKE_INSTALL_PREFIX", &install_dir) | ||
.define("CMAKE_TRY_COMPILE_TARGET_TYPE", "STATIC_LIBRARY") | ||
.define("ENABLE_GLSLANG_BINARIES", "OFF") | ||
.profile("Release") | ||
.build_target("install"); | ||
|
||
// Build config | ||
config.build(); | ||
|
||
// Add vendor suffix to all library names | ||
for path in library_dir | ||
.read_dir() | ||
.expect("Unable to locate compiled glslang libraries") | ||
{ | ||
let filename = path.unwrap().path(); | ||
let metadata = std::fs::metadata(&filename).unwrap(); | ||
if metadata.is_file() { | ||
let extension = filename.extension().unwrap().to_str().unwrap(); | ||
let new_extension = format!("glsltospirv.{}", extension); | ||
let new_name = filename.with_extension(new_extension); | ||
std::fs::copy(&filename, &new_name) | ||
.expect("Failed to rename a glslang library for linking"); | ||
} | ||
} | ||
|
||
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(target: &str) -> PathBuf { | ||
panic!("Platform {} must build glslang from source.", &target); | ||
} | ||
} |
Oops, something went wrong.