Skip to content

Commit

Permalink
Reapply "[build] Convert project file generation programs to C++ (#386……
Browse files Browse the repository at this point in the history
… (grpc#38768)

This reverts commit 6be50c9.
  • Loading branch information
ctiller committed Feb 19, 2025
1 parent 40a5e54 commit bd51f39
Show file tree
Hide file tree
Showing 18 changed files with 1,966 additions and 80 deletions.
2 changes: 0 additions & 2 deletions config.m4

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions templates/config.m4.inja
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
PHP_ARG_ENABLE(grpc, whether to enable grpc support,
[ --enable-grpc Enable grpc support])

if test "$PHP_GRPC" != "no"; then
dnl Write more examples of tests here...

dnl # --with-grpc -> add include path
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/include)
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/src/core/ext/upb-gen)
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/src/core/ext/upbdefs-gen)
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/src/php/ext/grpc)
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/third_party/abseil-cpp)
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/third_party/address_sorting/include)
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/third_party/boringssl-with-bazel/src/include)
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/third_party/re2)
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/third_party/upb)
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/third_party/utf8_range)
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/third_party/xxhash)

LIBS="-lpthread $LIBS"

CFLAGS="-std=c11 -g -O2"
CXXFLAGS="-std=c++17 -fno-exceptions -fno-rtti -g -O2"
GRPC_SHARED_LIBADD="-lpthread $GRPC_SHARED_LIBADD"
PHP_REQUIRE_CXX()
PHP_ADD_LIBRARY(pthread)
PHP_ADD_LIBRARY(dl,,GRPC_SHARED_LIBADD)
PHP_ADD_LIBRARY(dl)

case $host in
*darwin*)
PHP_ADD_LIBRARY(c++,1,GRPC_SHARED_LIBADD)
;;
*)
PHP_ADD_LIBRARY(stdc++,1,GRPC_SHARED_LIBADD)
PHP_ADD_LIBRARY(rt,,GRPC_SHARED_LIBADD)
PHP_ADD_LIBRARY(rt)
;;
esac

PHP_SUBST(GRPC_SHARED_LIBADD)
PHP_NEW_EXTENSION(grpc,
## for src in php_config_m4.srcs
{{src}} \
## endfor
, $ext_shared, , -fvisibility=hidden \
-DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN \
-D_HAS_EXCEPTIONS=0 -DNOMINMAX -DGRPC_ARES=0 \
-DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1 \
-DGRPC_XDS_USER_AGENT_NAME_SUFFIX='"\"PHP\""' \
-DGRPC_XDS_USER_AGENT_VERSION_SUFFIX='"\"{{settings.version.php}}\""')
## for dir in php_config_m4.dirs
PHP_ADD_BUILD_DIR($ext_builddir/{{dir}})
## endfor
fi
78 changes: 0 additions & 78 deletions templates/config.m4.template

This file was deleted.

2 changes: 2 additions & 0 deletions tools/artifact_gen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.xml
*.json
92 changes: 92 additions & 0 deletions tools/artifact_gen/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Copyright 2025 The gRPC Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cc_library(
name = "extract_metadata_from_bazel_xml",
srcs = ["extract_metadata_from_bazel_xml.cc"],
hdrs = ["extract_metadata_from_bazel_xml.h"],
deps = [
"@abseil-cpp//absl/algorithm:container",
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/log",
"@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@nlohmann_json//:json",
"@pugixml",
],
)

cc_library(
name = "metadata_for_wrapped_languages",
srcs = ["metadata_for_wrapped_languages.cc"],
hdrs = ["metadata_for_wrapped_languages.h"],
deps = [
"utils",
"@abseil-cpp//absl/log",
"@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@nlohmann_json//:json",
],
)

cc_library(
name = "boringssl",
srcs = ["boringssl.cc"],
hdrs = ["boringssl.h"],
deps = [
"@abseil-cpp//absl/log",
"@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@nlohmann_json//:json",
],
)

cc_library(
name = "utils",
srcs = ["utils.cc"],
hdrs = ["utils.h"],
deps = [
"@abseil-cpp//absl/log",
"@nlohmann_json//:json",
"@yaml-cpp//:yaml-cpp",
],
)

cc_library(
name = "render",
srcs = ["render.cc"],
hdrs = ["render.h"],
deps = [
":utils",
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/log",
"@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@nlohmann_json//:json",
"@pantor_inja//:inja",
],
)

cc_binary(
name = "artifact_gen",
srcs = ["artifact_gen.cc"],
deps = [
":extract_metadata_from_bazel_xml",
":metadata_for_wrapped_languages",
":render",
":utils",
"@abseil-cpp//absl/flags:parse",
"@pantor_inja//:inja",
],
)
30 changes: 30 additions & 0 deletions tools/artifact_gen/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2025 The gRPC Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

bazel_dep(name = "pugixml", version = "1.15")
bazel_dep(name = "abseil-cpp", version = "20240722.0")
bazel_dep(name = "nlohmann_json", version = "3.11.3.bcr.1")
bazel_dep(name = "yaml-cpp", version = "0.8.0")

http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "pantor_inja",
build_file = "inja.BUILD",
integrity = "sha256-5ijZlHYtzaqal/Y6m4tz2a9Rrw/6Ws6mvbugrOr47iU=",
strip_prefix = "inja-3.3.0",
urls = [
"https://github.com/pantor/inja/archive/refs/tags/v3.3.0.tar.gz",
],
)
42 changes: 42 additions & 0 deletions tools/artifact_gen/artifact_gen.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2025 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <fstream>

#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "extract_metadata_from_bazel_xml.h"
#include "metadata_for_wrapped_languages.h"
#include "render.h"
#include "utils.h"

ABSL_FLAG(std::vector<std::string>, extra_build_yaml, {},
"Extra build.yaml files to merge");
ABSL_FLAG(bool, save_json, false, "Save the generated build.yaml to a file");

int main(int argc, char** argv) {
absl::ParseCommandLine(argc, argv);
auto build_yaml = ExtractMetadataFromBazelXml();
for (const auto& filename : absl::GetFlag(FLAGS_extra_build_yaml)) {
build_yaml.update(LoadYaml(filename), true);
}
// TODO(ctiller): all the special yaml updates
AddMetadataForWrappedLanguages(build_yaml);
if (absl::GetFlag(FLAGS_save_json)) {
std::ofstream ofs("build.json");
ofs << build_yaml.dump(4);
}
RenderAllTemplates(build_yaml);
return 0;
}
38 changes: 38 additions & 0 deletions tools/artifact_gen/artifact_gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
# Copyright 2025 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


set -e

# PHASE 0: query bazel for information we'll need
cd $(dirname $0)/../..
tools/bazel query --noimplicit_deps --output=xml 'deps(//test/...)' > tools/artifact_gen/test_deps.xml
tools/bazel query --noimplicit_deps --output=xml 'deps(//:all)' > tools/artifact_gen/root_all_deps.xml
tools/bazel query --noimplicit_deps --output=xml 'deps(//src/compiler/...)' > tools/artifact_gen/compiler_deps.xml
tools/bazel query --noimplicit_deps --output=xml 'kind(alias, "//third_party:*")' > tools/artifact_gen/third_party_alias_deps.xml
tools/bazel query --noimplicit_deps --output=xml 'deps(kind("^proto_library", @envoy_api//envoy/...))' > tools/artifact_gen/envoy_api_proto_deps.xml
tools/bazel query --noimplicit_deps --output=xml 'deps("@com_google_protobuf//upb:generated_code_support__only_for_generated_code_do_not_use__i_give_permission_to_break_me")' > tools/artifact_gen/upb_deps.xml
tools/bazel query --noimplicit_deps --output=xml 'kind(http_archive, //external:*)' > tools/artifact_gen/external_http_archive_deps.xml

# PHASE 1: generate artifacts
cd tools/artifact_gen
bazel build -c opt :artifact_gen
bazel-bin/artifact_gen \
--target_query=`pwd`/test_deps.xml,`pwd`/root_all_deps.xml,`pwd`/compiler_deps.xml,`pwd`/third_party_alias_deps.xml,`pwd`/envoy_api_proto_deps.xml,`pwd`/upb_deps.xml \
--external_http_archive_query=`pwd`/external_http_archive_deps.xml \
--extra_build_yaml=`pwd`/../../build_handwritten.yaml \
--templates_dir=`pwd`/../../templates \
--output_dir=`pwd`/../.. \
--save_json=true
Loading

0 comments on commit bd51f39

Please sign in to comment.