Skip to content

Commit

Permalink
move bin/naga.rs to a separate crate in workspace (gfx-rs#938)
Browse files Browse the repository at this point in the history
* move bin/naga.rs to a separate crate

* enable all shader languages for naga binary

* [naga-cli] add env logger

* [naga-cli] remove unneccessary code

* [naga-cli]enable glsl-validate feature

* move naga-cli to cli, add trailing newline

* remove commented env_logger dependency
  • Loading branch information
jakobhellermann authored and Gordon-F committed Jun 13, 2021
1 parent 126354f commit c78c03b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 37 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = []
Expand All @@ -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"]
20 changes: 20 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
35 changes: 3 additions & 32 deletions bin/naga.rs → cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[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,
}

Expand Down Expand Up @@ -46,7 +41,7 @@ impl<T, E: Error> PrettyResult for Result<T, E> {
}

fn main() {
//env_logger::init(); // uncomment during development
env_logger::init();

let mut input_path = None;
let mut output_paths = Vec::new();
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -218,7 +199,6 @@ fn main() {
writeln!(file, "{:#?}", info).unwrap();
}
}
#[cfg(feature = "msl-out")]
"metal" => {
use naga::back::msl;

Expand All @@ -232,7 +212,6 @@ fn main() {
.unwrap_pretty();
fs::write(output_path, msl).unwrap();
}
#[cfg(feature = "spv-out")]
"spv" => {
use naga::back::spv;

Expand All @@ -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;

Expand All @@ -265,14 +243,12 @@ 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;
// TODO: Get `ShaderModel` from user
Expand All @@ -284,19 +260,14 @@ fn main() {
.unwrap_pretty();
fs::write(output_path, hlsl).unwrap();
}
#[cfg(feature = "wgsl-out")]
"wgsl" => {
use naga::back::wgsl;

let wgsl = wgsl::write_string(&module, info.as_ref().unwrap()).unwrap_pretty();
fs::write(output_path, wgsl).unwrap();
}
other => {
let _ = params;
println!(
"Unknown output extension: {}, forgot to enable a feature?",
other
);
println!("Unknown output extension: {}", other);
}
}
}
Expand Down

0 comments on commit c78c03b

Please sign in to comment.