Skip to content
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

bazel: branch cc_configure from bazel repo to support libstdc++/libgc… #782

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we need to make sure we set CXX now?

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)