Every now and then when building my project using cargo build the build process will hang on building a third-party crate. Up until now it's always been aws-lc-sys, but today I'm getting what looks like the same behaviour with mimalloc-sys.
Through verbose cargo output I trace this to the execution of build-script-build hanging. I then ran that binary manually which seemed to suggest the C compiler was hanging. Running again with CC_ENABLE_DEBUG_OUTPUT=1 confirmed that. The last output line I see is
running: "cc" "-E" "<project_root>/target/release/build/libmimalloc-sys-8a98c87ac87a2446/out/13408290981209617847detect_compiler_family.c"
Full build-script-build output
CARGO=/Users/pepijn/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo CARGO_CFG_FEATURE='' CARGO_CFG_PANIC=unwind CARGO_CFG_TARGET_ABI='' CARGO_CFG_TARGET_ARCH=aarch64 CARGO_CFG_TARGET_ENDIAN=little CARGO_CFG_TARGET_ENV='' CARGO_CFG_TARGET_FAMILY=unix CARGO_CFG_TARGET_FEATURE=aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,vh CARGO_CFG_TARGET_HAS_ATOMIC=128,16,32,64,8,ptr CARGO_CFG_TARGET_OS=macos CARGO_CFG_TARGET_POINTER_WIDTH=64 CARGO_CFG_TARGET_VENDOR=apple CARGO_CFG_UNIX='' CARGO_ENCODED_RUSTFLAGS='' CARGO_MANIFEST_DIR=/Users/pepijn/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libmimalloc-sys-0.1.44 CARGO_MANIFEST_LINKS=mimalloc CARGO_MANIFEST_PATH=/Users/pepijn/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libmimalloc-sys-0.1.44/Cargo.toml CARGO_PKG_AUTHORS='Octavian Oncescu <octavonce@gmail.com>' CARGO_PKG_DESCRIPTION='Sys crate wrapping the mimalloc allocator' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE=MIT CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=libmimalloc-sys CARGO_PKG_README='' CARGO_PKG_REPOSITORY='https://github.com/purpleprotocol/mimalloc_rust/tree/master/libmimalloc-sys' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.44 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=44 CARGO_PKG_VERSION_PRE='' DEBUG=false DYLD_FALLBACK_LIBRARY_PATH='<project root>/target/release/deps:<project root>/target/release:/Users/pepijn/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib:/Users/pepijn/.rustup/toolchains/stable-aarch64-apple-darwin/lib:/Users/pepijn/lib:/usr/local/lib:/usr/lib' HOST=aarch64-apple-darwin NUM_JOBS=10 OPT_LEVEL=3 RUST_BACKTRACE=1 OUT_DIR=<project root>/target/release/build/libmimalloc-sys-8a98c87ac87a2446/out PROFILE=release CC_ENABLE_DEBUG_OUTPUT=true RUSTC=/Users/pepijn/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc RUSTDOC=/Users/pepijn/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustdoc TARGET=aarch64-apple-darwin <project root>/target/release/build/libmimalloc-sys-c9219c1a459c644f/build-script-build --help
OPT_LEVEL = Some(3)
OUT_DIR = Some(<project root>/target/release/build/libmimalloc-sys-8a98c87ac87a2446/out)
TARGET = Some(aarch64-apple-darwin)
HOST = Some(aarch64-apple-darwin)
cargo:rerun-if-env-changed=CC_aarch64-apple-darwin
CC_aarch64-apple-darwin = None
cargo:rerun-if-env-changed=CC_aarch64_apple_darwin
CC_aarch64_apple_darwin = None
cargo:rerun-if-env-changed=HOST_CC
HOST_CC = None
cargo:rerun-if-env-changed=CC
CC = None
cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
running: "cc" "-E" "<project root>/target/release/build/libmimalloc-sys-8a98c87ac87a2446/out/13408290981209617847detect_compiler_family.c"
at this point in activity monitor I can see a clang subprocess running with 0% cpu usage. A dump of the process show it's hanging in a write syscall.
clang call stack
Call graph:
2587 Thread_6468193 DispatchQueue_1: com.apple.main-thread (serial)
2587 start (in dyld) + 6076 [0x181efeb98]
2587 main (in clang) + 84 [0x100ccb944]
2587 clang_main(int, char**, llvm::ToolContext const&) (in clang) + 216 [0x100cb3084]
2587 driver_main(int, char**, llvm::ToolContext const&) (in clang) + 4752 [0x100cb4378]
2587 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (in clang) + 1144 [0x100cb4900]
2587 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (in clang) + 2160 [0x100cb95a8]
2587 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (in clang) + 460 [0x101314344]
2587 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (in clang) + 452 [0x102eaf30c]
2587 <deduplicated_symbol> (in clang) + 532 [0x104bf3a78]
2587 llvm::raw_fd_ostream::write_impl(char const*, unsigned long) (in clang) + 72 [0x104bf4898]
2587 write (in libsystem_kernel.dylib) + 8 [0x1822616f4]
Running the exact same cc invocation manually works fine and produces the following output
cc output
"cc" "-E" "/Users/pepijn/RustroverProjects/datafusion_playground/target/release/build/libmimalloc-sys-8a98c87ac87a2446/out/13408290981209617847detect_compiler_family.c"
# 1 "/Users/pepijn/RustroverProjects/datafusion_playground/target/release/build/libmimalloc-sys-8a98c87ac87a2446/out/13408290981209617847detect_compiler_family.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 466 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "/Users/pepijn/RustroverProjects/datafusion_playground/target/release/build/libmimalloc-sys-8a98c87ac87a2446/out/13408290981209617847detect_compiler_family.c" 2
/Users/pepijn/RustroverProjects/datafusion_playground/target/release/build/libmimalloc-sys-8a98c87ac87a2446/out/13408290981209617847detect_compiler_family.c:2:9: warning: clang [-W#pragma-messages]
2 | #pragma message "clang"
| ^
#pragma message("clang")/Users/pepijn/RustroverProjects/datafusion_playground/target/release/build/libmimalloc-sys-8a98c87ac87a2446/out/13408290981209617847detect_compiler_family.c:6:9: warning: gcc [-W#pragma-messages]
6 | #pragma message "gcc"
| ^
#pragma message("gcc")
2 warnings generated.
The best I can make of this is that something's going wrong in the communication between the parent and child process. Perhaps the child's stdout or stderr pipe is not being drained properly or something like that.
Does anyone have an idea what could be going on here or how I can troubleshoot further?