Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build various target libraries from source #7

Merged
merged 11 commits into from
Jan 8, 2021
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
[package]
name = "bevy-glsl-to-spirv"
version = "0.2.0"
version = "0.2.2"
authors = ["Pierre Krieger <[email protected]>", "The vulkano contributors", "Carter Anderson <[email protected]>", "Nicholas Rishel <[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"

[build-dependencies]
cmake = "0.1.45"
GrygrFlzr marked this conversation as resolved.
Show resolved Hide resolved
cc = { version = "1.0.66", features = ["parallel"] }
58 changes: 58 additions & 0 deletions build/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
extern crate cmake;

use std::env;
use std::fs::copy;
use std::path::Path;
use std::path::PathBuf;

const COMMON_FILES: &[&str] = &[
"glslang",
"HLSL",
"OGLCompiler",
"OSDependent",
"SPIRV",
"SPVRemapper",
];

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") {
Expand Down Expand Up @@ -40,3 +55,46 @@ fn main() {
println!("cargo:rustc-link-lib=c++_shared");
}
}

fn build_windows_i686() -> PathBuf {
// Prepare directories
let cargo_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let source_dir = cargo_dir.join("glslang");

let out_dir_env = 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;
}

// 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 copy(
library_dir.join(file).with_extension("lib"),
library_dir.join(file).with_extension("glsltospirv.lib"),
) {
Ok(_) => {}
Err(err) => panic!("Error copying glslang libaries: {}", err),
}
});

return library_dir;
}
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,19 @@ This crate is deprecated please use [shaderc-rs](https://github.com/google/shade


BEVY NOTE: This crate is a temporary measure until native rust shader compilation like https://github.com/gfx-rs/naga lands.

---

## Additional Dependencies for `i686-pc-windows-msvc`

Assuming an MSVC Windows host (either 32 or 64-bit):
- git
- [cmake](https://cmake.org/download/)
- [VS C++ Build Tools](https://aka.ms/buildtools) (2017 or higher)
- Select **Visual C++ build tools**
- Make sure **Visual C++ tools for CMake** is ticked on the right
- Restart the computer after installing build tools - will fail to build otherwise
- `glslang` submodule is assumed to be initialized
- Run `git submodule update --init` if you're checking out from git

`glslang` will be built from source the first time. Compiled libraries are re-used afterwards.