blas-lapack-rs / openblas-src

Source of BLAS and LAPACK via OpenBLAS
Other
78 stars 48 forks source link

unwrap call in `windows_msvc_system` results in unclear error message. #82

Closed cgranade closed 2 days ago

cgranade commented 2 years ago

When attempting to compile a crate that depends on openblas-src with static and system features enabled and when using a Windows host, a confusing error message is raised when necessary vcpkg packages are not yet installed:

➜ cargo build
   Compiling openblas-src v0.10.4
error: failed to run custom build command for `openblas-src v0.10.4`

Caused by:
  process didn't exit successfully: `<path-to-project>\target\debug\build\openblas-src-ee3a2010492c76c2\build-script-build` (exit code: 101)
  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: VcpkgInstallation("could not read status file updates dir: The system cannot find the path specified. (os error 3)")', C:\Users\<username>\.cargo\registry\src\github.com-1ecc6299db9ec823\openblas-src-0.10.4\build.rs:40:37
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The root cause seems to be an unwrap call at build.rs:40:

/// Use vcpkg for msvc "system" feature
fn windows_msvc_system() {
    if feature_enabled("static") {
        env::set_var("CARGO_CFG_TARGET_FEATURE", "crt-static");
    } else {
        env::set_var("VCPKGRS_DYNAMIC", "1");
    }
    #[cfg(target_env = "msvc")]
    vcpkg::find_package("openblas").unwrap();  // ← this unwrap fails when openblas pkg is missing
    if !cfg!(target_env = "msvc") {
        unreachable!();
    }
}