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

cc: toolchain: remove default warnings #116

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
25 changes: 19 additions & 6 deletions cc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports_files(
visibility = ["//visibility:public"],
)

# Disable tests and test libraries with --@rules_swiftnav//:disable_test=true
# Disable tests and test libraries with --@rules_swiftnav///cc:disable_test=true
bool_flag(
name = "disable_tests",
build_setting_default = False,
Expand All @@ -29,7 +29,7 @@ config_setting(
visibility = ["//visibility:public"],
)

# Enable exceptions with --@rules_swiftnav//:enable_exceptions=true
# Enable exceptions with --@rules_swiftnav//cc:enable_exceptions=true
bool_flag(
name = "enable_exceptions",
build_setting_default = False,
Expand All @@ -42,7 +42,7 @@ config_setting(
visibility = ["//visibility:public"],
)

# Enable rtti with --@rules_swiftnav//:enable_exceptions=true
# Enable rtti with --@rules_swiftnav//cc:enable_exceptions=true
bool_flag(
name = "enable_rtti",
build_setting_default = False,
Expand All @@ -55,6 +55,19 @@ config_setting(
visibility = ["//visibility:public"],
)

# Enable shared linking with --@rules_swiftnav//cc:enable_shared=true
bool_flag(
name = "enable_shared",
build_setting_default = False,
visibility = ["//visibility:public"],
)

config_setting(
name = "_enable_shared",
flag_values = {":enable_shared": "true"},
visibility = ["//visibility:public"],
)

# Disable warnings as errors with --@rules_swiftnav//cc:warnings_as_errors=false
bool_flag(
name = "warnings_as_errors",
Expand All @@ -75,21 +88,21 @@ string_flag(
visibility = ["//visibility:public"],
)

# Enable with --@rules_swiftnav//:cxx_standard=17
# Enable with --@rules_swiftnav//cc:cxx_standard=17
config_setting(
name = "cxx17",
flag_values = {":cxx_standard": "17"},
visibility = ["//visibility:public"],
)

# Enable with --@rules_swiftnav//:cxx_standard=20
# Enable with --@rules_swiftnav//cc:cxx_standard=20
config_setting(
name = "cxx20",
flag_values = {":cxx_standard": "20"},
visibility = ["//visibility:public"],
)

# Enable with --@rules_swiftnav//:cxx_standard=23
# Enable with --@rules_swiftnav//cc:cxx_standard=23
config_setting(
name = "cxx23",
flag_values = {":cxx_standard": "23"},
Expand Down
7 changes: 5 additions & 2 deletions cc/copts.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# The following are set by default by Bazel:
# -Wall, -Wunused-but-set-parameter, -Wno-free-heap-object
DEFAULT_COPTS = [
"-Wall",
"-Wthread-safety",
"-Wunused-but-set-parameter",
"-Wno-free-nonheap-object",
"-Wself-assign",
"-Wcast-align",
"-Wcast-qual",
"-Wchar-subscripts",
Expand Down
18 changes: 18 additions & 0 deletions cc/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def _common_cxx_opts(exceptions = False, rtti = False, standard = None):
def _construct_local_includes(local_includes):
return [construct_local_include(path) for path in local_includes]

def _link_static(linkstatic = True):
return select({
Label("//cc:_enable_shared"): False,
"//conditions:default": linkstatic,
})

# Disable building when --//:disable_tests=true or when building on windows
def _test_compatible_with():
return select({
Expand Down Expand Up @@ -220,6 +226,8 @@ def swift_c_library(**kwargs):

kwargs["tags"] = [LIBRARY] + kwargs.get("tags", [])

kwargs["linkstatic"] = _link_static(kwargs.get("linkstatic", True))

native.cc_library(**kwargs)

def swift_cc_library(**kwargs):
Expand Down Expand Up @@ -271,6 +279,8 @@ def swift_cc_library(**kwargs):

kwargs["tags"] = [LIBRARY] + kwargs.get("tags", [])

kwargs["linkstatic"] = _link_static(kwargs.get("linkstatic", True))

native.cc_library(**kwargs)

def swift_c_tool_library(**kwargs):
Expand Down Expand Up @@ -313,6 +323,8 @@ def swift_c_tool_library(**kwargs):

kwargs["copts"] = copts + c_standard + kwargs.get("copts", [])

kwargs["linkstatic"] = _link_static(kwargs.get("linkstatic", True))

native.cc_library(**kwargs)

def swift_cc_tool_library(**kwargs):
Expand Down Expand Up @@ -358,6 +370,8 @@ def swift_cc_tool_library(**kwargs):

kwargs["copts"] = copts + cxxopts + kwargs.get("copts", [])

kwargs["linkstatic"] = _link_static(kwargs.get("linkstatic", True))

native.cc_library(**kwargs)

def swift_c_binary(**kwargs):
Expand Down Expand Up @@ -404,6 +418,8 @@ def swift_c_binary(**kwargs):

kwargs["tags"] = [BINARY] + kwargs.get("tags", [])

kwargs["linkstatic"] = _link_static(kwargs.get("linkstatic", True))

native.cc_binary(**kwargs)

def swift_cc_binary(**kwargs):
Expand Down Expand Up @@ -568,6 +584,8 @@ def swift_cc_test_library(**kwargs):

kwargs["target_compatible_with"] = kwargs.get("target_compatible_with", []) + _test_compatible_with()

kwargs["linkstatic"] = _link_static(kwargs.get("linkstatic", True))

native.cc_library(**kwargs)

def swift_cc_test(name, type, **kwargs):
Expand Down
9 changes: 0 additions & 9 deletions cc/toolchains/llvm/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ def cc_toolchain_config(
"-ffp-contract=off",
# Diagnostics
"-fcolor-diagnostics",
"-Wall",
"-Wthread-safety",
"-Wself-assign",
] + extra_copts

# -fstandalone-debug disables options that optimize
Expand Down Expand Up @@ -108,12 +105,6 @@ def cc_toolchain_config(
use_lld = False
link_flags.extend([
"-headerpad_max_install_names",
# This will issue a warning on macOS ventura; see:
# https://github.com/python/cpython/issues/97524
# https://developer.apple.com/forums/thread/719961
"-undefined",
"dynamic_lookup",
"-Wl,-no_fixup_chains",
])
else:
use_lld = True
Expand Down
24 changes: 23 additions & 1 deletion cc/toolchains/llvm/unix_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ load(
)
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")

def _target_os_version(ctx):
platform_type = ctx.fragments.apple.single_arch_platform.platform_type
xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
return xcode_config.minimum_os_for_platform_type(platform_type)

def layering_check_features(compiler):
if compiler != "clang":
return []
Expand Down Expand Up @@ -984,7 +989,7 @@ def _impl(ctx):
flag_set(
actions = [ACTION_NAMES.cpp_link_static_library],
flag_groups = [
flag_group(flags = ["-static", "-s"]),
flag_group(flags = ["-no_warning_for_no_symbols", "-static", "-s"]),
flag_group(
flags = ["-o", "%{output_execpath}"],
expand_if_available = "output_execpath",
Expand Down Expand Up @@ -1283,6 +1288,17 @@ def _impl(ctx):
],
)

macos_minimum_os_feature = feature(
name = "macos_minimum_os",
enabled = True,
flag_sets = [
flag_set(
actions = all_compile_actions + all_link_actions,
flag_groups = [flag_group(flags = ["-mmacos-version-min={}".format(_target_os_version(ctx))])],
),
],
)

is_linux = ctx.attr.target_libc != "macosx"
libtool_feature = feature(
name = "libtool",
Expand Down Expand Up @@ -1365,6 +1381,7 @@ def _impl(ctx):
asan_feature,
tsan_feature,
ubsan_feature,
macos_minimum_os_feature,
] + (
[
supports_start_end_lib_feature,
Expand Down Expand Up @@ -1431,6 +1448,11 @@ cc_toolchain_config = rule(
"coverage_link_flags": attr.string_list(),
"supports_start_end_lib": attr.bool(),
"builtin_sysroot": attr.string(),
"_xcode_config": attr.label(default = configuration_field(
fragment = "apple",
name = "xcode_config_label",
)),
},
fragments = ["apple"],
provides = [CcToolchainConfigInfo],
)
4 changes: 4 additions & 0 deletions third_party/check.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ cmake(
"CMAKE_INSTALL_LIBDIR": "lib",
"HAVE_SUBUNIT": "0",
},
generate_args = [
"-GNinja",
"-DCMAKE_OSX_DEPLOYMENT_TARGET=13.0",
],
lib_source = ":srcs",
linkopts = select({
"@bazel_tools//src/conditions:darwin": ["-lpthread"],
Expand Down
2 changes: 2 additions & 0 deletions third_party/hdf5.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ cc_library(
],
"//conditions:default": [
"-Wno-error=implicit-function-declaration",
"-Wno-format",
"-Wno-incompatible-pointer-types-discards-qualifiers",
],
}),
includes = [
Expand Down
1 change: 1 addition & 0 deletions third_party/netcdf-c.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ cc_library(
"libdispatch",
"libsrc",
],
copts = ["-Wno-implicit-const-int-float-conversion"],
textual_hdrs = dispatch_textual_hdrs,
visibility = ["//visibility:public"],
deps = [
Expand Down
2 changes: 2 additions & 0 deletions third_party/nlopt.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ cmake(
"CMAKE_INSTALL_LIBDIR": "lib",
},
generate_args = [
"-GNinja",
"-DCMAKE_OSX_DEPLOYMENT_TARGET=13.0",
"-DBUILD_SHARED_LIBS=OFF",
"-DNLOPT_PYTHON=OFF",
"-DNLOPT_OCTAVE=OFF",
Expand Down
4 changes: 4 additions & 0 deletions third_party/suitesparse.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ cc_library(
includes = [
"CHOLMOD/SuiteSparse_metis/GKlib",
],
copts = [
"-Wno-fortify-source"
],
linkopts = [
"-lm",
"-lpthread",
Expand Down Expand Up @@ -381,6 +384,7 @@ cc_library(
],
copts = [
"-Iexternal/suitesparse/CHOLMOD/SuiteSparse_metis/libmetis/",
"-Wno-absolute-value",
],
includes = [
"CHOLMOD/SuiteSparse_metis/include/",
Expand Down
Loading