From 91ec685eaf5694bd9282aff38b3baaabd92f1c0a Mon Sep 17 00:00:00 2001 From: Yuma Endo Date: Sun, 22 Mar 2026 10:35:55 +0900 Subject: [PATCH 1/3] fix: inject Homebrew library paths into configure on macOS GNU build systems (autoconf) need explicit --with-xxx paths to find libraries installed via Homebrew, since /opt/homebrew is not in the default search path. After verifying Homebrew prerequisites exist, detect the Homebrew prefix (/opt/homebrew for ARM, /usr/local for Intel) and inject --with-gmp/mpfr/mpc/isl flags into configure_args automatically. Mold-specified --with-xxx flags take precedence (skip injection). --- scripts/cast-ingot.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/scripts/cast-ingot.sh b/scripts/cast-ingot.sh index 6736b35..7ae822f 100755 --- a/scripts/cast-ingot.sh +++ b/scripts/cast-ingot.sh @@ -823,6 +823,46 @@ elif [[ "$SOURCE_TYPE" == "build" ]]; then exit 3 fi pass "Build dependencies verified on macOS" + + # Detect Homebrew prefix and inject --with-xxx flags for + # configure. GNU build systems (autoconf) need explicit + # paths to find libraries installed via Homebrew because + # /opt/homebrew is not in the default search path. + HB_PREFIX="" + if [[ -d /opt/homebrew ]]; then + HB_PREFIX="/opt/homebrew" + elif [[ -d /usr/local/Cellar ]]; then + HB_PREFIX="/usr/local" + fi + + if [[ -n "$HB_PREFIX" ]]; then + # Map apt package names to autoconf --with-xxx flag names + declare -A _HB_FLAG_MAP=( + [libgmp-dev]="gmp" + [libmpfr-dev]="mpfr" + [libmpc-dev]="mpc" + [libisl-dev]="isl" + ) + for pkg in "${APT_PACKAGES[@]}"; do + _flag_name="${_HB_FLAG_MAP[$pkg]:-}" + if [[ -z "$_flag_name" ]]; then + continue + fi + # Skip if mold already specifies --with-xxx + _already_set=false + for _arg in "${CONFIGURE_ARGS[@]}"; do + if [[ "$_arg" == --with-${_flag_name}=* ]]; then + _already_set=true + break + fi + done + if [[ "$_already_set" == "false" ]]; then + CONFIGURE_ARGS+=("--with-${_flag_name}=${HB_PREFIX}") + info "macOS: injected --with-${_flag_name}=${HB_PREFIX}" + fi + done + unset _HB_FLAG_MAP + fi fi else info "No prerequisites defined" From c661a165984356d021513b0e7c9c6c9900b004c5 Mon Sep 17 00:00:00 2001 From: Yuma Endo Date: Sun, 22 Mar 2026 10:39:27 +0900 Subject: [PATCH 2/3] fix: use bash 3.2 compatible case statement for Homebrew path injection - Replace declare -A (requires bash 4.0+) with case statement (macOS ships bash 3.2, GitHub Actions macos-14 also uses 3.2) - Only inject --with-xxx for autoconf projects (guard on ./configure) - Detect --with-xxx, --with-xxx=*, and --without-xxx as overrides - Prefer brew --prefix for path detection, fallback to known paths --- scripts/cast-ingot.sh | 47 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/scripts/cast-ingot.sh b/scripts/cast-ingot.sh index 7ae822f..5b4704e 100755 --- a/scripts/cast-ingot.sh +++ b/scripts/cast-ingot.sh @@ -825,43 +825,50 @@ elif [[ "$SOURCE_TYPE" == "build" ]]; then pass "Build dependencies verified on macOS" # Detect Homebrew prefix and inject --with-xxx flags for - # configure. GNU build systems (autoconf) need explicit - # paths to find libraries installed via Homebrew because + # autoconf projects. GNU build systems need explicit paths + # to find libraries installed via Homebrew because # /opt/homebrew is not in the default search path. + # NOTE: Only applies to autoconf (./configure). CMake + # projects require different variable names (e.g. -DGMP_ROOT). HB_PREFIX="" - if [[ -d /opt/homebrew ]]; then + if command -v brew &>/dev/null; then + HB_PREFIX="$(brew --prefix)" + elif [[ -d /opt/homebrew ]]; then HB_PREFIX="/opt/homebrew" elif [[ -d /usr/local/Cellar ]]; then HB_PREFIX="/usr/local" fi - if [[ -n "$HB_PREFIX" ]]; then - # Map apt package names to autoconf --with-xxx flag names - declare -A _HB_FLAG_MAP=( - [libgmp-dev]="gmp" - [libmpfr-dev]="mpfr" - [libmpc-dev]="mpc" - [libisl-dev]="isl" - ) + if [[ -n "$HB_PREFIX" ]] && [[ -x "${SOURCE_DIR}/configure" ]]; then for pkg in "${APT_PACKAGES[@]}"; do - _flag_name="${_HB_FLAG_MAP[$pkg]:-}" + _flag_name="" + case "$pkg" in + libgmp-dev) _flag_name="gmp" ;; + libmpfr-dev) _flag_name="mpfr" ;; + libmpc-dev) _flag_name="mpc" ;; + libisl-dev) _flag_name="isl" ;; + esac + if [[ -z "$_flag_name" ]]; then continue fi - # Skip if mold already specifies --with-xxx - _already_set=false + + # Skip if mold already specifies --with-xxx or --without-xxx + _skip=0 for _arg in "${CONFIGURE_ARGS[@]}"; do - if [[ "$_arg" == --with-${_flag_name}=* ]]; then - _already_set=true - break - fi + case "$_arg" in + --with-${_flag_name}=*|--with-${_flag_name}|--without-${_flag_name}) + _skip=1 + break + ;; + esac done - if [[ "$_already_set" == "false" ]]; then + + if [[ $_skip -eq 0 ]]; then CONFIGURE_ARGS+=("--with-${_flag_name}=${HB_PREFIX}") info "macOS: injected --with-${_flag_name}=${HB_PREFIX}" fi done - unset _HB_FLAG_MAP fi fi else From 0f1b4d15db1f301c9ed7ff69a968fd7be97ec23e Mon Sep 17 00:00:00 2001 From: Yuma Endo Date: Sun, 22 Mar 2026 10:42:24 +0900 Subject: [PATCH 3/3] fix: handle brew --prefix failure and --without-xxx=* override - Fall back to hardcoded paths if brew --prefix fails or returns empty - Detect --without-xxx=* in addition to --without-xxx --- scripts/cast-ingot.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/cast-ingot.sh b/scripts/cast-ingot.sh index 5b4704e..30920a3 100755 --- a/scripts/cast-ingot.sh +++ b/scripts/cast-ingot.sh @@ -832,10 +832,11 @@ elif [[ "$SOURCE_TYPE" == "build" ]]; then # projects require different variable names (e.g. -DGMP_ROOT). HB_PREFIX="" if command -v brew &>/dev/null; then - HB_PREFIX="$(brew --prefix)" - elif [[ -d /opt/homebrew ]]; then + HB_PREFIX="$(brew --prefix 2>/dev/null || true)" + fi + if [[ -z "$HB_PREFIX" ]] && [[ -d /opt/homebrew ]]; then HB_PREFIX="/opt/homebrew" - elif [[ -d /usr/local/Cellar ]]; then + elif [[ -z "$HB_PREFIX" ]] && [[ -d /usr/local/Cellar ]]; then HB_PREFIX="/usr/local" fi @@ -857,7 +858,7 @@ elif [[ "$SOURCE_TYPE" == "build" ]]; then _skip=0 for _arg in "${CONFIGURE_ARGS[@]}"; do case "$_arg" in - --with-${_flag_name}=*|--with-${_flag_name}|--without-${_flag_name}) + --with-${_flag_name}=*|--with-${_flag_name}|--without-${_flag_name}|--without-${_flag_name}=*) _skip=1 break ;;