diff options
Diffstat (limited to 'engine/build.rs')
| -rw-r--r-- | engine/build.rs | 81 |
1 files changed, 56 insertions, 25 deletions
diff --git a/engine/build.rs b/engine/build.rs index 58029fc..7ad5a9b 100644 --- a/engine/build.rs +++ b/engine/build.rs @@ -1,33 +1,58 @@ -// Original file: -// https://github.com/rust-windowing/glutin/blob/ -// 0433af9018febe0696c485ed9d66c40dad41f2d4/glutin-winit/build.rs -// -// Copyright © 2022 Kirill Chibisov -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the “Software”), to deal -// in the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -// of the Software, and to permit persons to whom the Software is furnished to do -// so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -// Keep this in sync with glutin's build.rs. +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::<CargoMetadata>( + 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. @@ -61,3 +86,9 @@ fn main() // cgl_backend: { all(macos_platform, not(wasm_platform)) }, } } + +#[derive(Debug, Deserialize)] +struct CargoMetadata +{ + target_directory: PathBuf, +} |
