diff --git a/Cargo.toml b/Cargo.toml index 7acbf4a330..55248d678b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ repository = "https://github.com/gfx-rs/naga" keywords = ["shader", "SPIR-V", "GLSL", "MSL"] license = "MIT OR Apache-2.0" exclude = ["bin/**/*", "tests/**/*", "Cargo.lock", "target/**/*"] +resolver = "2" [package.metadata.docs.rs] all-features = true @@ -26,7 +27,6 @@ serde = { version = "1.0", features = ["derive"], optional = true } petgraph = { version ="0.5", optional = true } rose_tree = { version ="0.2", optional = true } pp-rs = { git = "https://github.com/Kangz/glslpp-rs.git", optional = true, rev = "c02476b" } -#env_logger = "0.8" # uncomment temporarily for developing with the binary target [features] default = [] @@ -43,13 +43,13 @@ wgsl-in = ["codespan-reporting"] wgsl-out = [] hlsl-out = [] -[[bin]] -name = "naga" -path = "bin/naga.rs" - [dev-dependencies] diff = "0.1" ron = "0.6" serde = { version = "1.0", features = ["derive"] } spirv = { package = "spirv_headers", version = "1.5", features = ["deserialize"] } rspirv = "0.7" + +[workspace] +members = [".", "cli"] +default-members = ["cli"] diff --git a/cli/Cargo.toml b/cli/Cargo.toml new file mode 100644 index 0000000000..70a274cd87 --- /dev/null +++ b/cli/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "naga-cli" +version = "0.4.0" +authors = ["Naga Developers"] +edition = "2018" +description = "Shader translation command line tool" +homepage = "https://github.com/gfx-rs/naga" +repository = "https://github.com/gfx-rs/naga" +keywords = ["shader", "SPIR-V", "GLSL", "MSL"] +license = "MIT OR Apache-2.0" + +[[bin]] +name = "naga" +path = "src/main.rs" + +[dependencies] +naga = { path = "../", features = ["wgsl-in", "wgsl-out", "glsl-in", "glsl-out", "spv-in", "spv-out", "msl-out", "hlsl-out", "dot-out", "glsl-validate"] } +log = "0.4" +codespan-reporting = "0.11" +env_logger = "0.8" diff --git a/bin/naga.rs b/cli/src/main.rs similarity index 88% rename from bin/naga.rs rename to cli/src/main.rs index 09c1f64dc3..8b29308195 100644 --- a/bin/naga.rs +++ b/cli/src/main.rs @@ -6,15 +6,10 @@ use std::{env, error::Error, path::Path}; #[derive(Default)] struct Parameters { validation_flags: naga::valid::ValidationFlags, - #[cfg(feature = "spv-in")] spv_adjust_coordinate_space: bool, - #[cfg(feature = "spv-in")] spv_flow_dump_prefix: Option, - #[cfg(feature = "spv-out")] spv: naga::back::spv::Options, - #[cfg(feature = "msl-out")] msl: naga::back::msl::Options, - #[cfg(feature = "glsl-out")] glsl: naga::back::glsl::Options, } @@ -46,7 +41,7 @@ impl PrettyResult for Result { } fn main() { - //env_logger::init(); // uncomment during development + env_logger::init(); let mut input_path = None; let mut output_paths = Vec::new(); @@ -66,11 +61,8 @@ fn main() { params.validation_flags = naga::valid::ValidationFlags::from_bits(value).unwrap(); } - #[cfg(feature = "spv-in")] "flow-dir" => params.spv_flow_dump_prefix = args.next(), - #[cfg(feature = "glsl-out")] "entry-point" => params.glsl.entry_point = args.next().unwrap(), - #[cfg(feature = "glsl-out")] "profile" => { use naga::back::glsl::Version; let string = args.next().unwrap(); @@ -105,7 +97,6 @@ fn main() { .to_str() .unwrap() { - #[cfg(feature = "spv-in")] "spv" => { let options = naga::front::spv::Options { adjust_coordinate_space: params.spv_adjust_coordinate_space, @@ -115,7 +106,6 @@ fn main() { let input = fs::read(input_path).unwrap(); naga::front::spv::parse_u8_slice(&input, &options).unwrap() } - #[cfg(feature = "wgsl-in")] "wgsl" => { let input = fs::read_to_string(input_path).unwrap(); let result = naga::front::wgsl::parse_str(&input); @@ -127,7 +117,6 @@ fn main() { } } } - #[cfg(feature = "glsl-in")] "vert" => { let input = fs::read_to_string(input_path).unwrap(); let mut entry_points = naga::FastHashMap::default(); @@ -141,7 +130,6 @@ fn main() { ) .unwrap_pretty() } - #[cfg(feature = "glsl-in")] "frag" => { let input = fs::read_to_string(input_path).unwrap(); let mut entry_points = naga::FastHashMap::default(); @@ -155,7 +143,6 @@ fn main() { ) .unwrap_pretty() } - #[cfg(feature = "glsl-in")] "comp" => { let input = fs::read_to_string(input_path).unwrap(); let mut entry_points = naga::FastHashMap::default(); @@ -169,13 +156,7 @@ fn main() { ) .unwrap_pretty() } - other => { - if true { - // prevent "unreachable_code" warnings - panic!("Unknown input extension: {}", other); - } - naga::Module::default() - } + other => panic!("Unknown input extension: {}", other), }; // validate the IR @@ -218,7 +199,6 @@ fn main() { writeln!(file, "{:#?}", info).unwrap(); } } - #[cfg(feature = "msl-out")] "metal" => { use naga::back::msl; @@ -232,7 +212,6 @@ fn main() { .unwrap_pretty(); fs::write(output_path, msl).unwrap(); } - #[cfg(feature = "spv-out")] "spv" => { use naga::back::spv; @@ -247,7 +226,6 @@ fn main() { fs::write(output_path, bytes.as_slice()).unwrap(); } - #[cfg(feature = "glsl-out")] stage @ "vert" | stage @ "frag" | stage @ "comp" => { use naga::back::glsl; @@ -265,21 +243,18 @@ fn main() { writer.write().unwrap(); fs::write(output_path, buffer).unwrap(); } - #[cfg(feature = "dot-out")] "dot" => { use naga::back::dot; let output = dot::write(&module, info.as_ref()).unwrap(); fs::write(output_path, output).unwrap(); } - #[cfg(feature = "hlsl-out")] "hlsl" => { use naga::back::hlsl; let hlsl = hlsl::write_string(&module).unwrap_pretty(); fs::write(output_path, hlsl).unwrap(); } - #[cfg(feature = "wgsl-out")] "wgsl" => { use naga::back::wgsl; @@ -287,11 +262,7 @@ fn main() { fs::write(output_path, wgsl).unwrap(); } other => { - let _ = params; - println!( - "Unknown output extension: {}, forgot to enable a feature?", - other - ); + println!("Unknown output extension: {}", other); } } }