-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Replace Bazel's custom unix_cc_configure with a wrapper script. #2631
Conversation
cc @snowp because I think this will unblock your rules_go upgrade, @htuch because you'll be excited to see the crosstool patches go away, and @mattklein123 because I know how much you love Bazel. |
bazel/cc_wrapper.py
Outdated
envoy_real_cc = {ENVOY_REAL_CC} | ||
envoy_real_cxx = {ENVOY_REAL_CXX} | ||
compiler = envoy_real_cc | ||
if envoy_real_cxx is not None and "-static-libstdc++" in sys.argv[1:]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this play with libc++
requirements that exist for OSS-Fuzz?
This seems reasonable to me (still hacky, but I prefer hacky that works over hacky that doesn't) and should solve the rules_go issue as well as the general problem of building C files (#839) |
6e79f45
to
da4b0b7
Compare
asan/tsan is stuck on a clang/bazel interaction. Will look at it more on the weekend or holiday. Notes:
OK, so the clang include path is having a symlink party. Bazel is expecting Ran
Bazel is running
|
The script checks for `--static-libstdc++` in argv, and if found (1) switches to the `$CXX` compiler and (2) drops `-lstdc++` from argv. This should let the main Envoy binary build normally, without interfering with other build systems that treat C and C++ as different languages. Signed-off-by: John Millikin <jmillikin@stripe.com>
da4b0b7
to
8ea835f
Compare
And we're green! Based on the time to run tests, wrapping the compiler like this invalidates the build cache. We'll want to do a new build image after merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new approach is neat,I like it, it will be much more robust to Bazel version churn, in addition to the rules_go
stuff.
bazel/cc_configure.bzl
Outdated
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Rules for configuring the C++ toolchain (experimental).""" | ||
def _quiet_fake_which(program): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add comments here and below providing details on why we're faking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
bazel/cc_configure.bzl
Outdated
os = fake_os, | ||
), {}) | ||
repository_ctx.template("envoy_cc_wrapper", repository_ctx.attr._envoy_cc_wrapper, { | ||
"{ENVOY_REAL_CC}": repr(str(real_cc)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, definitely could do with a narrative explaining what's happening here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
bazel/cc_configure.bzl
Outdated
configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools) | ||
overriden_tools = {} | ||
if cpu_value not in ["freebsd", "x64_windows", "darwin"]: | ||
overriden_tools["gcc"] = _build_envoy_cc_wrapper(repository_ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is gcc hardcoded here? Is this generic $CC effectively? If so, why not on Darwin as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment. To Bazel, all CCs are GCC.
bazel/cc_wrapper.py
Outdated
compiler = envoy_real_cxx | ||
argv = [] | ||
for arg in sys.argv[1:]: | ||
if arg == "-lstdc++": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to ensure that this is going to work with Envoy OSS-Fuzz that uses libc++
, seehttps://github.com/google/oss-fuzz/tree/master/projects/envoy.
Can you checkout OSS-Fuzz (https://github.com/google/oss-fuzz) and run:
python infra/helper.py build_image envoy
python infra/helper.py build_fuzzers --sanitizer=address envoy <path to your Envoy source tree>
python infra/helper.py run_fuzzer envoy base64_fuzz_test
See https://github.com/google/oss-fuzz/blob/master/docs/new_project_guide.md#testing-locally for the official docs on this flow if you have issues, or reach out to me on Slack.
I think we should eventually put this in a CI slot to ensure we don't regress as we much with build, but for now we need to manually do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running now. I've only got a laptop to build with so it's taking a pretty good amount of time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oss-fuzz works with the new script, but we need to add python
to the Debian package lits in oss-fuzz/projects/envoy/Dockerfile
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correction: I ran the oss-fuzz script correctly this time (on my branch instead of envoy upstream) and it failed with some C++ stdlib linker problem. I think a -lstdc++
was getting through the wrapper somehow. Rebuilding now to see if more filtering fixed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified it works once we add -stdlib=libc++
to the list of flags that need -lstdc++
to be pruned first.
bazel/cc_wrapper.py
Outdated
argv.append(arg) | ||
else: | ||
argv = sys.argv[1:] | ||
os.execv(compiler, [compiler] + argv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty cool approach actually. It seems this gives us a lot of freedom to fix Bazel issues that aren't addressed upstream via the wrapper. Neat.
bazel/cc_wrapper.py
Outdated
# interchangeable, but `gcc` will ignore the `-static-libstdc++` flag. | ||
# This check lets Envoy statically link against libstdc++ to be more | ||
# portable between intalled glibc versions. | ||
if "-static-libstdc++" in sys.argv[1:]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you verified with ldd
that we're still getting the desired static/dynamic link mix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, libstdc++.so
doesn't show up in the output of ldd bazel-bin/source/exe/envoy
when using this wrapper.
Signed-off-by: John Millikin <jmillikin@stripe.com>
…_deps` Signed-off-by: John Millikin <jmillikin@stripe.com>
Signed-off-by: John Millikin <jmillikin@stripe.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rad, thanks for verifying sanity.
bazel/cc_wrapper.py
Outdated
# `g++` and `gcc -lstdc++` have similar behavior and Bazel treats them as | ||
# interchangeable, but `gcc` will ignore the `-static-libstdc++` flag. | ||
# This check lets Envoy statically link against libstdc++ to be more | ||
# portable between intalled glibc versions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: s/intalled/installed/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
bazel/cc_wrapper.py
Outdated
# unless the user has explicitly set environment variables | ||
# before starting Bazel. But here in $PWD is the Bazel sandbox, | ||
# which will be deleted automatically after the compiler exits. | ||
(flagfile_fd, flagfile_path) = tempfile.mkstemp(dir='./', suffix=".linker-params") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use a context manager here, i.e. with
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
bazel/cc_wrapper.py
Outdated
envoy_real_cxx = {ENVOY_REAL_CXX} | ||
|
||
def sanitize_flagfile(in_path, out_fd): | ||
with open(in_path, "rb") as in_fp: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 space indent, standard Google style for Python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with yapf -i --style '{based_on_style: google, indent_width: 2}' cc_wrapper.py
Signed-off-by: John Millikin <jmillikin@stripe.com>
# unless the user has explicitly set environment variables | ||
# before starting Bazel. But here in $PWD is the Bazel sandbox, | ||
# which will be deleted automatically after the compiler exits. | ||
(flagfile_fd, flagfile_path) = tempfile.mkstemp( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sigh, hopefully abseil-py (nee pyglib) gets a proper context manager wrapped mktemp someday.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is an impressive cleanup.
…yproxy#2631) The script checks for `--static-libstdc++` in argv, and if found (1) switches to the `$CXX` compiler and (2) drops `-lstdc++` from argv. This should let the main Envoy binary build normally, without interfering with other build systems that treat C and C++ as different languages. Signed-off-by: John Millikin <jmillikin@stripe.com>
…yproxy#2631) The script checks for `--static-libstdc++` in argv, and if found (1) switches to the `$CXX` compiler and (2) drops `-lstdc++` from argv. This should let the main Envoy binary build normally, without interfering with other build systems that treat C and C++ as different languages. Signed-off-by: John Millikin <jmillikin@stripe.com>
…yproxy#2631) The script checks for `--static-libstdc++` in argv, and if found (1) switches to the `$CXX` compiler and (2) drops `-lstdc++` from argv. This should let the main Envoy binary build normally, without interfering with other build systems that treat C and C++ as different languages. Signed-off-by: John Millikin <jmillikin@stripe.com>
* Merge envoy-wasm for v1.13.0. Signed-off-by: John Plevyak <jplevyak@gmail.com> * Update .wasm files. Signed-off-by: John Plevyak <jplevyak@gmail.com> * WASM SDK v2 -> v3. Signed-off-by: John Plevyak <jplevyak@gmail.com> * Address comments. Signed-off-by: John Plevyak <jplevyak@gmail.com> * Bump bazelversion. Signed-off-by: John Plevyak <jplevyak@gmail.com>
Description:
The script checks for
--static-libstdc++
in argv, and if found(1) switches to the
$CXX
compiler and (2) drops-lstdc++
from argv.This should let the main Envoy binary build normally, without
interfering with other build systems that treat C and C++ as different
languages.
Risk Level: Medium
Testing:
I tested this Works On My Machine but will rely on CI to verify it works on the more exotic build configurations.
Signed-off-by: John Millikin jmillikin@stripe.com