Skip to content

Commit 2beecad

Browse files
jmillikin-stripemattklein123
authored andcommitted
Lightstep build fixes from #envoy-dev. (#1872)
* Reorder cc_library includes so unsandboxed builds find correct headers. * Depend on `@local_config_cc//:toolchain` so MacOS builds with a compiler wrapper script can find that script. * Detect if $CC and $CXX are relative paths, and make them absolute before changing to the temporary build directory. Signed-off-by: John Millikin <jmillikin@stripe.com>
1 parent a5a3ea0 commit 2beecad

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

bazel/external/lightstep.BUILD

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ cc_library(
1212
":_prefix/include/lightstep_carrier.pb.h",
1313
],
1414
includes = [
15-
"_prefix/include",
15+
# Note: src/ is listed before _prefix to allow unsandboxed builds.
16+
#
17+
# Otherwise the compiler will locate included headers in `_prefix`
18+
# even though they're properly defined under `src/`, which breaks
19+
# strict include checking.
1620
"src/c++11",
21+
"_prefix/include",
1722
],
1823
visibility = ["//visibility:public"],
1924
deps = ["@protobuf_bzl//:protobuf"],
@@ -37,6 +42,7 @@ genrule(
3742
":lightstep_compiler_flags",
3843
":protobuf_deps",
3944
"@protobuf_bzl//:well_known_protos",
45+
"@local_config_cc//:toolchain",
4046
],
4147
outs = [
4248
"_prefix/lib/liblightstep_core_cxx11.a",

bazel/genrule_repository.bzl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ genrule_cc_deps = rule(
7474
implementation = _genrule_cc_deps,
7575
)
7676

77+
def _absolute_bin(path):
78+
# If the binary path looks like it's relative to the current directory,
79+
# transform it to be absolute by appending "${PWD}".
80+
if "/" in path and not path.startswith("/"):
81+
return '"${PWD}"/%r' % (path,)
82+
return '%r' % (path,)
83+
7784
def _genrule_environment(ctx):
7885
lines = []
7986

@@ -98,8 +105,8 @@ def _genrule_environment(ctx):
98105
lines.append("export CFLAGS=%r" % (" ".join(cc_flags),))
99106
lines.append("export LDFLAGS=%r" % (" ".join(ld_flags),))
100107
lines.append("export LIBS=%r" % (" ".join(ld_libs),))
101-
lines.append("export CC=%r" % (ctx.var['CC'],))
102-
lines.append("export CXX=%r" % (ctx.var['CC'],))
108+
lines.append("export CC=%s" % (_absolute_bin(ctx.var['CC']),))
109+
lines.append("export CXX=%s" % (_absolute_bin(ctx.var['CC']),))
103110

104111
# Some Autoconf helper binaries leak, which makes ./configure think the
105112
# system is unable to do anything. Turn off leak checking during part of

0 commit comments

Comments
 (0)