1# Protobuf PHP runtime 2# 3# See also code generation logic under /src/google/protobuf/compiler/php. 4 5load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix") 6load("@rules_pkg//pkg:tar.bzl", "pkg_tar") 7load("//:protobuf_version.bzl", "PROTOBUF_PHP_VERSION", "PROTOC_VERSION") 8load("//build_defs:internal_shell.bzl", "inline_sh_binary") 9load("//conformance:defs.bzl", "conformance_test") 10load("//upb/cmake:build_defs.bzl", "staleness_test") 11 12filegroup( 13 name = "source_files", 14 srcs = glob([ 15 "src/GPBMetadata/Google/Protobuf/**/*.php", 16 "src/Google/Protobuf/**/*.php", 17 ]) + [ 18 "composer.json", 19 ":php_ext_source_files", 20 ], 21 visibility = [ 22 "//conformance:__pkg__", 23 "//php:__pkg__", 24 ], 25) 26 27################################################################################ 28# PHP Extension 29################################################################################ 30 31inline_sh_binary( 32 name = "build_extension", 33 cmd = """ 34 mkdir -p php/ext/google/protobuf/third_party/utf8_range 35 cp third_party/utf8_range/* php/ext/google/protobuf/third_party/utf8_range 36 37 pushd php/ext/google/protobuf 38 phpize 39 ./configure --with-php-config=$$(which php-config) 40 make 41 popd 42 """, 43) 44 45genrule( 46 name = "extension", 47 srcs = [ 48 ":source_files", 49 "//third_party/utf8_range:utf8_range_srcs", 50 ], 51 outs = ["protobuf.so"], 52 cmd = """ 53 ./$(execpath :build_extension) $@ 54 cp php/ext/google/protobuf/modules/protobuf.so $(OUTS) 55 """, 56 tools = [":build_extension"], 57 visibility = ["//visibility:public"], 58) 59 60################################################################################ 61# Tests 62################################################################################ 63 64conformance_test( 65 name = "conformance_test", 66 failure_list = "//conformance:failure_list_php.txt", 67 maximum_edition = "2023", 68 target_compatible_with = select({ 69 "@platforms//os:osx": ["@platforms//:incompatible"], 70 "//conditions:default": [], 71 }), 72 testee = "//conformance:conformance_php", 73 text_format_failure_list = "//conformance:text_format_failure_list_php.txt", 74) 75 76conformance_test( 77 name = "conformance_test_c", 78 failure_list = "//conformance:failure_list_php_c.txt", 79 maximum_edition = "2023", 80 target_compatible_with = select({ 81 "@platforms//os:osx": [], 82 "//conditions:default": ["@platforms//:incompatible"], 83 }), 84 testee = "//conformance:conformance_php_c", 85 text_format_failure_list = "//conformance:text_format_failure_list_php.txt", 86) 87 88genrule( 89 name = "copy_php_amalgamation_h", 90 srcs = ["//upb:php-upb.h"], 91 outs = ["generated-in/ext/google/protobuf/php-upb.h"], 92 cmd = "cp $< $@", 93) 94 95genrule( 96 name = "copy_php_amalgamation_c", 97 srcs = ["//upb:php-upb.c"], 98 outs = ["generated-in/ext/google/protobuf/php-upb.c"], 99 cmd = "cp $< $@", 100) 101 102staleness_test( 103 name = "test_amalgamation_staleness", 104 outs = [ 105 "ext/google/protobuf/php-upb.c", 106 "ext/google/protobuf/php-upb.h", 107 ], 108 generated_pattern = "generated-in/%s", 109 tags = ["manual"], 110) 111 112################################################################################ 113# Distribution files 114################################################################################ 115 116pkg_files( 117 name = "dist_files", 118 srcs = glob([ 119 "ext/google/protobuf/**/*", 120 "tests/*.php", 121 "tests/*.sh", 122 "tests/generated_previous/**/*.php", 123 "tests/proto/**/*.proto", 124 "tests/proto_previous/*.proto", 125 ]) + [ 126 "BUILD.bazel", 127 "README.md", 128 "REFCOUNTING.md", 129 "composer.json", 130 "generate_descriptor_protos.sh", 131 "generate_test_protos.sh", 132 "release.sh", 133 "src/phpdoc.dist.xml", 134 "tests/valgrind.supp", 135 ":source_files", 136 ], 137 prefix = "php", 138 strip_prefix = strip_prefix.from_pkg(""), 139 visibility = ["//pkg:__pkg__"], 140) 141 142################################################################################ 143# PECL .tgz Release 144################################################################################ 145 146pkg_files( 147 name = "php_ext_source_files", 148 srcs = glob([ 149 "ext/google/protobuf/*.h", 150 "ext/google/protobuf/*.c", 151 ]) + [ 152 "ext/google/protobuf/config.m4", 153 "ext/google/protobuf/config.w32", 154 "ext/google/protobuf/wkt.inc", 155 "//:LICENSE", 156 ], 157) 158 159pkg_files( 160 name = "utf8_range_files", 161 srcs = [ 162 "//third_party/utf8_range:LICENSE", 163 "//third_party/utf8_range:utf8_range_srcs", 164 ], 165 prefix = "third_party/utf8_range", 166) 167 168pkg_filegroup( 169 name = "pecl_release_files", 170 srcs = [ 171 ":php_ext_source_files", 172 ":utf8_range_files", 173 ], 174 prefix = "protobuf-%s" % PROTOBUF_PHP_VERSION, 175) 176 177# PECL .tgz without package.xml 178pkg_tar( 179 name = "release_without_package", 180 srcs = [ 181 ":pecl_release_files", 182 ], 183 out = "release_without_package.tgz", 184 extension = "tgz", 185) 186 187# Generate PECL package.xml 188genrule( 189 name = "generate_package_xml", 190 srcs = [ 191 ":release_without_package", 192 "ext/google/protobuf/template_package.xml", 193 ], 194 outs = ["package.xml"], 195 cmd = " ".join([ 196 "$(location ext/google/protobuf/generate_package_xml.sh)", 197 "$(location ext/google/protobuf/template_package.xml)", 198 PROTOBUF_PHP_VERSION, 199 PROTOC_VERSION, 200 "$$(tar -tf $(location :release_without_package) | sed -z -e 's;\\n;,;g')", 201 "$(location package.xml)", 202 ]), 203 tools = ["ext/google/protobuf/generate_package_xml.sh"], 204) 205 206pkg_tar( 207 name = "release", 208 srcs = [ 209 ":generate_package_xml", 210 ":pecl_release_files", 211 ], 212 out = "protobuf-%s.tgz" % PROTOBUF_PHP_VERSION, 213 extension = "tgz", 214) 215