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"] }
69 changes: 69 additions & 0 deletions build/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
extern crate cmake;

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

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

fn main() {
let target = env::var("TARGET").unwrap();
Expand All @@ -8,6 +22,9 @@ fn main() {

if target.contains("x86_64-pc-windows-msvc") {
bin_dir.push("windows");
} else if target.contains("i686-pc-windows-msvc") {
build_windows_i686();
bin_dir.push("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 +57,55 @@ fn main() {
println!("cargo:rustc-link-lib=c++_shared");
}
}

fn build_windows_i686() {
// Prepare directories
let cargo_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
let source_dir = cargo_dir.join("glslang");
let install_dir = source_dir.join("install");
GrygrFlzr marked this conversation as resolved.
Show resolved Hide resolved
let library_source = install_dir.join("lib");
let library_destination = cargo_dir.join("build").join("windows-i686");

// Re-use libraries if they exist
if library_destination.exists() {
return;
}

// Initialize submodules
Command::new("git")
.args(&["submodule", "update", "--init"])
GrygrFlzr marked this conversation as resolved.
Show resolved Hide resolved
.status()
.expect("Failed to update submodules.");

// 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();

// Copy library files to /build
match std::fs::create_dir_all(&library_destination) {
Ok(_) => {}
Err(err) => panic!("Unable to create directory: {:?}", err),
}

COMMON_FILES.iter().for_each(|file| {
match copy(
library_source.join(file).with_extension("lib"),
library_destination
.join(file)
.with_extension("glsltospirv.lib"),
) {
Ok(_) => {}
Err(err) => panic!("Error copying glslang libaries: {}", err),
}
});
}
14 changes: 14 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,17 @@ 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` will be built from source the first time. Compiled libraries are re-used afterwards.