Skip to content

Commit 4fd925d

Browse files
committed
Add Crosstool from https://github.com/korfuri/bazel-travis to try and
fix ridiculous bazel issues
1 parent e2f9fbc commit 4fd925d

3 files changed

Lines changed: 192 additions & 2 deletions

File tree

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ before_install:
4141
- $CXX --version
4242
- export CXXFLAGS="-std=c++0x -stdlib=libc++"
4343

44-
- #https://github.com/bazelbuild/bazel/issues/649, https://github.com/tensorflow/tensorflow/issues/336 FML
45-
- sudo mv $(which $CXX) /usr/bin/gcc
4644

4745
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
4846
- echo "startup --host_jvm_args=-Xmx2500m" >> .bazelrc
4947
- echo "startup --host_jvm_args=-Xms2500m" >> .bazelrc
5048
- echo "test --ram_utilization_factor=10" >> .bazelrc
5149
- echo "startup --batch" >> .bazelrc
5250
- echo "build --spawn_strategy=standalone --genrule_strategy=standalone" >> .bazelrc
51+
# Bazel hardcodes /usr/bin/gcc by default :s
52+
# https://github.com/bazelbuild/bazel/issues/649, https://github.com/tensorflow/tensorflow/issues/336 FML
53+
- echo "build --crosstool_top //tools/custom_crosstool:CROSSTOOL" >> .bazelrc
5354
- export BAZELRC="$(pwd)/.bazelrc"
5455

5556
# BAZEL

tools/custom_crosstool/BUILD

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
filegroup(
4+
name = "empty",
5+
srcs = [],
6+
)
7+
8+
# This is the entry point for --crosstool_top. Toolchains are found
9+
# by lopping off the name of --crosstool_top and searching for
10+
# "cc-compiler-${CPU}" in this BUILD file, where CPU is the target CPU
11+
# specified in --cpu.
12+
#
13+
# This file group should include
14+
# * all cc_toolchain targets supported
15+
# * all file groups that said cc_toolchain might refer to,
16+
# including the default_grte_top setting in the CROSSTOOL
17+
# protobuf.
18+
filegroup(
19+
name = "toolchain",
20+
srcs = [
21+
":cc-compiler-local",
22+
":empty",
23+
],
24+
)
25+
26+
cc_toolchain(
27+
name = "cc-compiler-local",
28+
all_files = ":empty",
29+
compiler_files = ":empty",
30+
cpu = "local",
31+
dwp_files = ":empty",
32+
dynamic_runtime_libs = [":empty"],
33+
linker_files = ":empty",
34+
objcopy_files = ":empty",
35+
static_runtime_libs = [":empty"],
36+
strip_files = ":empty",
37+
supports_param_files = 0,
38+
)
39+
40+
cc_toolchain(
41+
name = "cc-compiler-k8",
42+
all_files = ":empty",
43+
compiler_files = ":empty",
44+
cpu = "local",
45+
dwp_files = ":empty",
46+
dynamic_runtime_libs = [":empty"],
47+
linker_files = ":empty",
48+
objcopy_files = ":empty",
49+
static_runtime_libs = [":empty"],
50+
strip_files = ":empty",
51+
supports_param_files = 0,
52+
)
53+
54+
filegroup(
55+
name = "srcs",
56+
srcs = glob(["**"]),
57+
)

tools/custom_crosstool/CROSSTOOL

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
major_version: "local"
2+
minor_version: ""
3+
default_target_cpu: "same_as_host"
4+
5+
default_toolchain {
6+
cpu: "k8"
7+
toolchain_identifier: "local_linux"
8+
}
9+
10+
toolchain {
11+
abi_version: "local"
12+
abi_libc_version: "local"
13+
builtin_sysroot: ""
14+
compiler: "compiler"
15+
host_system_name: "local"
16+
needsPic: true
17+
supports_gold_linker: false
18+
supports_incremental_linker: false
19+
supports_fission: false
20+
supports_interface_shared_objects: false
21+
supports_normalizing_ar: false
22+
supports_start_end_lib: false
23+
supports_thin_archives: false
24+
target_libc: "local"
25+
target_cpu: "local"
26+
target_system_name: "local"
27+
toolchain_identifier: "local_linux"
28+
29+
tool_path { name: "ar" path: "/usr/bin/ar" }
30+
tool_path { name: "compat-ld" path: "/usr/bin/ld" }
31+
tool_path { name: "cpp" path: "/usr/bin/cpp" }
32+
tool_path { name: "dwp" path: "/usr/bin/dwp" }
33+
tool_path { name: "gcc" path: "/usr/bin/gcc-4.8" }
34+
cxx_flag: "-std=c++0x"
35+
linker_flag: "-lstdc++"
36+
linker_flag: "-B/usr/bin/"
37+
38+
# TODO(bazel-team): In theory, the path here ought to exactly match the path
39+
# used by gcc. That works because bazel currently doesn't track files at
40+
# absolute locations and has no remote execution, yet. However, this will need
41+
# to be fixed, maybe with auto-detection?
42+
cxx_builtin_include_directory: "/usr/lib/gcc/"
43+
cxx_builtin_include_directory: "/usr/local/include"
44+
cxx_builtin_include_directory: "/usr/include"
45+
tool_path { name: "gcov" path: "/usr/bin/gcov" }
46+
47+
# C(++) compiles invoke the compiler (as that is the one knowing where
48+
# to find libraries), but we provide LD so other rules can invoke the linker.
49+
tool_path { name: "ld" path: "/usr/bin/ld" }
50+
51+
tool_path { name: "nm" path: "/usr/bin/nm" }
52+
tool_path { name: "objcopy" path: "/usr/bin/objcopy" }
53+
objcopy_embed_flag: "-I"
54+
objcopy_embed_flag: "binary"
55+
tool_path { name: "objdump" path: "/usr/bin/objdump" }
56+
tool_path { name: "strip" path: "/usr/bin/strip" }
57+
58+
# Anticipated future default.
59+
unfiltered_cxx_flag: "-no-canonical-prefixes"
60+
61+
# Make C++ compilation deterministic. Use linkstamping instead of these
62+
# compiler symbols.
63+
unfiltered_cxx_flag: "-Wno-builtin-macro-redefined"
64+
unfiltered_cxx_flag: "-D__DATE__=\"redacted\""
65+
unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\""
66+
unfiltered_cxx_flag: "-D__TIME__=\"redacted\""
67+
68+
# Security hardening on by default.
69+
# Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases.
70+
# We need to undef it before redefining it as some distributions now have
71+
# it enabled by default.
72+
compiler_flag: "-U_FORTIFY_SOURCE"
73+
compiler_flag: "-D_FORTIFY_SOURCE=1"
74+
compiler_flag: "-fstack-protector"
75+
compiler_flag: "-fPIE"
76+
linker_flag: "-pie"
77+
linker_flag: "-Wl,-z,relro,-z,now"
78+
79+
# Enable coloring even if there's no attached terminal. Bazel removes the
80+
# escape sequences if --nocolor is specified. This isn't supported by gcc
81+
# on Ubuntu 14.04.
82+
# compiler_flag: "-fcolor-diagnostics"
83+
84+
# All warnings are enabled. Maybe enable -Werror as well?
85+
compiler_flag: "-Wall"
86+
# Enable a few more warnings that aren't part of -Wall.
87+
compiler_flag: "-Wunused-but-set-parameter"
88+
# But disable some that are problematic.
89+
compiler_flag: "-Wno-free-nonheap-object" # has false positives
90+
91+
# Keep stack frames for debugging, even in opt mode.
92+
compiler_flag: "-fno-omit-frame-pointer"
93+
94+
# Anticipated future default.
95+
linker_flag: "-no-canonical-prefixes"
96+
# Have gcc return the exit code from ld.
97+
linker_flag: "-pass-exit-codes"
98+
# Stamp the binary with a unique identifier.
99+
linker_flag: "-Wl,--build-id=md5"
100+
linker_flag: "-Wl,--hash-style=gnu"
101+
# Gold linker only? Can we enable this by default?
102+
# linker_flag: "-Wl,--warn-execstack"
103+
# linker_flag: "-Wl,--detect-odr-violations"
104+
105+
compilation_mode_flags {
106+
mode: DBG
107+
# Enable debug symbols.
108+
compiler_flag: "-g"
109+
}
110+
compilation_mode_flags {
111+
mode: OPT
112+
113+
# No debug symbols.
114+
# Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or
115+
# even generally? However, that can't happen here, as it requires special
116+
# handling in Bazel.
117+
compiler_flag: "-g0"
118+
119+
# Conservative choice for -O
120+
# -O3 can increase binary size and even slow down the resulting binaries.
121+
# Profile first and / or use FDO if you need better performance than this.
122+
compiler_flag: "-O2"
123+
124+
# Disable assertions
125+
compiler_flag: "-DNDEBUG"
126+
127+
# Removal of unused code and data at link time (can this increase binary size in some cases?).
128+
compiler_flag: "-ffunction-sections"
129+
compiler_flag: "-fdata-sections"
130+
linker_flag: "-Wl,--gc-sections"
131+
}
132+
}

0 commit comments

Comments
 (0)