No public description

PiperOrigin-RevId: 613626993
pull/36072/head
Esun Kim 9 months ago committed by Copybara-Service
parent 02276f4774
commit 7b98cda1f4
  1. 2331
      Makefile
  2. 1
      Rakefile
  3. 7
      build_handwritten.yaml
  4. 12
      grpc.gyp
  5. 11
      src/php/ext/grpc/config.m4
  6. 2
      src/ruby/ext/grpc/extconf.rb
  7. 25
      templates/CMakeLists.txt.template
  8. 197
      templates/Makefile.template
  9. 42
      tools/buildgen/_utils.py

2331
Makefile generated

File diff suppressed because it is too large Load Diff

@ -109,7 +109,6 @@ task 'dlls', [:plat] do |t, args|
env += 'SYSTEM=MINGW32 '
env += 'EMBED_ZLIB=true '
env += 'EMBED_OPENSSL=true '
env += 'EMBED_CARES=true '
env += 'BUILDDIR=/tmp '
env += "V=#{verbose} "
env += "GRPC_RUBY_BUILD_PROCS=#{nproc_override} "

@ -129,10 +129,6 @@ configs:
test_environ:
UBSAN_OPTIONS: halt_on_error=1:print_stacktrace=1:suppressions=test/core/util/ubsan_suppressions.txt
defaults:
abseil:
CPPFLAGS: -g -Ithird_party/abseil-cpp
benchmark:
CPPFLAGS: -Ithird_party/benchmark/include -DHAVE_POSIX_REGEX
boringssl:
CFLAGS: -g
CPPFLAGS: -Ithird_party/boringssl-with-bazel/src/include -fvisibility=hidden -DOPENSSL_NO_ASM
@ -150,7 +146,8 @@ defaults:
COREFLAGS: -fno-exceptions
CPPFLAGS: -g -Wall -Wextra -DOSATOMIC_USE_INLINED=1 -Ithird_party/abseil-cpp -Ithird_party/re2
-Ithird_party/upb -Isrc/core/ext/upb-gen -Isrc/core/ext/upbdefs-gen -Ithird_party/utf8_range
-Ithird_party/xxhash
-Ithird_party/xxhash -Ithird_party/cares/cares/include -Ithird_party/cares -Ithird_party/cares/cares
-Ithird_party/address_sorting/include
LDFLAGS: -g
zlib:
CFLAGS: -fvisibility=hidden

12
grpc.gyp generated

@ -62,6 +62,10 @@
'-Isrc/core/ext/upbdefs-gen',
'-Ithird_party/utf8_range',
'-Ithird_party/xxhash',
'-Ithird_party/cares/cares/include',
'-Ithird_party/cares',
'-Ithird_party/cares/cares',
'-Ithird_party/address_sorting/include',
],
'ldflags': [
'-g',
@ -143,6 +147,10 @@
'-Isrc/core/ext/upbdefs-gen',
'-Ithird_party/utf8_range',
'-Ithird_party/xxhash',
'-Ithird_party/cares/cares/include',
'-Ithird_party/cares',
'-Ithird_party/cares/cares',
'-Ithird_party/address_sorting/include',
],
'OTHER_CPLUSPLUSFLAGS': [
'-g',
@ -156,6 +164,10 @@
'-Isrc/core/ext/upbdefs-gen',
'-Ithird_party/utf8_range',
'-Ithird_party/xxhash',
'-Ithird_party/cares/cares/include',
'-Ithird_party/cares',
'-Ithird_party/cares/cares',
'-Ithird_party/address_sorting/include',
'-stdlib=libc++',
'-std=c++14',
'-Wno-error=deprecated-declarations',

@ -60,17 +60,6 @@ if test "$PHP_GRPC" != "no"; then
PHP_ADD_LIBPATH($GRPC_LIBDIR)
PHP_CHECK_LIBRARY(gpr,gpr_now,
[
PHP_ADD_LIBRARY(gpr,,GRPC_SHARED_LIBADD)
PHP_ADD_LIBRARY(gpr)
AC_DEFINE(HAVE_GPRLIB,1,[ ])
],[
AC_MSG_ERROR([wrong gpr lib version or lib not found])
],[
-L$GRPC_LIBDIR
])
PHP_CHECK_LIBRARY(grpc,grpc_channel_destroy,
[
PHP_ADD_LIBRARY(grpc,,GRPC_SHARED_LIBADD)

@ -100,8 +100,6 @@ ENV['EMBED_OPENSSL'] = (RUBY_ENGINE != 'truffleruby').to_s
# Don't embed on TruffleRuby (the system zlib is already linked for the zlib C extension, slow build times)
ENV['EMBED_ZLIB'] = (RUBY_ENGINE != 'truffleruby').to_s
ENV['EMBED_CARES'] = 'true'
ENV['ARCH_FLAGS'] = RbConfig::CONFIG['ARCH_FLAG']
if apple_toolchain && !cross_compiling
if RUBY_PLATFORM =~ /arm64/

@ -197,19 +197,6 @@
deps.append(d)
return deps
def get_all_deps(target_dict, all_libs):
ret = set()
get_all_deps_recurse(target_dict, all_libs, ret)
return ret
def get_all_deps_recurse(target_dict, all_libs, all_deps):
for d in target_dict.get('deps', []):
if not d in all_deps:
all_deps.add(d)
for other_lib in all_libs:
if other_lib.name == d:
get_all_deps_recurse(other_lib, all_libs, all_deps)
def is_generate_cmake_target(lib_or_target):
"""Returns True if a cmake target should be generated for given library/target."""
# TODO(jtattermusch): extract the metadata to a centralized location.
@ -844,11 +831,11 @@
dll_annotations.append("GRPC_DLL_EXPORTS")
if lib.name in grpcxx_libs:
dll_annotations.append("GRPCXX_DLL_EXPORTS")
if set(gpr_libs) & set(get_all_deps(lib, libs)):
if set(gpr_libs) & set(lib.transitive_deps):
dll_annotations.append("GPR_DLL_IMPORTS")
if set(grpc_libs) & set(get_all_deps(lib, libs)):
if set(grpc_libs) & set(lib.transitive_deps):
dll_annotations.append("GRPC_DLL_IMPORTS")
if set(grpcxx_libs) & set(get_all_deps(lib, libs)):
if set(grpcxx_libs) & set(lib.transitive_deps):
dll_annotations.append("GRPCXX_DLL_IMPORTS")
%>
% if dll_annotations:
@ -945,11 +932,11 @@
% endfor
)<%
dll_annotations = []
if set(gpr_libs) & set(get_all_deps(tgt, libs)):
if set(gpr_libs) & set(tgt.transitive_deps):
dll_annotations.append("GPR_DLL_IMPORTS")
if set(grpc_libs) & set(get_all_deps(tgt, libs)):
if set(grpc_libs) & set(tgt.transitive_deps):
dll_annotations.append("GRPC_DLL_IMPORTS")
if set(grpcxx_libs) & set(get_all_deps(tgt, libs)):
if set(grpcxx_libs) & set(tgt.transitive_deps):
dll_annotations.append("GRPCXX_DLL_IMPORTS")
%>
% if dll_annotations:

@ -24,31 +24,11 @@
import re
import os
def is_absl_lib(target_name):
"""Returns True if the target name is one of the abseil libraries."""
return target_name.startswith("absl/")
def collapse_absl_deps(deps):
"""Replace first occurrence of absl dependency with grpc_abseil and remove the remaining absl dependencies."""
result = []
absl_dep_added = False
for dep in deps:
if is_absl_lib(dep):
if not absl_dep_added:
result.append('grpc_abseil')
absl_dep_added = True
else:
result.append(dep)
return result
def get_dep_expression(dep):
"""For given dependency, return the expression to be used in Makefile rule dependencies."""
if dep == 'z':
return "$(ZLIB_DEP)"
elif dep == 'grpc_abseil':
return "$(GRPC_ABSEIL_DEP)"
elif dep == 'libssl':
return "$(OPENSSL_DEP)"
else:
@ -59,8 +39,6 @@
"""For given dependency, return the lib archive expression to be used when linking."""
if dep == 'z':
return "$(ZLIB_MERGE_LIBS)"
elif dep == 'grpc_abseil':
return "$(GRPC_ABSEIL_MERGE_LIBS)"
elif dep == 'libssl':
return "$(OPENSSL_MERGE_LIBS)"
else:
@ -71,8 +49,6 @@
"""For given dependency, return the expression with variable that has list of all object files."""
if dep == 'z':
return "$(ZLIB_MERGE_OBJS)"
elif dep == 'grpc_abseil':
return "$(LIBGRPC_ABSEIL_OBJS)"
elif dep == 'libssl':
return "$(OPENSSL_MERGE_OBJS)"
else:
@ -83,8 +59,7 @@
"""Generate make rule dependency list for given library, when building as static."""
make_rule_deps = []
collapsed_deps = collapse_absl_deps(lib.get('transitive_deps', []))
collapsed_deps = lib.get('transitive_deps', [])
# depend on static libraries
for dep in collapsed_deps:
@ -103,7 +78,7 @@
def get_merge_objs_for_deps(lib):
"""Get list of merge objs for all deps of a given library."""
result = []
collapsed_deps = collapse_absl_deps(lib.get('transitive_deps', []))
collapsed_deps = lib.get('transitive_deps', [])
for dep in collapsed_deps:
result.append(get_objs_expression(dep))
@ -115,7 +90,7 @@
"""Generate make rule dependency list given library, when built as shared."""
make_rule_deps = []
collapsed_deps = collapse_absl_deps(lib.get('transitive_deps', []))
collapsed_deps = lib.get('transitive_deps', [])
# depend of obj files of this library itself
make_rule_deps.append(get_objs_expression(lib.name))
@ -131,7 +106,7 @@
"""Generate list of libraries to link given library, when built as shared."""
result = []
collapsed_deps = collapse_absl_deps(lib.get('transitive_deps', []))
collapsed_deps = lib.get('transitive_deps', [])
# depend of obj files of this library itself
result.append(get_objs_expression(lib.name))
@ -148,37 +123,31 @@
return " ".join(result)
sources_that_need_openssl = set()
sources_that_don_t_need_openssl = set()
# warnings we'd like, but that don't exist in all compilers
PREFERRED_WARNINGS=['extra-semi']
CHECK_WARNINGS=PREFERRED_WARNINGS + ['no-shift-negative-value', 'no-unused-but-set-variable', 'no-maybe-uninitialized', 'no-unknown-warning-option']
def warning_var(fmt, warning):
return fmt % warning.replace('-', '_').replace('+', 'X').upper()
def neg_warning(warning):
if warning[0:3] == 'no-':
return warning[3:]
else:
return 'no-' + warning
lang_to_var = {
'c': 'CORE',
'c++': 'CPP',
}
%>
<%
lib_maps = {lib.name: lib for lib in libs}
sys_libs = ['boringssl', 'cares', 'libssl', 'z']
# Build a new gRPC target which embeds sources of all dependencies except system libraries such as libz
grpc_lib = lib_maps.get('grpc', None)
for dep in set(grpc_lib.transitive_deps) - set(sys_libs):
dep_lib = lib_maps.get(dep, None)
if dep_lib:
grpc_lib.src += dep_lib.src
grpc_lib.headers += dep_lib.headers
grpc_lib.src = list(sorted(set(grpc_lib.src)))
grpc_lib.headers = list(sorted(set(grpc_lib.headers)))
grpc_lib.deps = list(sorted(list(set(grpc_lib.deps) & set(sys_libs))))
grpc_lib.transitive_deps = list(sorted(list(set(grpc_lib.transitive_deps) & set(sys_libs))))
# Makefile is only intended for internal needs (building distribution artifacts etc.)
# so we can restrict the number of libraries/targets that are buildable using the Makefile.
# Other targets can be built with cmake or bazel.
# TODO(jtattermusch): Figure out how to avoid the need to list the dependencies explicitly.
# Currently it is necessary because some dependencies are marked as "build: private" in build.yaml
# (which itself is correct, as they are not "public" libraries from our perspective and cmake
# needs to have them marked as such)
filtered_libs = [lib for lib in libs if (lib.build in ['all'] and lib.language != 'c++') or lib.name in ['cares', 'boringssl', 'z']]
filtered_targets = [tgt for tgt in targets if tgt.build in ['all'] and lib.language != 'c++']
filtered_libs = [grpc_lib, ] + [lib_maps[lib] for lib in sys_libs if lib != 'libssl']
%>
comma := ,
@ -317,27 +286,6 @@
$(error Invalid CONFIG value '$(CONFIG)')
endif
ifeq ($(SYSTEM),Linux)
TMPOUT = /dev/null
else
TMPOUT = `mktemp /tmp/test-out-XXXXXX`
endif
CHECK_NO_CXX14_COMPAT_WORKS_CMD = $(CC) -std=c++14 -Werror -Wno-c++14-compat -o $(TMPOUT) -c test/build/no-c++14-compat.cc
HAS_WORKING_NO_CXX14_COMPAT = $(shell $(CHECK_NO_CXX14_COMPAT_WORKS_CMD) 2> /dev/null && echo true || echo false)
ifeq ($(HAS_WORKING_NO_CXX14_COMPAT),true)
W_NO_CXX14_COMPAT=-Wno-c++14-compat
endif
%for warning in CHECK_WARNINGS:
${warning_var('CHECK_%s_WORKS_CMD', warning)} = $(CC) -std=c99 -Werror -W${warning} -o $(TMPOUT) -c test/build/${warning}.c
${warning_var('HAS_WORKING_%s', warning)} = $(shell $(${warning_var('CHECK_%s_WORKS_CMD', warning)}) 2> /dev/null && echo true || echo false)
ifeq ($(${warning_var('HAS_WORKING_%s', warning)}),true)
${warning_var('W_%s', warning)}=-W${warning}
${warning_var('NO_W_%s', warning)}=-W${neg_warning(warning)}
endif
%endfor
# The HOST compiler settings are used to compile the protoc plugins.
# In most cases, you won't have to change anything, but if you are
# cross-compiling, you can override these variables from GNU make's
@ -348,7 +296,7 @@
HOST_LD ?= $(LD)
HOST_LDXX ?= $(LDXX)
CFLAGS += -std=c11 ${' '.join(warning_var('$(W_%s)', warning) for warning in PREFERRED_WARNINGS)}
CFLAGS += -std=c11
CXXFLAGS += -std=c++14
ifeq ($(SYSTEM),Darwin)
CXXFLAGS += -stdlib=libc++
@ -519,36 +467,6 @@
LIBS += z
endif
# Setup c-ares dependency
ifeq ($(wildcard third_party/cares/cares/include/ares.h),)
HAS_EMBEDDED_CARES = false
else
HAS_EMBEDDED_CARES = true
endif
ifeq ($(HAS_EMBEDDED_CARES),true)
EMBED_CARES ?= true
else
# only building with c-ares from submodule is supported
DEP_MISSING += cares
EMBED_CARES ?= broken
endif
ifeq ($(EMBED_CARES),true)
CPPFLAGS := -Ithird_party/cares/cares/include -Ithird_party/cares -Ithird_party/cares/cares $(CPPFLAGS)
endif
# Setup address_sorting dependency
# TODO(jtattermusch): should the include be added elsewhere?
CPPFLAGS := -Ithird_party/address_sorting/include $(CPPFLAGS)
# Setup abseil dependency
GRPC_ABSEIL_DEP = $(LIBDIR)/$(CONFIG)/libgrpc_abseil.a
GRPC_ABSEIL_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libgrpc_abseil.a
# Setup boringssl dependency
ifeq ($(wildcard third_party/boringssl-with-bazel/src/include/openssl/ssl.h),)
@ -583,15 +501,8 @@
NO_DEPS = true
endif
.SECONDARY = %.pb.h %.pb.cc
ifeq ($(DEP_MISSING),)
all: static shared\
% for tgt in filtered_targets:
% if tgt.build == 'all':
$(BINDIR)/$(CONFIG)/${tgt.name}\
% endif
% endfor
all: static shared
dep_error:
@echo "You shouldn't see this message - all of your dependencies are correct."
@ -665,10 +576,6 @@
stop:
@false
% for tgt in filtered_targets:
${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name}
% endfor
run_dep_checks:
@echo "run_dep_checks target has been deprecated."
@ -839,11 +746,6 @@
$(Q) mkdir -p `dirname $@`
$(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
$(OBJDIR)/$(CONFIG)/test/core/%.o : test/core/%.cc
$(E) "[CXX] Compiling $<"
$(Q) mkdir -p `dirname $@`
$(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $<
$(OBJDIR)/$(CONFIG)/%.o : %.cc
$(E) "[CXX] Compiling $<"
$(Q) mkdir -p `dirname $@`
@ -877,41 +779,13 @@
% endif
% endfor
# Add private ABSEIL target which contains all sources used by all baselib libraries.
<%
# Collect all abseil source and header files used by gpr, grpc, so on.
used_abseil_rules = set()
for lib in libs:
if lib.get("baselib"):
for dep in lib.transitive_deps:
if is_absl_lib(dep):
used_abseil_rules.add(dep)
used_abseil_srcs = []
used_abseil_hdrs = []
for lib in libs:
if lib.name in used_abseil_rules:
used_abseil_srcs.extend(lib.get("src", []))
used_abseil_hdrs.extend(lib.get("hdr", []))
# Create `grpc_abseil` rule with collected files.
lib_type = type(libs[0])
grpc_abseil_lib = lib_type({
"name": "grpc_abseil",
"build": "private",
"language": "c",
"defaults": "abseil",
"src": sorted(used_abseil_srcs),
"hdr": sorted(used_abseil_hdrs),
})
%>
${makelib(grpc_abseil_lib)}
<%def name="makelib(lib)">
# start of build recipe for library "${lib.name}" (generated by makelib(lib) template function)
# deps: ${collapse_absl_deps(lib.get('deps', []))}
# transitive_deps: ${collapse_absl_deps(lib.get('transitive_deps', []))}
# deps: ${lib.get('deps', [])}
# transitive_deps: ${lib.get('transitive_deps', [])}
LIB${lib.name.upper()}_SRC = \\
% for src in lib.src:
% for src in sorted(lib.src):
${src} \\
% endfor
@ -924,7 +798,7 @@
PUBLIC_HEADERS_C += \\
% endif
% for hdr in lib.public_headers:
% for hdr in sorted(lib.public_headers):
${hdr} \\
% endfor
@ -972,13 +846,6 @@
ldflags = '$(LDFLAGS)'
if lib.get('LDFLAGS', None):
ldflags += ' ' + lib['LDFLAGS']
if 'libssl' in lib.get('transitive_deps', []):
for src in lib.src:
sources_that_need_openssl.add(src)
else:
for src in lib.src:
sources_that_don_t_need_openssl.add(src)
%>
# shared library for "${lib.name}"
% if lib.build == "all":
@ -1019,18 +886,6 @@
# end of build recipe for library "${lib.name}"
</%def>
# TODO(jtattermusch): is there a way to get around this hack?
ifneq ($(OPENSSL_DEP),)
# This is to ensure the embedded OpenSSL is built beforehand, properly
# installing headers to their final destination on the drive. We need this
# otherwise parallel compilation will fail if a source is compiled first.
% for src in sorted(sources_that_need_openssl):
% if src not in sources_that_don_t_need_openssl:
${src}: $(OPENSSL_DEP)
% endif
% endfor
endif
.PHONY: all strip tools \
dep_error openssl_dep_error openssl_dep_message git_update stop \
buildtests buildtests_c buildtests_cxx \

@ -34,9 +34,45 @@ def import_python_module(path: str) -> types.ModuleType:
class Bunch(dict):
"""Allows dot-accessible dictionaries."""
def __init__(self, d: Mapping):
dict.__init__(self, d)
self.__dict__.update(d)
def __contains__(self, k):
try:
return dict.__contains__(self, k) or hasattr(self, k)
except:
return False
def __getattr__(self, k):
try:
# Throws exception if not in prototype chain
return object.__getattribute__(self, k)
except AttributeError:
try:
return self[k]
except KeyError:
raise AttributeError(k)
def __setattr__(self, k, v):
try:
# Throws exception if not in prototype chain
object.__getattribute__(self, k)
except AttributeError:
try:
self[k] = v
except:
raise AttributeError(k)
else:
object.__setattr__(self, k, v)
def __delattr__(self, k):
try:
# Throws exception if not in prototype chain
object.__getattribute__(self, k)
except AttributeError:
try:
del self[k]
except KeyError:
raise AttributeError(k)
else:
object.__delattr__(self, k)
def to_bunch(var: Any) -> Any:

Loading…
Cancel
Save