rust-gpu/spirv-tools-sys/generate.rs
Jake Shadle 307d0da66b
Add spirv-tools and spirv-tools-sys crates to wrap usage of spirv-tools (#179)
* Add spirv-headers and spirv-tools as submodules

* Add simple generator and the generated code needed for compilation

* Add first pass on spirv-tools-sys

* Add first pass on spirv-tools

* Replace invocation of spirv-opt with spirv-tools crate

* Use C++11

* Placate clippy

* Add validation, replacing spirv-val with the spirv-tools crate

* Fix MSVC warning

* Use patched spirv-tools

* Fixup metadata

* Add same compiler flags as "official" build scripts

* Update spirv-tools and generated files

* Fixup

* Add assembler and example

* Use assembler in tests

* Oops, fix macos TARGET_OS

* write -> write_all

* Start splitting spirv-tools into a compiled vs tool feature set

* Checkpointing

* Checkpoint

* Boop

* Get tests to work both with installed and compiled tools

* Cleanup CI config

* Splits steps to clearly show how long each part of a longer (eg test)
step actually takes
* Label all steps

* Explicitly disable submodule checkout

* Rustfmt

* Rename features for consistency and fix clippy warnings

* Split "core" crates from examples

* Add run_clippy bash script

* Add test script

* Remove x flag

* Newline

* Actually print out errors from running val/opt

* Revert drive-by import merging

* Change intro to take the changes this PR has into account

* Actually run tests on Windows

* Fetch only the host target to reduce fetch times

* Add more info when a spirv tool returns a non-zero exit code

* Rustfmt

* Switch tool assembler to use files to see if it fixes windows

* Use files for input and output for now until I can figure out Windows being dumb

* Fix API docs generation

* Compile and use C++ code to check Windows issue

* Return to use installed tools
2020-10-29 23:03:07 +01:00

116 lines
5.1 KiB
Rust

// The spirv tools use generated code, for now we just replicate the minimum
// generation we need here by calling the *shudders* python script(s) we need
// to in a simple script and commit them to source control, as they only need
// to be regenerated when spirv-headers is updated
use std::{fs, process::Command};
fn python<S: AsRef<std::ffi::OsStr>>(args: impl IntoIterator<Item = S>) -> Result<(), i32> {
Command::new("python")
.args(args.into_iter())
.status()
.map_err(|_| -1)
.and_then(|es| {
if es.success() {
Ok(())
} else {
Err(es.code().unwrap_or(-1))
}
})
}
fn main() {
fs::create_dir_all("generated").expect("unable to create 'generated'");
python(&[
"spirv-tools/utils/update_build_version.py",
"spirv-tools",
"generated/build-version.inc",
])
.expect("failed to generate build version from spirv-headers");
enum_string_mapping("unified1");
core_table("unified1");
glsl_table("unified1");
opencl_table("unified1");
vendor_table("spv-amd-shader-explicit-vertex-parameter", None);
vendor_table("spv-amd-shader-trinary-minmax", None);
vendor_table("spv-amd-gcn-shader", None);
vendor_table("spv-amd-shader-ballot", None);
vendor_table("debuginfo", None);
vendor_table("nonsemantic.clspvreflection", None);
vendor_table("opencl.debuginfo.100", Some("CLDEBUG100_"));
registry_table();
}
fn enum_string_mapping(version: &str) {
python(&[
"spirv-tools/utils/generate_grammar_tables.py".to_owned(),
format!("--spirv-core-grammar=spirv-headers/include/spirv/{}/spirv.core.grammar.json", version),
"--extinst-debuginfo-grammar=spirv-headers/include/spirv/unified1/extinst.debuginfo.grammar.json".to_owned(),
"--extinst-cldebuginfo100-grammar=spirv-headers/include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json".to_owned(),
"--extension-enum-output=generated/extension_enum.inc".to_owned(),
"--enum-string-mapping-output=generated/enum_string_mapping.inc".to_owned(),
]).expect("failed to generate enum includes from spirv-headers");
}
fn vendor_table(which: &str, prefix: Option<&str>) {
python(&[
"spirv-tools/utils/generate_grammar_tables.py".to_owned(),
format!(
"--extinst-vendor-grammar=spirv-headers/include/spirv/unified1/extinst.{}.grammar.json",
which
),
format!("--vendor-insts-output=generated/{}.insts.inc", which),
format!(
"--vendor-operand-kind-prefix={}",
prefix.unwrap_or_default()
),
])
.expect("failed to generate vendor table");
}
fn core_table(which: &str) {
python(&[
"spirv-tools/utils/generate_grammar_tables.py".to_owned(),
"--spirv-core-grammar=spirv-headers/include/spirv/unified1/spirv.core.grammar.json".to_owned(),
format!("--core-insts-output=generated/core.insts-{}.inc", which),
"--extinst-debuginfo-grammar=spirv-headers/include/spirv/unified1/extinst.debuginfo.grammar.json".to_owned(),
"--extinst-cldebuginfo100-grammar=spirv-headers/include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json".to_owned(),
format!("--operand-kinds-output=generated/operand.kinds-{}.inc", which),
]).expect("failed to generate core table from spirv-headers");
}
fn registry_table() {
python(&[
"spirv-tools/utils/generate_registry_tables.py",
"--xml=spirv-headers/include/spirv/spir-v.xml",
"--generator=generated/generators.inc",
])
.expect("failed to generate core table from spirv-headers");
}
fn glsl_table(version: &str) {
python(&[
"spirv-tools/utils/generate_grammar_tables.py".to_owned(),
format!("--spirv-core-grammar=spirv-headers/include/spirv/{}/spirv.core.grammar.json", version),
"--extinst-debuginfo-grammar=spirv-headers/include/spirv/unified1/extinst.debuginfo.grammar.json".to_owned(),
"--extinst-cldebuginfo100-grammar=spirv-headers/include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json".to_owned(),
format!("--extinst-glsl-grammar=spirv-headers/include/spirv/{}/extinst.glsl.std.450.grammar.json", version),
"--glsl-insts-output=generated/glsl.std.450.insts.inc".to_owned(),
]).expect("failed to generate glsl table from spirv-headers");
}
fn opencl_table(version: &str) {
python(&[
"spirv-tools/utils/generate_grammar_tables.py".to_owned(),
format!("--spirv-core-grammar=spirv-headers/include/spirv/{}/spirv.core.grammar.json", version),
"--extinst-debuginfo-grammar=spirv-headers/include/spirv/unified1/extinst.debuginfo.grammar.json".to_owned(),
"--extinst-cldebuginfo100-grammar=spirv-headers/include/spirv/unified1/extinst.opencl.debuginfo.100.grammar.json".to_owned(),
format!("--extinst-opencl-grammar=spirv-headers/include/spirv/{}/extinst.opencl.std.100.grammar.json", version),
"--opencl-insts-output=generated/opencl.std.insts.inc".to_owned(),
]).expect("failed to generate glsl table from spirv-headers");
}