From 1e5dfcf21c0e323b07010ef42345c48d4c509834 Mon Sep 17 00:00:00 2001 From: Ousama Ben Younes Date: Fri, 24 Jul 2026 08:20:03 +0000 Subject: [PATCH 1/2] fix: let go.sh accept PHP_CONFIG --- go.sh | 7 ++++-- go_sh_test.sh | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) create mode 100755 go_sh_test.sh diff --git a/go.sh b/go.sh index a1172206aa..f3d6d704af 100755 --- a/go.sh +++ b/go.sh @@ -1,7 +1,10 @@ #!/bin/sh # Runs the go command with the proper Go and cgo flags. +readonly DEFAULT_PHP_CONFIG="php-config" +PHP_CONFIG="${PHP_CONFIG:-${DEFAULT_PHP_CONFIG}}" + GOFLAGS="$GOFLAGS -tags=nobadger,nomysql,nopgx" \ - CGO_CFLAGS="$CGO_CFLAGS $(php-config --includes) $(sh "$(dirname "$0")/mtls-cflags.sh")" \ - CGO_LDFLAGS="$CGO_LDFLAGS $(php-config --ldflags) $(php-config --libs)" \ + CGO_CFLAGS="$CGO_CFLAGS $("${PHP_CONFIG}" --includes) $(sh "$(dirname "$0")/mtls-cflags.sh")" \ + CGO_LDFLAGS="$CGO_LDFLAGS $("${PHP_CONFIG}" --ldflags) $("${PHP_CONFIG}" --libs)" \ go "$@" diff --git a/go_sh_test.sh b/go_sh_test.sh new file mode 100755 index 0000000000..e113c851b9 --- /dev/null +++ b/go_sh_test.sh @@ -0,0 +1,68 @@ +#!/bin/sh +set -eu + +readonly TEST_PHP_CONFIG="custom-php-config" +readonly TEST_PATH_PHP_CONFIG_ERROR="go.sh ignored PHP_CONFIG" +readonly TEST_PHP_INCLUDE_FLAG="-I/custom/php/include" +readonly TEST_PHP_LDFLAG="-Wl,-rpath,/custom/php/lib" +readonly TEST_PHP_LIBS="-lxml2" +readonly TEST_EXISTING_CFLAGS="-Dexisting" +readonly TEST_EXISTING_LDFLAGS="-lexisting" +readonly EXPECTED_CGO_LDFLAGS="${TEST_EXISTING_LDFLAGS} ${TEST_PHP_LDFLAG} ${TEST_PHP_LIBS}" + +ROOT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)" +TMP_DIR="$(mktemp -d)" +OUTPUT_FILE="${TMP_DIR}/go-env" + +cleanup() { + rm -rf "${TMP_DIR}" +} +trap cleanup EXIT INT TERM + +cat >"${TMP_DIR}/php-config" <&2 +exit 42 +PHP_CONFIG_PATH + +cat >"${TMP_DIR}/${TEST_PHP_CONFIG}" <&2 + exit 2 + ;; +esac +PHP_CONFIG + +cat >"${TMP_DIR}/go" <<'GO' +#!/bin/sh +{ + printf 'CGO_CFLAGS=%s\n' "${CGO_CFLAGS}" + printf 'CGO_LDFLAGS=%s\n' "${CGO_LDFLAGS}" + printf 'GOFLAGS=%s\n' "${GOFLAGS}" + printf 'ARGS=%s\n' "$*" +} >"${OUTPUT_FILE}" +GO + +chmod +x "${TMP_DIR}/php-config" "${TMP_DIR}/${TEST_PHP_CONFIG}" "${TMP_DIR}/go" + +PATH="${TMP_DIR}:${PATH}" \ + CGO_CFLAGS="${TEST_EXISTING_CFLAGS}" \ + CGO_LDFLAGS="${TEST_EXISTING_LDFLAGS}" \ + PHP_CONFIG="${TMP_DIR}/${TEST_PHP_CONFIG}" \ + OUTPUT_FILE="${OUTPUT_FILE}" \ + "${ROOT_DIR}/go.sh" build -v + +grep -F "CGO_CFLAGS=${TEST_EXISTING_CFLAGS} ${TEST_PHP_INCLUDE_FLAG}" "${OUTPUT_FILE}" +grep -Fx "CGO_LDFLAGS=${EXPECTED_CGO_LDFLAGS}" "${OUTPUT_FILE}" +grep -Fx "ARGS=build -v" "${OUTPUT_FILE}" From 0ddd12c5e86e8864bced98da0c44d4a1dfc49db9 Mon Sep 17 00:00:00 2001 From: Ousama Ben Younes Date: Fri, 24 Jul 2026 09:39:49 +0000 Subject: [PATCH 2/2] fix: simplify PHP_CONFIG handling in go.sh --- go.sh | 7 ++---- go_sh_test.sh | 68 --------------------------------------------------- 2 files changed, 2 insertions(+), 73 deletions(-) delete mode 100755 go_sh_test.sh diff --git a/go.sh b/go.sh index f3d6d704af..9774a8cef5 100755 --- a/go.sh +++ b/go.sh @@ -1,10 +1,7 @@ #!/bin/sh # Runs the go command with the proper Go and cgo flags. -readonly DEFAULT_PHP_CONFIG="php-config" -PHP_CONFIG="${PHP_CONFIG:-${DEFAULT_PHP_CONFIG}}" - GOFLAGS="$GOFLAGS -tags=nobadger,nomysql,nopgx" \ - CGO_CFLAGS="$CGO_CFLAGS $("${PHP_CONFIG}" --includes) $(sh "$(dirname "$0")/mtls-cflags.sh")" \ - CGO_LDFLAGS="$CGO_LDFLAGS $("${PHP_CONFIG}" --ldflags) $("${PHP_CONFIG}" --libs)" \ + CGO_CFLAGS="$CGO_CFLAGS $(${PHP_CONFIG:-php-config} --includes) $(sh "$(dirname "$0")/mtls-cflags.sh")" \ + CGO_LDFLAGS="$CGO_LDFLAGS $(${PHP_CONFIG:-php-config} --ldflags) $(${PHP_CONFIG:-php-config} --libs)" \ go "$@" diff --git a/go_sh_test.sh b/go_sh_test.sh deleted file mode 100755 index e113c851b9..0000000000 --- a/go_sh_test.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/sh -set -eu - -readonly TEST_PHP_CONFIG="custom-php-config" -readonly TEST_PATH_PHP_CONFIG_ERROR="go.sh ignored PHP_CONFIG" -readonly TEST_PHP_INCLUDE_FLAG="-I/custom/php/include" -readonly TEST_PHP_LDFLAG="-Wl,-rpath,/custom/php/lib" -readonly TEST_PHP_LIBS="-lxml2" -readonly TEST_EXISTING_CFLAGS="-Dexisting" -readonly TEST_EXISTING_LDFLAGS="-lexisting" -readonly EXPECTED_CGO_LDFLAGS="${TEST_EXISTING_LDFLAGS} ${TEST_PHP_LDFLAG} ${TEST_PHP_LIBS}" - -ROOT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)" -TMP_DIR="$(mktemp -d)" -OUTPUT_FILE="${TMP_DIR}/go-env" - -cleanup() { - rm -rf "${TMP_DIR}" -} -trap cleanup EXIT INT TERM - -cat >"${TMP_DIR}/php-config" <&2 -exit 42 -PHP_CONFIG_PATH - -cat >"${TMP_DIR}/${TEST_PHP_CONFIG}" <&2 - exit 2 - ;; -esac -PHP_CONFIG - -cat >"${TMP_DIR}/go" <<'GO' -#!/bin/sh -{ - printf 'CGO_CFLAGS=%s\n' "${CGO_CFLAGS}" - printf 'CGO_LDFLAGS=%s\n' "${CGO_LDFLAGS}" - printf 'GOFLAGS=%s\n' "${GOFLAGS}" - printf 'ARGS=%s\n' "$*" -} >"${OUTPUT_FILE}" -GO - -chmod +x "${TMP_DIR}/php-config" "${TMP_DIR}/${TEST_PHP_CONFIG}" "${TMP_DIR}/go" - -PATH="${TMP_DIR}:${PATH}" \ - CGO_CFLAGS="${TEST_EXISTING_CFLAGS}" \ - CGO_LDFLAGS="${TEST_EXISTING_LDFLAGS}" \ - PHP_CONFIG="${TMP_DIR}/${TEST_PHP_CONFIG}" \ - OUTPUT_FILE="${OUTPUT_FILE}" \ - "${ROOT_DIR}/go.sh" build -v - -grep -F "CGO_CFLAGS=${TEST_EXISTING_CFLAGS} ${TEST_PHP_INCLUDE_FLAG}" "${OUTPUT_FILE}" -grep -Fx "CGO_LDFLAGS=${EXPECTED_CGO_LDFLAGS}" "${OUTPUT_FILE}" -grep -Fx "ARGS=build -v" "${OUTPUT_FILE}"