From 1692b7c8a1fa2f9fb534307133acf652674454fa Mon Sep 17 00:00:00 2001 From: Andrej Orsula Date: Mon, 8 Jan 2024 15:34:18 +0100 Subject: [PATCH] Make build script errors more explicit Signed-off-by: Andrej Orsula --- Cargo.lock | 2 -- Cargo.toml | 1 - pxr_build/Cargo.toml | 1 - pxr_build/src/codegen/vt/value.rs | 4 +-- pxr_build/src/lib.rs | 2 +- pxr_build/src/utils/codegen.rs | 14 ++++---- pxr_sys/Cargo.toml | 1 - pxr_sys/build.rs | 53 +++++++++++++++---------------- 8 files changed, 34 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0fd20be..f2172b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1152,7 +1152,6 @@ dependencies = [ name = "pxr_build" version = "0.1.0" dependencies = [ - "anyhow", "regex", "which 5.0.0", ] @@ -1161,7 +1160,6 @@ dependencies = [ name = "pxr_sys" version = "0.1.0" dependencies = [ - "anyhow", "autocxx", "autocxx-build", "built_different", diff --git a/Cargo.toml b/Cargo.toml index df7e6a9..a094641 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ version = "0.1.0" pxr_build = { path = "pxr_build", version = "0.1.0" } pxr_sys = { path = "pxr_sys", version = "0.1.0" } -anyhow = { version = "1.0" } autocxx = { version = "0.26" } autocxx-build = { version = "0.26" } built_different = { version = "0.1" } diff --git a/pxr_build/Cargo.toml b/pxr_build/Cargo.toml index 9f130a0..00ed046 100644 --- a/pxr_build/Cargo.toml +++ b/pxr_build/Cargo.toml @@ -12,7 +12,6 @@ rust-version.workspace = true version.workspace = true [dependencies] -anyhow = { workspace = true } regex = { workspace = true } which = { workspace = true } diff --git a/pxr_build/src/codegen/vt/value.rs b/pxr_build/src/codegen/vt/value.rs index 8eccefb..7f5361e 100644 --- a/pxr_build/src/codegen/vt/value.rs +++ b/pxr_build/src/codegen/vt/value.rs @@ -93,7 +93,7 @@ macro_rules! gen_vt_value { }; } -pub fn codegen(out: impl AsRef) -> anyhow::Result<()> { +pub fn codegen(out: impl AsRef) { let code = gen_vt_value![ bool as "bool", u8 as "uint8_t" => "unsigned char", @@ -140,5 +140,5 @@ pub fn codegen(out: impl AsRef) -> anyhow::Result<()> { crate::pxr::GfVec4i as "pxr::GfVec4i" => "GfVec4i", [i32; 4] as "pxr::GfVec4i" => "GfVec4i", ]; - crate::codegen_write(&code, out) + crate::codegen_write(&code, out); } diff --git a/pxr_build/src/lib.rs b/pxr_build/src/lib.rs index fac3dd5..77a3979 100644 --- a/pxr_build/src/lib.rs +++ b/pxr_build/src/lib.rs @@ -4,4 +4,4 @@ pub mod codegen; mod utils; pub use codegen::*; -pub(crate) use utils::codegen::codegen_write; +pub(crate) use utils::codegen_write; diff --git a/pxr_build/src/utils/codegen.rs b/pxr_build/src/utils/codegen.rs index a200a81..53ea768 100644 --- a/pxr_build/src/utils/codegen.rs +++ b/pxr_build/src/utils/codegen.rs @@ -6,7 +6,7 @@ pub const HEADER: &str = "\ //! It is not intended for manual editing. "; -pub fn codegen_write(code: &str, out: impl AsRef) -> anyhow::Result<()> { +pub fn codegen_write(code: &str, out: impl AsRef) { // Try formatting the generated code if rustfmt is available. let code = rustfmt(code).unwrap_or_else(|_| code.to_string()); @@ -16,20 +16,18 @@ pub fn codegen_write(code: &str, out: impl AsRef) -> anyhow::Result<()> { // Don't overwrite the file if it hasn't changed (ignoring whitespace differences) let out = out.as_ref(); if out.exists() { - let original_code = std::fs::read_to_string(out)?; + let original_code = std::fs::read_to_string(out).unwrap(); if remove_redundant_whitespace(&original_code) == remove_redundant_whitespace(&code) { - return Ok(()); + return; } } // Ensure the parent directory exists if let Some(parent) = out.parent() { - std::fs::create_dir_all(parent)?; + std::fs::create_dir_all(parent).unwrap(); } // Write the generated code to a file. - let mut file = std::fs::File::create(out)?; - file.write_all(code.as_bytes())?; - - Ok(()) + let mut file = std::fs::File::create(out).unwrap(); + file.write_all(code.as_bytes()).unwrap(); } diff --git a/pxr_sys/Cargo.toml b/pxr_sys/Cargo.toml index 56e1f14..b6e9d46 100644 --- a/pxr_sys/Cargo.toml +++ b/pxr_sys/Cargo.toml @@ -20,7 +20,6 @@ half = { workspace = true } thiserror = { workspace = true } [build-dependencies] -anyhow = { workspace = true } autocxx-build = { workspace = true } built_different = { workspace = true } cpp_build = { workspace = true } diff --git a/pxr_sys/build.rs b/pxr_sys/build.rs index 0f79d0b..a7b72b6 100644 --- a/pxr_sys/build.rs +++ b/pxr_sys/build.rs @@ -173,7 +173,7 @@ fn main() { // If the `vendored` feature is enabled, download and compile OpenUSD (or use the previously cached installation) #[cfg(feature = "vendored")] - vendored::download_and_compile_openusd().unwrap() + vendored::download_and_compile_openusd() } }; // Verify that the OpenUSD installation contains the required subdirectories @@ -294,21 +294,19 @@ fn main() { .collect::>(); // Expand macros to generate Rust code with `cpp` macros (workaround | `cpp!` macros cannot be nested) - bindings::expand_macros_cpp().unwrap(); + bindings::expand_macros_cpp(); // Compile C++ code with `cpp` - bindings::compile_cpp(&include_paths).unwrap(); + bindings::compile_cpp(&include_paths); // Generate bindings with `autocxx` - bindings::generate_autocxx(&include_paths).unwrap(); + bindings::generate_autocxx(&include_paths); } /// Module that contains functions for generating bindings. mod bindings { - pub fn generate_autocxx( - include_paths: impl IntoIterator>, - ) -> anyhow::Result<()> { - autocxx_build::Builder::new("src/ffi/bindings.rs", include_paths.into_iter()) + pub fn generate_autocxx(include_paths: impl IntoIterator>) { + autocxx_build::Builder::new("src/ffi/bindings.rs", include_paths) .extra_clang_args(&[ "-x", "c++", @@ -318,7 +316,8 @@ mod bindings { &format!("-D_GLIBCXX_USE_CXX11_ABI={}", super::USE_CXX11_ABI), "-Wno-everything", ]) - .build()? + .build() + .unwrap() .compiler("clang") .flag("-x") .flag("c++") @@ -328,23 +327,19 @@ mod bindings { .define("_GLIBCXX_USE_CXX11_ABI", Some(super::USE_CXX11_ABI)) .flag("-Wno-everything") .compile("openusd_sys_autocxx"); - Ok(()) } - pub fn expand_macros_cpp() -> anyhow::Result<()> { + pub fn expand_macros_cpp() { pxr_build::codegen::codegen_vt_value( std::path::PathBuf::from("src") .join("ffi") .join("pxr") .join("vt") .join("value.rs"), - )?; - Ok(()) + ); } - pub fn compile_cpp( - include_paths: impl IntoIterator>, - ) -> anyhow::Result<()> { + pub fn compile_cpp(include_paths: impl IntoIterator>) { // Configure rebuild triggers based on file changes walkdir::WalkDir::new("src/ffi") .into_iter() @@ -375,13 +370,12 @@ mod bindings { cpp_builder = cpp_builder.include(path); } cpp_builder.build("src/lib.rs"); - Ok(()) } } #[cfg(feature = "vendored")] mod vendored { - pub fn download_and_compile_openusd() -> anyhow::Result { + pub fn download_and_compile_openusd() -> std::path::PathBuf { // ENV: Determine if the download should be forced regardless of the cache validity println!("cargo:rerun-if-env-changed=OPENUSD_DOWNLOAD_FORCE"); let force_download = built_different::parse_bool_env("OPENUSD_DOWNLOAD_FORCE", false); @@ -413,7 +407,7 @@ mod vendored { // Skip download if the cache is valid and download is not forced if !force_download && cache_path.exists() { - return Ok(cache_path); + return cache_path; } // Determine the path where the OpenUSD source will be extracted @@ -430,13 +424,15 @@ mod vendored { &download_url, &openusd_extract_path, force_download, - )?; + ) + .unwrap(); // Locate the root of the OpenUSD source let openusd_src_path = openusd_extract_path.join(format!("OpenUSD-{openusd_version}")); // Apply compile-time patches - built_different::apply_file_patches_in_place("patches/src", &openusd_src_path, true, true)?; + built_different::apply_file_patches_in_place("patches/src", &openusd_src_path, true, true) + .unwrap(); // Locate the build script let build_script_path = openusd_src_path.join("build_scripts").join("build_usd.py"); @@ -534,7 +530,8 @@ mod vendored { .arg(&openusd_install_path) .stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped()) - .output()?; + .output() + .unwrap(); let status = output.status; if !status.success() { let stdout = String::from_utf8_lossy(&output.stdout); @@ -543,20 +540,20 @@ mod vendored { } // Remove the source now that it is no longer needed - std::fs::remove_dir_all(&openusd_extract_path)?; - std::fs::remove_dir_all(openusd_install_path.join("src"))?; + std::fs::remove_dir_all(&openusd_extract_path).unwrap(); + std::fs::remove_dir_all(openusd_install_path.join("src")).unwrap(); // Move OpenUSD to the cache or create a symlink if symlink_cache && !cache_path.is_dir() { - built_different::create_symlink(&openusd_install_path, &cache_path, true)?; + built_different::create_symlink(&openusd_install_path, &cache_path, true).unwrap(); } else { if let Some(parent) = cache_path.parent() { - std::fs::create_dir_all(parent)?; + std::fs::create_dir_all(parent).unwrap(); } - std::fs::rename(&openusd_install_path, &cache_path)?; + std::fs::rename(&openusd_install_path, &cache_path).unwrap(); } - Ok(cache_path) + cache_path } fn determine_cache_path_openusd(version: &str) -> std::path::PathBuf {