Add bazel php:release target for PECL tgz using generated package.xml (#10845)

* Add bazel php:release target for PECL tgz using generated package.xml

* move targets from php/ext/google/protobuf to php packages since this breaks dist_files and add utf8 license file

* Remove package.xml form Makefile.am

* add files to Makefile.am
pull/10960/head
zhangskz 2 years ago committed by GitHub
parent ba01779860
commit accd49b95a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      .github/workflows/php-ext.yml
  2. 3
      Makefile.am
  3. 77
      php/BUILD.bazel
  4. 39
      php/ext/google/protobuf/generate_package_xml.sh
  5. 1467
      php/ext/google/protobuf/package.xml
  6. 42
      php/ext/google/protobuf/template_package.xml
  7. 1
      protobuf_version.bzl
  8. 16
      third_party/utf8_range/BUILD.bazel

@ -15,6 +15,16 @@ jobs:
- php:7.4-cli - php:7.4-cli
- php:8.1-cli - php:8.1-cli
steps: steps:
- name: Install python3
run: |
apt-get update -q
apt-get install -qy python3
- name: Install bazel
run: |
apt-get install -qy wget
mkdir $HOME/bin
wget -O $HOME/bin/bazel https://github.com/bazelbuild/bazel/releases/download/5.3.2/bazel-5.3.2-linux-x86_64
chmod a+x $HOME/bin/bazel
- name: Install git - name: Install git
run: | run: |
apt-get update -q apt-get update -q
@ -23,20 +33,15 @@ jobs:
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
submodules: recursive submodules: recursive
- name: Prepare source code
run: |
rm -rf "$GITHUB_WORKSPACE/php/ext/google/protobuf/third_party"
cp -r "$GITHUB_WORKSPACE/third_party" "$GITHUB_WORKSPACE/php/ext/google/protobuf"
cp "$GITHUB_WORKSPACE/LICENSE" "$GITHUB_WORKSPACE/php/ext/google/protobuf"
- name: Create package - name: Create package
run: | run: |
cd /tmp cd $GITHUB_WORKSPACE
rm -rf protobuf-*.tgz rm -rf bazel-bin/php/protobuf-*.tgz
pecl package "$GITHUB_WORKSPACE/php/ext/google/protobuf/package.xml" $HOME/bin/bazel build php:release
- name: Compile extension - name: Compile extension
run: | run: |
cd /tmp cd /tmp
MAKE="make -j$(nproc)" pecl install protobuf-*.tgz MAKE="make -j$(nproc)" pecl install $GITHUB_WORKSPACE/bazel-bin/php/protobuf-*.tgz
- name: Enable extension - name: Enable extension
run: docker-php-ext-enable protobuf run: docker-php-ext-enable protobuf
- name: Inspect extension - name: Inspect extension

@ -809,18 +809,19 @@ php_EXTRA_DIST= \
php/ext/google/protobuf/convert.h \ php/ext/google/protobuf/convert.h \
php/ext/google/protobuf/def.c \ php/ext/google/protobuf/def.c \
php/ext/google/protobuf/def.h \ php/ext/google/protobuf/def.h \
php/ext/google/protobuf/generate_package_xml.sh \
php/ext/google/protobuf/map.c \ php/ext/google/protobuf/map.c \
php/ext/google/protobuf/map.h \ php/ext/google/protobuf/map.h \
php/ext/google/protobuf/message.c \ php/ext/google/protobuf/message.c \
php/ext/google/protobuf/message.h \ php/ext/google/protobuf/message.h \
php/ext/google/protobuf/names.c \ php/ext/google/protobuf/names.c \
php/ext/google/protobuf/names.h \ php/ext/google/protobuf/names.h \
php/ext/google/protobuf/package.xml \
php/ext/google/protobuf/php-upb.c \ php/ext/google/protobuf/php-upb.c \
php/ext/google/protobuf/php-upb.h \ php/ext/google/protobuf/php-upb.h \
php/ext/google/protobuf/php_protobuf.h \ php/ext/google/protobuf/php_protobuf.h \
php/ext/google/protobuf/protobuf.c \ php/ext/google/protobuf/protobuf.c \
php/ext/google/protobuf/protobuf.h \ php/ext/google/protobuf/protobuf.h \
php/ext/google/protobuf/template_package.xml \
php/ext/google/protobuf/wkt.inc \ php/ext/google/protobuf/wkt.inc \
php/ext/google/protobuf/tests/unnecessary_zval.phpt \ php/ext/google/protobuf/tests/unnecessary_zval.phpt \
php/generate_descriptor_protos.sh \ php/generate_descriptor_protos.sh \

@ -2,7 +2,9 @@
# #
# See also code generation logic under /src/google/protobuf/compiler/php. # See also code generation logic under /src/google/protobuf/compiler/php.
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@rules_pkg//:mappings.bzl", "pkg_files", "pkg_filegroup", "strip_prefix")
load("//:protobuf_version.bzl", "PROTOBUF_PHP_VERSION")
pkg_files( pkg_files(
name = "dist_files", name = "dist_files",
@ -30,3 +32,76 @@ pkg_files(
strip_prefix = strip_prefix.from_pkg(""), strip_prefix = strip_prefix.from_pkg(""),
visibility = ["//pkg:__pkg__"], visibility = ["//pkg:__pkg__"],
) )
################################################################################
# PECL .tgz Release
################################################################################
pkg_files(
name = "php_ext_source_files",
srcs = glob([
"ext/google/protobuf/*.h",
"ext/google/protobuf/*.c",
]) + [
"//:LICENSE",
"ext/google/protobuf/config.m4",
"ext/google/protobuf/wkt.inc",
],
)
pkg_files(
name = "utf8_range_files",
srcs = [
"//third_party/utf8_range:utf8_range_srcs",
"//third_party/utf8_range:LICENSE",
],
prefix = "third_party/utf8_range",
)
pkg_filegroup(
name = "pecl_release_files",
srcs = [
":php_ext_source_files",
":utf8_range_files",
],
prefix = "protobuf-%s" % PROTOBUF_PHP_VERSION,
)
# PECL .tgz without package.xml
pkg_tar(
name = "release_without_package",
extension = "tgz",
srcs = [
":pecl_release_files",
],
out = "release_without_package.tgz",
)
# Generate PECL package.xml
genrule(
name = "generate_package_xml",
srcs = [
":release_without_package",
"ext/google/protobuf/template_package.xml",
],
outs = ["package.xml"],
cmd = " ".join([
"$(location ext/google/protobuf/generate_package_xml.sh)",
"$(location ext/google/protobuf/template_package.xml)",
PROTOBUF_PHP_VERSION,
"$$(tar -tf $(location :release_without_package) | sed -z -e 's;\\n;,;g')",
"$(location package.xml)"
]),
tools = ["ext/google/protobuf/generate_package_xml.sh"],
)
pkg_tar(
name = "release",
extension = "tgz",
srcs = [
":pecl_release_files",
":generate_package_xml",
],
out = "protobuf-%s.tgz" % PROTOBUF_PHP_VERSION,
)

@ -0,0 +1,39 @@
#!/bin/bash
template_package_xml=$1
release_version=$2
release_files=$3
out=$4
date=$(date +%Y-%m-%d)
time=$(date +%H:%M:%S)
php_version_array=(${release_version//RC/ })
api_version=${php_version_array[0]}
if [ ${#php_version_array[@]} -eq 2 ]; then
rc=${php_version_array[1]}
stability='beta'
else
stability='stable'
fi
files="\\n"
for file in ${release_files//,/ }; do
name=$(echo $file | grep .*[^/]\$ | sed -e "s;protobuf-${release_version}/;;")
if [ ! -z $name ]; then
if [[ $name =~ LICENSE$ ]]; then
role='doc'
else
role='src'
fi
files+=" <file baseinstalldir=\"/\" name=\"${name}\" role=\"${role}\"/>\\n"
fi
done
cat $template_package_xml |
sed -e "s;TEMPLATE_DATE;${date};" |
sed -e "s;TEMPLATE_TIME;${time};" |
sed -e "s;TEMPLATE_PHP_RELEASE;${release_version};" |
sed -e "s;TEMPLATE_PHP_API;${api_version};" |
sed -e "s;TEMPLATE_PHP_STABILITY;${stability};g" |
sed -e "s;TEMPLATE_FILES;${files};" > $out

File diff suppressed because it is too large Load Diff

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.9.5" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>protobuf</name>
<channel>pecl.php.net</channel>
<summary>Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.</summary>
<description>https://developers.google.com/protocol-buffers/</description>
<lead>
<name>Protobuf Team</name>
<user>protobufpackages</user>
<email>protobuf-packages@google.com</email>
<active>yes</active>
</lead>
<date>TEMPLATE_DATE</date>
<time>TEMPLATE_TIME</time>
<version>
<release>TEMPLATE_PHP_RELEASE</release>
<api>TEMPLATE_PHP_API</api>
</version>
<stability>
<release>TEMPLATE_PHP_STABILITY</release>
<api>TEMPLATE_PHP_STABILITY</api>
</stability>
<license uri="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</license>
<notes>
* See github.com/protocolbuffers/protobuf/releases for release notes.
</notes>
<contents>
<dir baseinstalldir="/" name="/">TEMPLATE_FILES</dir>
</contents>
<dependencies>
<required>
<php>
<min>7.0.0</min>
</php>
<pearinstaller>
<min>1.4.0</min>
</pearinstaller>
</required>
</dependencies>
<providesextension>protobuf</providesextension>
<extsrcrelease/>
</package>

@ -1,3 +1,4 @@
PROTOC_VERSION = "21.9" PROTOC_VERSION = "21.9"
PROTOBUF_JAVA_VERSION = "3.21.9" PROTOBUF_JAVA_VERSION = "3.21.9"
PROTOBUF_PYTHON_VERSION = "4.21.9" PROTOBUF_PYTHON_VERSION = "4.21.9"
PROTOBUF_PHP_VERSION = "3.21.9"

@ -1,6 +1,22 @@
# Pulled from: https://github.com/cyb70289/utf8 # Pulled from: https://github.com/cyb70289/utf8
exports_files(["LICENSE"])
filegroup(
name = "utf8_range_srcs",
srcs = [
"naive.c",
"range2-neon.c",
"range2-sse.c",
"utf8_range.h",
],
visibility = [
"@com_google_protobuf//:__subpackages__",
"@upb//:__subpackages__",
],
)
cc_library( cc_library(
name = "utf8_range", name = "utf8_range",
hdrs = ["utf8_range.h"], hdrs = ["utf8_range.h"],

Loading…
Cancel
Save