From 5a0743a17b4c49ef68294a6a564b9438805bbf2b Mon Sep 17 00:00:00 2001 From: DanS Date: Thu, 23 Jul 2026 17:59:05 -0500 Subject: [PATCH] fix(setup): skip sudo apt when the Windows toolchain is already installed setup.sh --win ran `sudo apt-get install` (and update-alternatives) unconditionally, forcing the whole run under sudo even when mingw-w64 was already present. Running setup as root makes the daemon cross-compile run as root, leaving root-owned artifacts under external/dragonx that break `make clean` on a later non-sudo build (stale objects relink -> mingw link failure recurs). Gate the apt/update-alternatives block behind a presence check so `./setup.sh --win` runs sudo-free (and the daemon build as the invoking user) when the toolchain is already installed. Co-Authored-By: Claude Fable 5 --- setup.sh | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/setup.sh b/setup.sh index 49245ec..4020627 100755 --- a/setup.sh +++ b/setup.sh @@ -284,18 +284,27 @@ fi header "Windows Cross-Compile" if $SETUP_WIN; then - win_pkgs="$(get_pkgs win)" - if [[ -n "$win_pkgs" ]]; then - install_pkgs "$win_pkgs" "Windows cross-compile" - fi + # Only touch apt / update-alternatives (which need sudo) when the toolchain is missing. If it is + # already installed, skip them so `./setup.sh --win` can run WITHOUT sudo — important because the + # daemon cross-compile that follows should run as the invoking user. Running the whole setup under + # sudo leaves root-owned build artifacts under external/dragonx, which then break `make clean` on + # a later non-sudo build (stale objects get relinked -> the mingw link failure recurs). + if has_cmd x86_64-w64-mingw32-g++-posix || has_cmd x86_64-w64-mingw32-g++; then + ok "Windows cross-compile toolchain already present — skipping apt install" + else + win_pkgs="$(get_pkgs win)" + if [[ -n "$win_pkgs" ]]; then + install_pkgs "$win_pkgs" "Windows cross-compile" + fi - # Set posix thread model if available - if has_cmd update-alternatives && [[ "$PKG" == "apt" ]]; then - if ! $CHECK_ONLY; then - sudo update-alternatives --set x86_64-w64-mingw32-gcc \ - /usr/bin/x86_64-w64-mingw32-gcc-posix 2>/dev/null || true - sudo update-alternatives --set x86_64-w64-mingw32-g++ \ - /usr/bin/x86_64-w64-mingw32-g++-posix 2>/dev/null || true + # Set posix thread model if available + if has_cmd update-alternatives && [[ "$PKG" == "apt" ]]; then + if ! $CHECK_ONLY; then + sudo update-alternatives --set x86_64-w64-mingw32-gcc \ + /usr/bin/x86_64-w64-mingw32-gcc-posix 2>/dev/null || true + sudo update-alternatives --set x86_64-w64-mingw32-g++ \ + /usr/bin/x86_64-w64-mingw32-g++-posix 2>/dev/null || true + fi fi fi