From b4426ff9399c2d262458cd092762186138d41ecd Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 30 Oct 2026 18:52:24 +0000 Subject: [PATCH] build(bazel): use pre-installed system php when available --- repositories.bzl | 1 + rules_php_gapic/php_repo.bzl | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/repositories.bzl b/repositories.bzl index 20e36bf1c..497efc2d0 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -29,6 +29,7 @@ def gapic_generator_php_repositories(): maybe( php, name = "php_micro", + version = _php_version, urls = ["https://www.php.net/distributions/php-%s.tar.gz" % _php_version ], strip_prefix = "php-%s" % _php_version, ) diff --git a/rules_php_gapic/php_repo.bzl b/rules_php_gapic/php_repo.bzl index 882836be6..5ddca7444 100644 --- a/rules_php_gapic/php_repo.bzl +++ b/rules_php_gapic/php_repo.bzl @@ -36,7 +36,26 @@ filegroup( os_name = ctx.os.name - # First try using the prebuilt version + # First try using a pre-installed system php if it meets the minimum version and extension requirements + system_php = ctx.which("php") + if system_php != None: + res, _str = _execute_log_action( + ctx, + "system_php_test.log", + [ + str(system_php), + "-n", + "-r", + "\"exit((!('%s' !== '' && version_compare(PHP_VERSION, '%s', '<')) && extension_loaded('libxml') && extension_loaded('curl') && extension_loaded('openssl') && extension_loaded('mbstring') && extension_loaded('bcmath')) ? 0:1);\"" % (ctx.attr.version, ctx.attr.version), + ], + ) + if res.return_code == 0: + _execute_and_check_result(ctx, ["mkdir", "-p", "bin"]) + _execute_and_check_result(ctx, ["cp", str(system_php), "bin/php"]) + ctx.file("BUILD.bazel", build_bazel) + return + + # Next try using the prebuilt version for prebuilt_php in ctx.attr.prebuilt_phps: if prebuilt_php.name.find(os_name) < 0: continue @@ -110,6 +129,7 @@ filegroup( php = repository_rule( implementation = _php_impl, attrs = { + "version": attr.string(), "urls": attr.string_list(), "strip_prefix": attr.string(), "prebuilt_phps": attr.label_list(allow_files = True, mandatory = False),