use std::path::{Path, PathBuf}; use std::process::Command; use cfg_aliases::cfg_aliases; use serde::Deserialize; fn main() { let slang_artifacts = std::env::var("DEP_CRATE_SHADER_SLANG_ARTIFACTS").unwrap(); let cargo_metadata_output = Command::new(build_rs::input::cargo()) .args([ "metadata", "--format-version=1", "-q", "--no-deps", "--color=never", "--manifest-path", build_rs::input::cargo_manifest_path().to_str().unwrap(), ]) .output() .unwrap(); if !cargo_metadata_output.status.success() { panic!( "'cargo metadata' command failed:\n\nstdout:\n{}\n\nstderr:\n{}", String::from_utf8_lossy(&cargo_metadata_output.stdout), String::from_utf8_lossy(&cargo_metadata_output.stderr), ); } let cargo_metadata = serde_json::from_str::( str::from_utf8(&cargo_metadata_output.stdout).unwrap(), ) .unwrap(); let final_artifact_dir = (if build_rs::input::target() == build_rs::input::host() { cargo_metadata.target_directory } else { cargo_metadata .target_directory .join(build_rs::input::target()) }) .join(build_rs::input::profile()); for artifact_path in slang_artifacts.split(";") { let artifact_path = Path::new(artifact_path); std::fs::copy( artifact_path, final_artifact_dir.join(artifact_path.file_name().unwrap()), ) .unwrap(); } // Setup alias to reduce `cfg` boilerplate. cfg_aliases! { // Systems. android_platform: { target_os = "android" }, wasm_platform: { target_family = "wasm" }, macos_platform: { target_os = "macos" }, ios_platform: { target_os = "ios" }, apple: { any(ios_platform, macos_platform) }, free_unix: { all(unix, not(apple), not(android_platform)) }, // Native displays. x11_platform: { all(free_unix, not(wasm_platform)) }, wayland_platform: { all(free_unix, not(wasm_platform)) }, // x11_platform: { all(feature = "x11", free_unix, not(wasm_platform)) }, // wayland_platform: { all(feature = "wayland", free_unix, not(wasm_platform)) }, // Backends. egl_backend: { all(any(windows, unix), not(apple), not(wasm_platform)) }, glx_backend: { all(x11_platform, not(wasm_platform)) }, wgl_backend: { all(windows, not(wasm_platform)) }, cgl_backend: { all(macos_platform, not(wasm_platform)) }, // Backends. // egl_backend: { // all(feature = "egl", any(windows, unix), not(apple), not(wasm_platform)) // }, // glx_backend: { all(feature = "glx", x11_platform, not(wasm_platform)) }, // wgl_backend: { all(feature = "wgl", windows, not(wasm_platform)) }, // cgl_backend: { all(macos_platform, not(wasm_platform)) }, } } #[derive(Debug, Deserialize)] struct CargoMetadata { target_directory: PathBuf, }