53 lines
2.1 KiB
Rust
53 lines
2.1 KiB
Rust
use std::env;
|
|
use std::fs;
|
|
use std::path::Path;
|
|
|
|
fn compile_wgsl_to_spv(src_path: &str, out_name: &str) {
|
|
println!("cargo:rerun-if-changed={}", src_path);
|
|
let source = fs::read_to_string(src_path)
|
|
.unwrap_or_else(|e| panic!("Failed to read shader {}: {}", src_path, e));
|
|
|
|
let module = naga::front::wgsl::parse_str(&source)
|
|
.unwrap_or_else(|e| panic!("WGSL parse error in {}:\n{}", src_path, e.emit_to_string(&source)));
|
|
|
|
let info = naga::valid::Validator::new(
|
|
naga::valid::ValidationFlags::all(),
|
|
naga::valid::Capabilities::PUSH_CONSTANT,
|
|
)
|
|
.validate(&module)
|
|
.unwrap_or_else(|e| panic!("WGSL validation error in {}:\n{:?}", src_path, e));
|
|
|
|
let mut options = naga::back::spv::Options::default();
|
|
options.lang_version = (1, 3);
|
|
options.flags = naga::back::spv::WriterFlags::LABEL_VARYINGS;
|
|
|
|
let words = naga::back::spv::write_vec(&module, &info, &options, None)
|
|
.unwrap_or_else(|e| panic!("SPIR-V emit error in {}: {:?}", src_path, e));
|
|
|
|
let bytes: Vec<u8> = words.iter().flat_map(|w| w.to_le_bytes()).collect();
|
|
let out_dir = env::var("OUT_DIR").unwrap();
|
|
let dest = Path::new(&out_dir).join(out_name);
|
|
fs::write(&dest, bytes).expect("Failed to write SPIR-V output");
|
|
}
|
|
|
|
fn main() {
|
|
compile_wgsl_to_spv("shaders/ui_sdf.wgsl", "ui_sdf.spv");
|
|
compile_wgsl_to_spv("shaders/blur.wgsl", "blur.spv");
|
|
compile_wgsl_to_spv("shaders/vibe.wgsl", "vibe.spv");
|
|
|
|
#[cfg(target_os = "windows")]
|
|
if env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows") {
|
|
let ico = "packaging/icons/yandex-music-rs.ico";
|
|
println!("cargo:rerun-if-changed={}", ico);
|
|
if Path::new(ico).exists() {
|
|
let mut res = winresource::WindowsResource::new();
|
|
res.set_icon(ico);
|
|
res.set("ProductName", "Яндекс Музыка (yandex-music-rs)");
|
|
res.set("FileDescription", "Yandex Music Desktop Client");
|
|
res.set("CompanyName", "marwy");
|
|
if let Err(e) = res.compile() {
|
|
println!("cargo:warning=winresource failed: {}", e);
|
|
}
|
|
}
|
|
}
|
|
}
|