alexcrichton / openssl-src-rs

Source code and logic to build OpenSSL from source
Apache License 2.0
70 stars 114 forks source link

Surface the failing command's name from the build error dump #253

Closed kornelski closed 2 months ago

kornelski commented 2 months ago

Because Cargo's formatting of build errors is very noisy users struggle to understand what is causing the build to fail.

Here's a recent case where the failure reason was simple, but the user could not see it through all the noise.


    Compiling openssl-sys v0.9.103 (~/openssl-sys/openssl-sys)
+The following warnings were emitted during compilation:
+
+warning: openssl-sys@0.9.103: configuring OpenSSL build: Command 'perl' not found. Is perl installed?
+
 error: failed to run custom build command for `openssl-sys v0.9.103 (~/openssl-sys/openssl-sys)`
 note: To improve backtraces for build dependencies, set the CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG=true environment variable to enable debug information generation.

 Caused by:
   process didn't exit successfully: `~/openssl-sys/target/debug/build/openssl-sys-60b6752181d583d2/build-script-main` (exit status: 101)

 [...]

   --- stderr
-   thread 'main' panicked at ~/openssl-src-rs/src/lib.rs:578:14:
+   thread 'main' panicked at ~/openssl-sys/build/find_vendored.rs:18:39:

   Error configuring OpenSSL build:
-      Command: cd "~/openssl-sys/target/debug/build/openssl-sys-8f90d3753aa6037e/out/openssl-build/build/src" && env -u CROSS_COMPILE AR="ar" CC="cc" RANLIB="ranlib" "perl" "./Configure" "--prefix=~/openssl-sys/target/debug/build/openssl-sys-8f90d3753aa6037e/out/openssl-build/install" "--openssldir=/usr/local/ssl" "no-dso" "no-shared" "no-ssl3" "no-tests" "no-comp" "no-zlib" "no-zlib-dynamic" "--libdir=lib" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "darwin64-arm64-cc" "-nologo" "-MD" "-O2" "-Z7" "-Brepro" "-mmacosx-version-min=11.0"
-      Failed to execute: No such file or directory (os error 2)
+      Command 'perl' not found. Is perl installed?
+      Command failed: cd "~/openssl-sys/target/debug/build/openssl-sys-3ae48db4843d8fdf/out/openssl-build/build/src" && env -u CROSS_COMPILE AR="ar" CC="cc" RANLIB="ranlib" "perl" "./Configure" "--prefix=~/openssl-sys/target/debug/build/openssl-sys-3ae48db4843d8fdf/out/openssl-build/install" "--openssldir=/usr/local/ssl" "no-shared" "no-ssl3" "no-tests" "no-comp" "no-zlib" "no-zlib-dynamic" "--libdir=lib" "no-md2" "no-rc5" "no-weak-ssl-ciphers" "no-camellia" "no-idea" "no-seed" "darwin64-arm64-cc" "-nologo" "-MD" "-O2" "-Z7" "-Brepro" "-mmacosx-version-min=11.0"
kornelski commented 2 months ago

I've also added try_build, so that I can make openssl-sys report the error without a noisy backtrace.

bjorn3 commented 2 months ago

Instead of using panic, maybe using eprintln!() + std::process::exit(1) would work? openssl-src is probably not called in any context where recovering from an unexpected build error is necessary, and you added try_build for cases where build errors are expected to happen.

kornelski commented 2 months ago

Exiting directly without a panic would be cleaner, but I'm leaving that to the caller of try_build – I'm adding such exits to openssl-sys.

kornelski commented 2 months ago

I've updated it with a clean exit, and converted other panics into errors.

alexcrichton commented 2 months ago

Thanks for this!