Skip to content

Commit

Permalink
Add compiler-specific warnings in Bazel.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-german-tri committed Jan 11, 2017
1 parent 0405c05 commit e9516b7
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 3 deletions.
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@ soft_failure_binary_repository(
name = "drake_visualizer",
local_path = __workspace_dir__ + "/build/install/bin/drake-visualizer",
)


load("//tools:toolchain.bzl", "drake_toolchain")
drake_toolchain()
25 changes: 25 additions & 0 deletions tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,40 @@ alias(
cc_toolchain_suite(
name = "default-toolchain",
toolchains = {
"k8|compiler": "cc-compiler-gcc-linux",
"k8|clang-3.9": "cc-compiler-clang-3.9-linux",
},
)

sh_binary(
name = "amend_crosstool",
srcs = ["amend_crosstool.sh"],
)

filegroup(
name = "empty",
srcs = [],
)

filegroup(
name = "gcc_wrapper",
srcs = ["gcc_wrapper.sh"],
)

cc_toolchain(
name = "cc-compiler-gcc-linux",
all_files = ":gcc_wrapper",
compiler_files = ":gcc_wrapper",
cpu = "k8",
dwp_files = ":empty",
dynamic_runtime_libs = [":empty"],
linker_files = ":gcc_wrapper",
objcopy_files = ":empty",
static_runtime_libs = [":empty"],
strip_files = ":empty",
supports_param_files = 0,
)

cc_toolchain(
name = "cc-compiler-clang-3.9-linux",
all_files = ":empty",
Expand Down
97 changes: 96 additions & 1 deletion tools/CROSSTOOL
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,101 @@ minor_version: ""
default_target_cpu: "same_as_host"
default_toolchain {
cpu: "k8"
toolchain_identifier: "clang-3.9-linux"
toolchain_identifier: "gcc-linux"
}

# System GCC on Linux
# Supported versions: 4.9 on Trusty, 5.4 on Xenial
toolchain {
toolchain_identifier: "gcc-linux"
abi_libc_version: "local"
abi_version: "local"
builtin_sysroot: ""
compiler: "compiler"
compiler_flag: "-U_FORTIFY_SOURCE"
compiler_flag: "-D_FORTIFY_SOURCE=1"
compiler_flag: "-fstack-protector"
compiler_flag: "-Wall"
compiler_flag: "-Wl,-z,-relro,-z,now"
compiler_flag: "-B/usr/bin"
compiler_flag: "-B/usr/bin"
compiler_flag: "-Wunused-but-set-parameter"
compiler_flag: "-Wno-free-nonheap-object"
compiler_flag: "-fno-canonical-system-headers"
compiler_flag: "-fno-omit-frame-pointer"
cxx_builtin_include_directory: "/usr/include/c++/4.9"
cxx_builtin_include_directory: "/usr/include/x86_64-linux-gnu/c++/4.9"
cxx_builtin_include_directory: "/usr/include/c++/4.9/backward"
cxx_builtin_include_directory: "/usr/lib/gcc/x86_64-linux-gnu/4.9/include"
cxx_builtin_include_directory: "/usr/local/include"
cxx_builtin_include_directory: "/usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed"
cxx_builtin_include_directory: "/usr/include/x86_64-linux-gnu"
cxx_builtin_include_directory: "/usr/include"
cxx_flag: "-std=c++1y"
host_system_name: "local"
linker_flag: "-lstdc++"
linker_flag: "-lm"
linker_flag: "-Wl,-no-as-needed"
linker_flag: "-B/usr/bin"
linker_flag: "-B/usr/bin"
linker_flag: "-pass-exit-codes"
linker_flag: "-Wl,--build-id=md5"
linker_flag: "-Wl,--hash-style=gnu"
needsPic: true
objcopy_embed_flag: "-I"
objcopy_embed_flag: "binary"
supports_fission: false
supports_gold_linker: false
supports_incremental_linker: false
supports_interface_shared_objects: false
supports_normalizing_ar: false
supports_start_end_lib: false
target_cpu: "k8"
target_libc: "local"
target_system_name: "local"
unfiltered_cxx_flag: "-fno-canonical-system-headers"
unfiltered_cxx_flag: "-Wno-builtin-macro-redefined"
unfiltered_cxx_flag: "-D__DATE__=\"redacted\""
unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\""
unfiltered_cxx_flag: "-D__TIME__=\"redacted\""
tool_path {name: "ar" path: "/usr/bin/ar" }
tool_path {name: "cpp" path: "/usr/bin/cpp" }
tool_path {name: "dwp" path: "/usr/bin/dwp" }
tool_path {name: "gcc" path: "/usr/bin/gcc-4.9" }
tool_path {name: "gcov" path: "/usr/bin/gcov" }
tool_path {name: "ld" path: "/usr/bin/ld" }
tool_path {name: "nm" path: "/usr/bin/nm" }
tool_path {name: "objcopy" path: "/usr/bin/objcopy" }
tool_path {name: "objdump" path: "/usr/bin/objdump" }
tool_path {name: "strip" path: "/usr/bin/strip" }

compilation_mode_flags {
mode: DBG
compiler_flag: "-g"
}
compilation_mode_flags {
mode: OPT
compiler_flag: "-g0"
compiler_flag: "-O2"
compiler_flag: "-DNDEBUG"
compiler_flag: "-ffunction-sections"
compiler_flag: "-fdata-sections"
linker_flag: "-Wl,--gc-sections"
}
linking_mode_flags { mode: DYNAMIC }

# Upgrade a bunch of warnings to errors.
cxx_flag: "-Werror=all"
cxx_flag: "-Werror=extra"
cxx_flag: "-Werror=ignored-qualifiers"
cxx_flag: "-Werror=overloaded-virtual"
cxx_flag: "-Werror=return-local-addr"
cxx_flag: "-Wno-unused-parameter"
cxx_flag: "-Wno-missing-field-initializers"
}


# Clang 3.9 on Linux
toolchain {
abi_version: "local"
abi_libc_version: "local"
Expand Down Expand Up @@ -48,6 +140,9 @@ toolchain {
compiler_flag: "-fno-omit-frame-pointer"
compiler_flag: "-O2"
}

compiler_flag: "-B/usr/bin/"

linker_flag: "-lstdc++"
linker_flag: "-lm"
linker_flag: "-B/usr/bin/"
Expand Down
7 changes: 7 additions & 0 deletions tools/amend_crosstool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

if grep clang "$1"; then

else

fi
17 changes: 17 additions & 0 deletions tools/bazel.rc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@ build -c opt

# Default build options.
build --strip=never
build --crosstool_top=//external:drake_toolchain

# Compilation flags that apply on all supported compilers.
build --copt -Werror=all
build --cxxopt -std=c++1y
build --cxxopt -Werror=ignored-qualifiers
build --cxxopt -Werror=overloaded-virtual

# Compilation flags that apply only on clang.
build --cxxopt -Werror=shadow
build --cxxopt -Werror=inconsistent-missing-override
build --cxxopt -Werror=sign-compare
build --cxxopt -Werror=return-stack-address

# Compilation flags that apply only on GCC.
build --cxxopt -Werror=extra
build --cxxopt -Werror=return-local-addr
build --cxxopt -Wno-unused-parameter
build --cxxopt -Wno-missing-field-initializers

# Default test options.
test --test_output=errors
Expand Down
11 changes: 10 additions & 1 deletion tools/bullet.BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# -*- python -*-


# These options are used when building Bullet C/C++ code.
# They do not flow downstream to Bullet-using libraries.
BULLET_COPTS = [
"-Wno-all",
"-Wno-extra",
"-Wno-overloaded-virtual",
]

# Note that this is only a portion of Bullet.
cc_library(
name = "lib",
Expand All @@ -11,7 +20,7 @@ cc_library(
"src/BulletCollision/**/*.h",
"src/LinearMath/**/*.h",
]) + ["src/btBulletCollisionCommon.h"],
copts = ["-Wno-all"],
copts = BULLET_COPTS,
defines = ["BT_USE_DOUBLE_PRECISION"],
includes = ["src"],
visibility = ["//visibility:public"],
Expand Down
5 changes: 4 additions & 1 deletion tools/gtest.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ cc_library(
"include/**/*.h",
"src/*.h",
]),
copts = ["-Wno-unused-const-variable"],
copts = [
"-Wno-unused-const-variable",
"-Wno-missing-field-initializers",
],
defines = [
"GTEST_DONT_DEFINE_FAIL=1",
"GTEST_DONT_DEFINE_SUCCEED=1",
Expand Down
1 change: 1 addition & 0 deletions tools/lcm.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ LCM_COPTS = [
"-Wno-all",
"-Wno-deprecated-declarations",
"-Wno-format-zero-length",
"-Wno-sign-compare",
"-std=gnu11",
]

Expand Down
22 changes: 22 additions & 0 deletions tools/toolchain.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- python -*-
# This is a Bazel repository_rule for auto-configuring the C++ toolchain.
# https://www.bazel.io/versions/master/docs/skylark/repository_rules.html
# It tweaks the default auto-configuration to add extra compiler flags.
# https://github.com/bazelbuild/bazel/blob/master/tools/cpp/cc_configure.bzl

def _drake_toolchain_impl(repository_ctx):
print("in _drake_toolchain_impl")
repository_ctx.file("scratch", content="foo")
repository_ctx.symlink(Label("@local_config_cc//:BUILD"), "BUILD")
repository_ctx.symlink(Label("@local_config_cc//:CROSSTOOL"), "CROSSTOOL.generic")
repository_ctx.symlink(Label("//tools:amend_crosstool"), "amend_crosstool.sh")
repository_ctx.execute(["bash", "amend_crosstool.sh", "CROSSTOOL.generic"])

drake_toolchain_autoconf = repository_rule(
local = True,
implementation = _drake_toolchain_impl,
)

def drake_toolchain():
drake_toolchain_autoconf(name="local_config_drake")
native.bind(name="drake_toolchain", actual="@local_config_drake//:toolchain")

0 comments on commit e9516b7

Please sign in to comment.