Skip to content

Commit

Permalink
Provide build_internal error context
Browse files Browse the repository at this point in the history
  • Loading branch information
shutton committed Jan 24, 2024
1 parent 4503a17 commit 7427398
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 11 additions & 6 deletions clamav-sys/build_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn bindgen_internal(output_path: &Path) -> anyhow::Result<()> {
std::env::vars()
.filter(|(k, _)| ENV_PATTERNS.iter().any(|prefix| k.starts_with(prefix)))
.for_each(|(k, v)| eprintln!(" {}={:?}", k, v));
detect_clamav_build()?;
detect_clamav_build().map_err(|e| anyhow!("detect_clamav_build: {e}"))?;

// We only want to generate bindings for `cargo build`, not `cargo test`.
// FindRust.cmake defines $CARGO_CMD so we can differentiate.
Expand All @@ -114,13 +114,15 @@ pub fn bindgen_internal(output_path: &Path) -> anyhow::Result<()> {
// On the plus-side, this means that our `.rs` file is present before our
// first build, so at least rust-analyzer will be happy.
if super::in_maintainer_mode() {
execute_bindgen(output_path)?;
execute_bindgen(output_path).map_err(|e| anyhow!("execute_bindgen: {e}"))?;
// And place a copy in the source tree (for potential check-in)
std::fs::copy(output_path, BINDGEN_OUTPUT_FILE)?;
std::fs::copy(output_path, BINDGEN_OUTPUT_FILE)
.map_err(|e| anyhow!("copying {output_path:?} to {BINDGEN_OUTPUT_FILE}: {e}"))?;
} else {
// Otherwise, just copy the pre-generated file to the specified
// location.
std::fs::copy(BINDGEN_OUTPUT_FILE, output_path)?;
std::fs::copy(BINDGEN_OUTPUT_FILE, output_path)
.map_err(|e| anyhow!("copying {BINDGEN_OUTPUT_FILE} to {output_path:?}: {e}"))?;
}
} else {
eprintln!("NOTE: Not generating bindings because CARGO_CMD != build");
Expand Down Expand Up @@ -182,7 +184,9 @@ fn execute_bindgen(output_path: &Path) -> anyhow::Result<()> {
fn detect_clamav_build() -> anyhow::Result<()> {
println!("cargo:rerun-if-env-changed=LIBCLAMAV");

if search_and_link_lib("LIBCLAMAV")? {
if search_and_link_lib("LIBCLAMAV")
.map_err(|e| anyhow!("search_and_link_lib(LIBCLAMAV): {e}"))?
{
eprintln!("NOTE: LIBCLAMAV defined. Examining LIB* environment variables");
// Need to link with libclamav dependencies

Expand Down Expand Up @@ -267,7 +271,8 @@ fn search_and_link_lib(environment_variable: &str) -> anyhow::Result<bool> {
}
};

let parsed_path = parse_lib_path(&filepath_str)?;
let parsed_path = parse_lib_path(&filepath_str)
.map_err(|e| anyhow!("parse_lib_path({filepath_str}): {e}"))?;
eprintln!(
" - adding {:?} to rustc library search path",
&parsed_path.dir
Expand Down
8 changes: 8 additions & 0 deletions macos-cmake-github.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

PATH="/usr/local/opt/flex/bin:$PATH"; export PATH
LDFLAGS="-L/usr/local/opt/flex/lib"; export LDFLAGS
CPPFLAGS="-I/usr/local/opt/flex/include"; export CPPFLAGS
PATH="/usr/local/opt/bison/bin:$PATH"; export PATH
#cmake .. -D OPENSSL_ROOT_DIR=/usr/local/opt/openssl -D CMAKE_BUILD_TYPE=Release -D ENABLE_STATIC_LIB=ON -D ENABLE_EXAMPLES=ON
cmake .. -D CMAKE_BUILD_TYPE=Release -D ENABLE_STATIC_LIB=ON -D ENABLE_EXAMPLES=ON

0 comments on commit 7427398

Please sign in to comment.