-
Notifications
You must be signed in to change notification settings - Fork 5.5k
build: simplify cc_configure and static link for libc++ #7329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
56d5bd0
76bbfa9
f4c1fc2
9f0eec5
900b808
dae720b
e19c3f6
30a0b42
fac1815
2675933
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,57 +2,8 @@ load("@bazel_tools//tools/cpp:cc_configure.bzl", _upstream_cc_autoconf_impl = "c | |
| load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value") | ||
| load("@bazel_tools//tools/cpp:unix_cc_configure.bzl", "find_cc") | ||
|
|
||
| # Stub for `repository_ctx.which()` that always succeeds. See comments in | ||
| # `_find_cxx` for details. | ||
| def _quiet_fake_which(program): | ||
| return struct(_envoy_fake_which = program) | ||
|
|
||
| # Stub for `repository_ctx.which()` that always fails. See comments in | ||
| # `_find_cxx` for details. | ||
| def _noisy_fake_which(program): | ||
| return None | ||
|
|
||
| # Find a good path for the C++ compiler, by hooking into Bazel's C compiler | ||
| # detection. Uses `$CXX` if found, otherwise defaults to `g++` because Bazel | ||
| # defaults to `gcc`. | ||
| def _find_cxx(repository_ctx): | ||
| # Bazel's `find_cc` helper uses the repository context to inspect `$CC`. | ||
| # Replace this value with `$CXX` if set. | ||
| environ_cxx = repository_ctx.os.environ.get("CXX", "g++") | ||
| fake_os = struct( | ||
| environ = {"CC": environ_cxx}, | ||
| ) | ||
|
|
||
| # We can't directly assign `repository_ctx.which` to a struct attribute | ||
| # because Skylark doesn't support bound method references. Instead, stub | ||
| # out `which()` using a two-pass approach: | ||
| # | ||
| # * The first pass uses a stub that always succeeds, passing back a special | ||
| # value containing the original parameter. | ||
| # * If we detect the special value, we know that `find_cc` found a compiler | ||
| # name but don't know if that name could be resolved to an executable path. | ||
| # So do the `which()` call ourselves. | ||
| # * If our `which()` failed, call `find_cc` again with a dummy which that | ||
| # always fails. The error raised by `find_cc` will be identical to what Bazel | ||
| # would generate for a missing C compiler. | ||
| # | ||
| # See https://github.com/bazelbuild/bazel/issues/4644 for more context. | ||
| real_cxx = find_cc(struct( | ||
| which = _quiet_fake_which, | ||
| os = fake_os, | ||
| ), {}) | ||
| if hasattr(real_cxx, "_envoy_fake_which"): | ||
| real_cxx = repository_ctx.which(real_cxx._envoy_fake_which) | ||
| if real_cxx == None: | ||
| find_cc(struct( | ||
| which = _noisy_fake_which, | ||
| os = fake_os, | ||
| ), {}) | ||
| return real_cxx | ||
|
|
||
| def _build_envoy_cc_wrapper(repository_ctx): | ||
| real_cc = find_cc(repository_ctx, {}) | ||
| real_cxx = _find_cxx(repository_ctx) | ||
|
|
||
| # Copy our CC wrapper script into @local_config_cc, with the true paths | ||
| # to the C and C++ compiler injected in. The wrapper will use these paths | ||
|
|
@@ -64,7 +15,6 @@ def _build_envoy_cc_wrapper(repository_ctx): | |
| repository_ctx.template("extra_tools/envoy_cc_wrapper", repository_ctx.attr._envoy_cc_wrapper, { | ||
| "{ENVOY_REAL_CC}": repr(str(real_cc)), | ||
| "{ENVOY_CFLAGS}": repr(str(repository_ctx.os.environ.get("CFLAGS", ""))), | ||
| "{ENVOY_REAL_CXX}": repr(str(real_cxx)), | ||
| "{ENVOY_CXXFLAGS}": repr(str(repository_ctx.os.environ.get("CXXFLAGS", ""))), | ||
| }) | ||
| return repository_ctx.path("extra_tools/envoy_cc_wrapper") | ||
|
|
@@ -93,6 +43,7 @@ cc_autoconf = repository_rule( | |
| "ABI_VERSION", | ||
| "BAZEL_COMPILER", | ||
| "BAZEL_HOST_SYSTEM", | ||
| "BAZEL_CXXOPTS", | ||
|
lizan marked this conversation as resolved.
|
||
| "BAZEL_LINKOPTS", | ||
| "BAZEL_PYTHON", | ||
| "BAZEL_SH", | ||
|
|
@@ -108,7 +59,6 @@ cc_autoconf = repository_rule( | |
| "USE_CLANG_CL", | ||
| "CC", | ||
| "CFLAGS", | ||
| "CXX", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When building with GCC, does the final link happen with
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "CXXFLAGS", | ||
| "CC_CONFIGURE_DEBUG", | ||
| "CC_TOOLCHAIN_NAME", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,6 +125,7 @@ envoy_cmake_external( | |
| "ENABLE_LIB_ONLY": "on", | ||
| "CMAKE_BUILD_TYPE": "RelWithDebInfo", | ||
| "CMAKE_INSTALL_LIBDIR": "lib", | ||
| "CMAKE_CXX_COMPILER_FORCED": "on", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we set
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't add it because it wasn't needed, but fine to add as well. no strong opinion on this. |
||
| # Disable ranlib because it is not handled by bazel, and therefore | ||
| # doesn't respect custom toolchains such as the Android NDK, | ||
| # see https://github.com/bazelbuild/rules_foreign_cc/issues/252 | ||
|
|
@@ -147,6 +148,7 @@ envoy_cmake_external( | |
| "YAML_CPP_BUILD_TESTS": "off", | ||
| "YAML_CPP_BUILD_TOOLS": "off", | ||
| "CMAKE_BUILD_TYPE": "RelWithDebInfo", | ||
| "CMAKE_CXX_COMPILER_FORCED": "on", | ||
| # Disable ranlib because it is not handled by bazel, and therefore | ||
| # doesn't respect custom toolchains such as the Android NDK, | ||
| # see https://github.com/bazelbuild/rules_foreign_cc/issues/252 | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.