Skip to content

Commit

Permalink
bazel: branch cc_configure from bazel repo to support libstdc++/libgc…
Browse files Browse the repository at this point in the history
…c static linking.

We import cc_configure.bzl from https://github.com/bazelbuild/bazel at d6fec93 in this patch.
This allows us to workaround bazelbuild/bazel#2840 (see the header comment for further details).
  • Loading branch information
htuch committed Apr 18, 2017
1 parent 2f2aa37 commit a9f3a64
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
2 changes: 2 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
workspace(name = "envoy")

load("//bazel:repositories.bzl", "envoy_dependencies")
load("//bazel:cc_configure.bzl", "cc_configure")

envoy_dependencies()
cc_configure()
24 changes: 16 additions & 8 deletions bazel/cc_configure.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# This file was imported from https://github.com/bazelbuild/bazel at d6fec93. We apply a number of
# local modifications to deal with known issues in Bazel 0.4.5:
#
# * https://github.com/bazelbuild/bazel/issues/2840
# * (and potentially) https://github.com/bazelbuild/bazel/issues/2805
#
# Specifically, for #2840 we replace gcc with g++ invocations and remove the mandatory -lstdc++
# link. In the future, we can simplify our --build-id story resulting from #2805, but there's some
# additional work necessary to plumb in the actual git hash.

# Copyright 2016 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -232,7 +242,6 @@ def _crosstool_content(repository_ctx, cc, cpu_value, darwin):
"-std=c++0x",
] + _cplus_include_paths(repository_ctx),
"linker_flag": [
"-lstdc++",
"-lm", # Some systems expect -lm in addition to -lstdc++
# Anticipated future default.
] + (
Expand Down Expand Up @@ -328,9 +337,8 @@ def _get_windows_msys_crosstool_content(repository_ctx):
' tool_path { name: "compat-ld" path: "%susr/bin/ld" }\n' % msys_root +
' tool_path { name: "cpp" path: "%susr/bin/cpp" }\n' % msys_root +
' tool_path { name: "dwp" path: "%susr/bin/dwp" }\n' % msys_root +
' tool_path { name: "gcc" path: "%susr/bin/gcc" }\n' % msys_root +
' tool_path { name: "gcc" path: "%susr/bin/g++" }\n' % msys_root +
' cxx_flag: "-std=gnu++0x"\n' +
' linker_flag: "-lstdc++"\n' +
' cxx_builtin_include_directory: "%s"\n' % msys_root +
' cxx_builtin_include_directory: "/usr/"\n' +
' tool_path { name: "gcov" path: "%susr/bin/gcov" }\n' % msys_root +
Expand Down Expand Up @@ -387,18 +395,18 @@ def _get_system_root(repository_ctx):

def _find_cc(repository_ctx):
"""Find the C++ compiler."""
cc_name = "gcc"
if "CC" in repository_ctx.os.environ:
cc_name = repository_ctx.os.environ["CC"].strip()
cc_name = "g++"
if "CXX" in repository_ctx.os.environ:
cc_name = repository_ctx.os.environ["CXX"].strip()
if not cc_name:
cc_name = "gcc"
cc_name = "g++"
if cc_name.startswith("/"):
# Absolute path, maybe we should make this suported by our which function.
return cc_name
cc = repository_ctx.which(cc_name)
if cc == None:
fail(
"Cannot find gcc, either correct your path or set the CC" +
"Cannot find g++, either correct your path or set the CXX" +
" environment variable")
return cc

Expand Down
3 changes: 3 additions & 0 deletions ci/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
workspace(name = "ci")

load("//bazel:repositories.bzl", "envoy_dependencies")
load("//bazel:cc_configure.bzl", "cc_configure")

envoy_dependencies(
path = "//ci/prebuilt",
Expand All @@ -13,3 +14,5 @@ new_local_repository(
# We only want protobuf.bzl, so don't support building out of this repo.
build_file_content = "",
)

cc_configure()
3 changes: 3 additions & 0 deletions ci/WORKSPACE.consumer
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ local_repository(
)

load("//bazel:repositories.bzl", "envoy_dependencies")
load("//bazel:cc_configure.bzl", "cc_configure")

envoy_dependencies(path = "@envoy//ci/prebuilt")

cc_configure()
7 changes: 7 additions & 0 deletions test/exe/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package(default_visibility = ["//visibility:public"])

sh_test(
name = "envoy_static_test",
srcs = ["envoy_static_test.sh"],
data = ["//source/exe:envoy-static"],
)
8 changes: 8 additions & 0 deletions test/exe/envoy_static_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
#

set -e

# Validate we statically link libstdc++ and libgcc.
DYNDEPS=$(ldd source/exe/envoy-static | grep "libstdc++\|libgcc"; echo)
[[ -z "$DYNDEPS" ]] || (echo "libstdc++ or libgcc dynamically linked: ${DYNDEPS}"; exit 1)

0 comments on commit a9f3a64

Please sign in to comment.