diff --git a/install-scripts/hyprwire.sh b/install-scripts/hyprwire.sh index 4958688..1daf57e 100755 --- a/install-scripts/hyprwire.sh +++ b/install-scripts/hyprwire.sh @@ -12,10 +12,33 @@ if [ -z "${HYPRWIRE_TAG:-}" ]; then fi if [ -n "${HYPRWIRE_TAG:-}" ]; then tag="$HYPRWIRE_TAG"; fi -# Dry-run support +# Dry-run support + shim controls DO_INSTALL=1 -if [ "$1" = "--dry-run" ] || [ "${DRY_RUN}" = "1" ] || [ "${DRY_RUN}" = "true" ]; then +FORCE_SHIM=0 +NO_SHIM=0 + +for arg in "$@"; do + case "$arg" in + --dry-run) + DO_INSTALL=0 + ;; + # Force the compatibility shim used on Debian 13 (trixie) toolchains. + # This is intentionally distro-named so it's obvious what it does for most users. + --build-trixie|--force-shim) + FORCE_SHIM=1 + ;; + # For testing/sid (or any toolchain that supports std::vector::append_range), allow opting out. + --no-shim) + NO_SHIM=1 + ;; + esac +done + +if [ "${DRY_RUN}" = "1" ] || [ "${DRY_RUN}" = "true" ]; then DO_INSTALL=0 +fi + +if [ $DO_INSTALL -eq 0 ]; then echo "${NOTE} DRY RUN: install step will be skipped." fi @@ -48,30 +71,71 @@ fi if git clone --recursive -b "$tag" https://github.com/hyprwm/hyprwire.git; then cd hyprwire || exit 1 - # Temporary compatibility shim for compilers/libstdc++ without std::vector::append_range - cat > append_range_compat.hpp <<'EOF' + # Decide whether we need the append_range compatibility shim. + # On Debian 13 (trixie), libstdc++ typically lacks std::vector::append_range, so we patch. + # On newer toolchains (testing/sid), prefer building upstream unmodified. + NEED_SHIM=0 + if [ "$NO_SHIM" -eq 1 ]; then + NEED_SHIM=0 + elif [ "$FORCE_SHIM" -eq 1 ]; then + NEED_SHIM=1 + else + CXX_TEST="${CXX:-c++}" + TMPD="$(mktemp -d)" + cat >"$TMPD/append_range_test.cpp" <<'EOF' +#include +int main() { + std::vector v; + v.append_range(std::vector{1,2,3}); + return 0; +} +EOF + if "$CXX_TEST" -std=c++23 -c "$TMPD/append_range_test.cpp" -o /dev/null >/dev/null 2>&1; then + NEED_SHIM=0 + else + NEED_SHIM=1 + fi + rm -rf "$TMPD" + fi + + if [ "$NEED_SHIM" -eq 1 ]; then + echo "${NOTE} Applying append_range compatibility shim (use --no-shim to disable; --build-trixie to force)." + + # Temporary compatibility shim for toolchains where libstdc++ lacks std::vector::append_range (C++23 library feature). + # Note: append_range in upstream accepts temporaries (e.g. encodeVarInt(...) returns a temporary vector). To support that, + # we bind the expression to a named auto&& first. + cat > append_range_compat.hpp <<'EOF' #pragma once #include -#define APPEND_RANGE(vec, ...) (vec).insert((vec).end(), std::begin(__VA_ARGS__), std::end(__VA_ARGS__)) + +// Append any begin/end range to a container, supporting temporaries by binding to auto&&. +#define APPEND_RANGE(vec, ...) do { \ + auto&& _r = (__VA_ARGS__); \ + (vec).insert((vec).end(), std::begin(_r), std::end(_r)); \ +} while(0) EOF -# Replace X.append_range(Y) -> APPEND_RANGE(X, Y) only where it appears -PATCH_FILES=$(grep -RIl --exclude-dir=.git 'append_range\(' . || true) -if [ -n "$PATCH_FILES" ]; then - # Replace LHS .append_range(arg...) with APPEND_RANGE(LHS, arg...) - # LHS: identifiers and common member/ptr chains (this->obj, ns::obj.member) - echo "$PATCH_FILES" | xargs -r sed -ri 's/([A-Za-z_][A-Za-z0-9_:\->\.]+)\s*\.\s*append_range\s*\(/APPEND_RANGE(\1, /g' - # Show any remaining occurrences - REMAIN=$(grep -RIn --exclude-dir=.git '\.\s*append_range\s*\(' $PATCH_FILES || true) - if [ -n "$REMAIN" ]; then - echo "[WARN] Some append_range() calls remain unpatched:" >&2 - echo "$REMAIN" >&2 + + # Replace X.(.|->)append_range(Y) -> APPEND_RANGE(X, Y) only where it appears + PATCH_FILES=$(grep -RIl --exclude-dir=.git -F 'append_range(' . || true) + if [ -n "$PATCH_FILES" ]; then + # LHS: identifiers and common member/ptr chains (this->obj, ns::obj.member) + echo "$PATCH_FILES" | xargs -r sed -ri 's/([A-Za-z_][A-Za-z0-9_:>.\-]+)\s*(\.|->)\s*append_range\s*\(/APPEND_RANGE(\1, /g' + # Show any remaining occurrences + REMAIN=$(grep -RIn --exclude-dir=.git -E '(\.|->)[[:space:]]*append_range[[:space:]]*\(' $PATCH_FILES || true) + if [ -n "$REMAIN" ]; then + echo "[WARN] Some append_range() calls remain unpatched:" >&2 + echo "$REMAIN" >&2 + fi + fi + + # Absolute path for forced include + APPEND_HDR="$(pwd)/append_range_compat.hpp" + + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_CXX_STANDARD=23 -DCMAKE_CXX_FLAGS="-include ${APPEND_HDR}" + else + echo "${NOTE} Toolchain supports std::vector::append_range; building hyprwire without shim." + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_CXX_STANDARD=23 fi -fi - -# Absolute path for forced include -APPEND_HDR="$(pwd)/append_range_compat.hpp" - -cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_CXX_STANDARD=23 -DCMAKE_CXX_FLAGS="-include ${APPEND_HDR}" cmake --build build -j "$(nproc 2>/dev/null || getconf _NPROCESSORS_CONF)" if [ $DO_INSTALL -eq 1 ]; then if sudo cmake --install build 2>&1 | tee -a "$MLOG" ; then