[bazel] Build a single maven artifact bundle (#8049)

Signed-off-by: Austin Schuh <austin.linux@gmail.com>
Co-authored-by: PJ Reiniger <pj.reiniger@gmail.com>
Co-authored-by: David Vo <auscompgeek@users.noreply.github.com>
This commit is contained in:
Austin Schuh
2025-07-22 13:26:20 -07:00
committed by GitHub
parent f3af50fc8e
commit 60098b0685
17 changed files with 930 additions and 136 deletions

View File

@@ -1,28 +0,0 @@
###############################
# Linux Common
###############################
# C++ only
build:base_linux --cxxopt=-std=c++20
build:base_linux --cxxopt=-Wformat=2
build:base_linux --cxxopt=-pedantic
build:base_linux --cxxopt=-Wno-psabi
build:base_linux --cxxopt=-Wno-unused-parameter
build:base_linux --cxxopt=-fPIC
build:base_linux --cxxopt=-pthread
# C Only
build:base_linux --conlyopt=-Wformat=2
build:base_linux --conlyopt=-pedantic
build:base_linux --conlyopt=-Wno-psabi
build:base_linux --conlyopt=-Wno-unused-parameter
build:base_linux --conlyopt=-fPIC
build:base_linux --conlyopt=-pthread
# Linker
build:base_linux --linkopt=-rdynamic
build:base_linux --linkopt=-pthread
build:base_linux --linkopt=-ldl
build:base_linux --linkopt=-latomic
build:base_linux --linkopt=-Wl,-rpath,'$ORIGIN'

View File

@@ -1,17 +1,19 @@
###############################
# Linux
###############################
build:linux --config=base_linux
# Warning level
build:linux --copt=-Wall
build:linux --copt=-Wextra
build:linux --copt=-Werror
# Start with configuring the autodetected toolchain.
# The target toolchain should be captured already in its toolchain.
common:linux --repo_env=BAZEL_COPTS="-Wall:-Wextra:-Werror"
# Not in nativetools
build:linux --cxxopt=-Wno-deprecated-enum-enum-conversion
# C++ only
common:linux --repo_env=BAZEL_CXXOPTS="-std=c++20:-Wformat=2:-pedantic:-Wno-psabi:-Wno-unused-parameter:-fPIC:-pthread:-Wno-deprecated-enum-enum-conversion"
# C Only
common:linux --repo_env=BAZEL_CONLYOPTS="-Wformat=2:-pedantic:-Wno-psabi:-Wno-unused-parameter:-fPIC:-pthread"
# Linker
common:linux --repo_env=BAZEL_LINKOPTS="-rdynamic:-pthread:-ldl:-latomic:-Wl,-rpath,'$ORIGIN'"
# Cleanup build output for tools
build:linux --host_cxxopt=-Wno-missing-field-initializers
@@ -19,3 +21,11 @@ build:linux --host_cxxopt=-Wno-deprecated-enum-enum-conversion
build:linux --host_cxxopt=-Wno-sign-compare
build:linux --host_cxxopt=-Wno-unknown-pragmas
build:linux --host_cxxopt=-Wno-attributes
# Ignore potential issues in third party code on the host
build:linux --host_cxxopt=-Wno-pedantic
build:linux --host_cxxopt=-Wno-format-nonliteral
build:linux --host_cxxopt=-Wno-missing-requires
build:linux --host_cxxopt=-Wno-implicit-fallthrough
build:linux --host_per_file_copt=external/zlib/.*\.c@-Wno-deprecated-non-prototype

View File

@@ -1,36 +1,10 @@
# Warning level
build:macos --copt=-Wall
build:macos --copt=-Wextra
build:macos --copt=-Werror
common:macos --repo_env=BAZEL_COPTS="-Wall:-Wextra:-Werror:-Wno-shorten-64-to-32:-Wno-gcc-compat"
common:macos --host_per_file_copt=external/.*@-Wno-deprecated-non-prototype,-Wno-unused-function,-Wno-sign-compare
# C++ only
build:macos --cxxopt=-std=c++20
build:macos --cxxopt=-pedantic
build:macos --cxxopt=-fPIC
build:macos --cxxopt=-Wno-unused-parameter
build:macos --cxxopt=-Wno-error=deprecated-enum-enum-conversion
build:macos --cxxopt=-Wno-missing-field-initializers
build:macos --cxxopt=-Wno-unused-private-field
build:macos --cxxopt=-Wno-unused-const-variable
build:macos --cxxopt=-Wno-error=c11-extensions
build:macos --cxxopt=-pthread
build:macos --cxxopt=-Wno-deprecated-anon-enum-enum-conversion
common:macos --repo_env=BAZEL_CXXOPTS="-std=c++20:-pedantic:-fPIC:-Wno-unused-parameter:-Wno-error=deprecated-enum-enum-conversion:-Wno-missing-field-initializers:-Wno-unused-private-field:-Wno-unused-const-variable:-Wno-error=c11-extensions:-pthread:-Wno-deprecated-anon-enum-enum-conversion"
# C only
build:macos --conlyopt=-pedantic
build:macos --conlyopt=-fPIC
build:macos --conlyopt=-Wno-unused-parameter
build:macos --conlyopt=-Wno-missing-field-initializers
build:macos --conlyopt=-Wno-unused-private-field
build:macos --conlyopt=-Wno-fixed-enum-extension"
common:macos --repo_env=BAZEL_CONLYOPTS="-pedantic:-fPIC:-Wno-unused-parameter:-Wno-missing-field-initializers:-Wno-unused-private-field:-Wno-fixed-enum-extension"
build:macos --linkopt=-headerpad_max_install_names
build:macos --linkopt=-Wl,-rpath,'@loader_path'"
# Things not in nativetools
build:macos --copt=-Wno-shorten-64-to-32
build:macos --host_per_file_copt=external/zlib/.*\.c@-Wno-deprecated-non-prototype
build:macos --host_per_file_copt=external/com_google_protobuf/.*\.cc@-Wno-unused-function
common:macos --repo_env=BAZEL_LINKOPTS="-Wl,-rpath,'@loader_path'"

View File

@@ -1,17 +1,5 @@
###############################
# Roborio
###############################
build:roborio --config=base_linux
build:roborio --platforms=@rules_bzlmodrio_toolchains//platforms/roborio
build:roborio --features=compiler_param_file
build:roborio --platform_suffix=roborio
build:roborio --incompatible_enable_cc_toolchain_resolution
build:roborio --cxxopt=-Wno-error=deprecated-declarations
# Extra 11
build:roborio --cxxopt=-Wno-error=deprecated-enum-enum-conversion
build:roborio --host_per_file_copt=external/zlib/.*\.c@-Wno-deprecated-non-prototype

View File

@@ -1,10 +1,6 @@
build:systemcore --config=base_linux
###############################
# Systemcore
###############################
build:systemcore --platforms=@rules_bzlmodrio_toolchains//platforms/systemcore
build:systemcore --build_tag_filters=-no-systemcore
build:systemcore --features=compiler_param_file
build:systemcore --platform_suffix=systemcore
build:systemcore --incompatible_enable_cc_toolchain_resolution
build:systemcore --cxxopt=-Wno-error=deprecated-declarations

View File

@@ -2,49 +2,28 @@
# Common Flags
################################
# Warning level
build:windows_common --copt=/W3
build:windows_common --copt=/WX
common:windows --repo_env="BAZEL_COPTS=/W3:/WX"
# C++ options
build:windows_common --cxxopt=/EHsc
build:windows_common --cxxopt=/FS
build:windows_common --cxxopt=/Zc:inline
build:windows_common --cxxopt=/wd4244
build:windows_common --cxxopt=/wd4267
build:windows_common --cxxopt=/wd4146
build:windows_common --cxxopt=/wd4996
build:windows_common --cxxopt=/Zc:throwingNew
build:windows_common --cxxopt=/D_CRT_SECURE_NO_WARNINGS
build:windows_common --cxxopt=/std:c++20
build:windows_common --cxxopt=/permissive-
build:windows_common --cxxopt=/utf-8
build:windows_common --cxxopt=/bigobj
build:windows_common --cxxopt=/Zc:__cplusplus
build:windows_common --cxxopt=/Zc:preprocessor
build:windows_common --cxxopt=/wd5105
common:windows --repo_env="BAZEL_CXXOPTS=/EHsc:/FS:/Zc%:inline:/wd4244:/wd4267:/wd4146:/wd4996:/Zc%:throwingNew:/D_CRT_SECURE_NO_WARNINGS:/std%:c++20:/permissive-:/utf-8:/bigobj:/Zc%:__cplusplus:/Zc%:preprocessor:/wd5105"
# Remove "/D_WIN32_WINNT=0x0601"
common:windows --repo_env="BAZEL_WIN32_WINNT="
# C Only
build:windows_common --conlyopt=/FS
build:windows_common --conlyopt=/Zc:inline
build:windows_common --conlyopt=/D_CRT_SECURE_NO_WARNINGS
# build:windows_common --linkopt=/IGNORE:4099
# TODO there is a "bug" in bazel that forces "/D_WIN32_WINNT=0x0601". Remove it from the files that break because of this.
build:windows_common --per_file_copt=wpiutil/src/main/native/cpp/timestamp.cpp,wpinet/src/main/native/thirdparty/libuv/src/win/util.cpp,hal/src/main/native/sim/HAL.cpp@/U_WIN32_WINNT
common:windows --repo_env="BAZEL_CONLYOPTS=/FS:/Zc%:inline:/D_CRT_SECURE_NO_WARNINGS"
################################
# Standard Windows Flags
################################
build:windows --config=windows_common
build:windows --linkopt=/DEPENDENTLOADFLAG:0x1100
build:windows --repo_env="BAZEL_LINKOPTS=/DEPENDENTLOADFLAG%:0x1100"
################################
# ARM Windows Flags
################################
build:windows_arm --config=windows_common
build:windows_arm --platforms="@rules_bzlmodrio_toolchains//platforms/windows_arm64" --platform_suffix=windowsarm64
build:windows_arm --cpu=arm64_windows
build:windows_arm --linkopt=/IGNORE:4099
# Ignore duplicate inline statment in tools
build:windows --host_copt=/wd4141
# Ignore utf8 warning in tools
build:windows --host_copt=/wd4715

View File

@@ -0,0 +1,524 @@
diff --git a/cc/private/toolchain/BUILD.tpl b/cc/private/toolchain/BUILD.tpl
index 522d67e..afc8a25 100644
--- a/cc/private/toolchain/BUILD.tpl
+++ b/cc/private/toolchain/BUILD.tpl
@@ -115,6 +115,7 @@ cc_toolchain_config(
opt_compile_flags = [%{opt_compile_flags}],
dbg_compile_flags = [%{dbg_compile_flags}],
conly_flags = [%{conly_flags}],
+ c_flags = [%{c_flags}],
cxx_flags = [%{cxx_flags}],
link_flags = [%{link_flags}],
link_libs = [%{link_libs}],
diff --git a/cc/private/toolchain/BUILD.windows.tpl b/cc/private/toolchain/BUILD.windows.tpl
index 75fbd0a..2ff8c3a 100644
--- a/cc/private/toolchain/BUILD.windows.tpl
+++ b/cc/private/toolchain/BUILD.windows.tpl
@@ -124,6 +124,11 @@ cc_toolchain_config(
cxx_builtin_include_directories = [%{cxx_builtin_include_directories}],
tool_paths = {%{tool_paths}},
tool_bin_path = "%{tool_bin_path}",
+ c_flags = [%{c_flags}],
+ conly_flags = [%{conly_flags}],
+ cxx_flags = [%{cxx_flags}],
+ link_flags = [%{link_flags}],
+ win32_winnt_flag = "%{win32_winnt_flag}",
)
toolchain(
@@ -170,6 +175,11 @@ cc_toolchain_config(
tool_bin_path = "%{tool_bin_path}",
default_compile_flags = ["-m32"],
default_link_flags = ["-m32"],
+ c_flags = [%{c_flags}],
+ conly_flags = [%{conly_flags}],
+ cxx_flags = [%{cxx_flags}],
+ link_flags = [%{link_flags}],
+ win32_winnt_flag = "%{win32_winnt_flag}",
)
toolchain(
@@ -214,6 +224,11 @@ cc_toolchain_config(
tool_bin_path = "%{mingw_tool_bin_path}",
cxx_builtin_include_directories = [%{mingw_cxx_builtin_include_directories}],
tool_paths = {%{mingw_tool_paths}},
+ c_flags = [%{c_flags}],
+ conly_flags = [%{conly_flags}],
+ cxx_flags = [%{cxx_flags}],
+ link_flags = [%{link_flags}],
+ win32_winnt_flag = "%{win32_winnt_flag}",
)
toolchain(
@@ -260,6 +275,11 @@ cc_toolchain_config(
tool_paths = {%{mingw_tool_paths}},
default_compile_flags = ["-m32"],
default_link_flags = ["-m32"],
+ c_flags = [%{c_flags}],
+ conly_flags = [%{conly_flags}],
+ cxx_flags = [%{cxx_flags}],
+ link_flags = [%{link_flags}],
+ win32_winnt_flag = "%{win32_winnt_flag}",
)
toolchain(
@@ -330,6 +350,11 @@ cc_toolchain_config(
dbg_mode_debug_flag = "%{dbg_mode_debug_flag_x64}",
fastbuild_mode_debug_flag = "%{fastbuild_mode_debug_flag_x64}",
supports_parse_showincludes = %{msvc_parse_showincludes_x64},
+ c_flags = [%{c_flags}],
+ conly_flags = [%{conly_flags}],
+ cxx_flags = [%{cxx_flags}],
+ link_flags = [%{link_flags}],
+ win32_winnt_flag = "%{win32_winnt_flag}",
)
toolchain(
@@ -399,6 +424,11 @@ cc_toolchain_config(
dbg_mode_debug_flag = "%{dbg_mode_debug_flag_x86}",
fastbuild_mode_debug_flag = "%{fastbuild_mode_debug_flag_x86}",
supports_parse_showincludes = %{msvc_parse_showincludes_x86},
+ c_flags = [%{c_flags}],
+ conly_flags = [%{conly_flags}],
+ cxx_flags = [%{cxx_flags}],
+ link_flags = [%{link_flags}],
+ win32_winnt_flag = "%{win32_winnt_flag}",
)
toolchain(
@@ -468,6 +498,11 @@ cc_toolchain_config(
dbg_mode_debug_flag = "%{dbg_mode_debug_flag_arm}",
fastbuild_mode_debug_flag = "%{fastbuild_mode_debug_flag_arm}",
supports_parse_showincludes = %{msvc_parse_showincludes_arm},
+ c_flags = [%{c_flags}],
+ conly_flags = [%{conly_flags}],
+ cxx_flags = [%{cxx_flags}],
+ link_flags = [%{link_flags}],
+ win32_winnt_flag = "%{win32_winnt_flag}",
)
toolchain(
@@ -537,6 +572,11 @@ cc_toolchain_config(
dbg_mode_debug_flag = "%{dbg_mode_debug_flag_arm64}",
fastbuild_mode_debug_flag = "%{fastbuild_mode_debug_flag_arm64}",
supports_parse_showincludes = %{msvc_parse_showincludes_arm64},
+ c_flags = [%{c_flags}],
+ conly_flags = [%{conly_flags}],
+ cxx_flags = [%{cxx_flags}],
+ link_flags = [%{link_flags}],
+ win32_winnt_flag = "%{win32_winnt_flag}",
)
toolchain(
@@ -604,6 +644,11 @@ cc_toolchain_config(
dbg_mode_debug_flag = "%{clang_cl_dbg_mode_debug_flag_x64}",
fastbuild_mode_debug_flag = "%{clang_cl_fastbuild_mode_debug_flag_x64}",
supports_parse_showincludes = %{clang_cl_parse_showincludes_x64},
+ c_flags = [%{c_flags}],
+ conly_flags = [%{conly_flags}],
+ cxx_flags = [%{cxx_flags}],
+ link_flags = [%{link_flags}],
+ win32_winnt_flag = "%{win32_winnt_flag}",
)
toolchain(
@@ -672,6 +717,11 @@ cc_toolchain_config(
dbg_mode_debug_flag = "%{clang_cl_dbg_mode_debug_flag_arm64}",
fastbuild_mode_debug_flag = "%{clang_cl_fastbuild_mode_debug_flag_arm64}",
supports_parse_showincludes = %{clang_cl_parse_showincludes_arm64},
+ c_flags = [%{c_flags}],
+ conly_flags = [%{conly_flags}],
+ cxx_flags = [%{cxx_flags}],
+ link_flags = [%{link_flags}],
+ win32_winnt_flag = "%{win32_winnt_flag}",
)
toolchain(
diff --git a/cc/private/toolchain/cc_configure.bzl b/cc/private/toolchain/cc_configure.bzl
index ce0dac5..475a9dd 100644
--- a/cc/private/toolchain/cc_configure.bzl
+++ b/cc/private/toolchain/cc_configure.bzl
@@ -125,6 +125,7 @@ cc_autoconf = repository_rule(
"BAZEL_TARGET_SYSTEM",
"BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN",
"BAZEL_USE_LLVM_NATIVE_COVERAGE",
+ "BAZEL_WIN32_WINNT",
"BAZEL_LLVM",
"BAZEL_IGNORE_SYSTEM_HEADERS_VERSIONS",
"USE_CLANG_CL",
diff --git a/cc/private/toolchain/BUILD.windows_toolchains.tpl b/cc/private/toolchain/BUILD.windows_toolchains.tpl
index e69de29..63f5b6d 100644
--- a/cc/private/toolchain/BUILD.windows_toolchains.tpl
+++ b/cc/private/toolchain/BUILD.windows_toolchains.tpl
@@ -0,0 +1,34 @@
+load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")
+
+toolchain(
+ name = "cc-toolchain-arm64_windows",
+ exec_compatible_with = HOST_CONSTRAINTS,
+ target_compatible_with = [
+ "@platforms//cpu:arm64",
+ "@platforms//os:windows",
+ ],
+ toolchain = "@local_config_cc//:cc-compiler-arm64_windows",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
+
+toolchain(
+ name = "cc-toolchain-x64_windows",
+ exec_compatible_with = HOST_CONSTRAINTS,
+ target_compatible_with = [
+ "@platforms//cpu:x86_64",
+ "@platforms//os:windows",
+ ],
+ toolchain = "@local_config_cc//:cc-compiler-x64_windows",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
+
+toolchain(
+ name = "cc-toolchain-armeabi-v7a",
+ exec_compatible_with = HOST_CONSTRAINTS,
+ target_compatible_with = [
+ "@platforms//cpu:armv7",
+ "@platforms//os:android",
+ ],
+ toolchain = "@local_config_cc//:cc-compiler-armeabi-v7a",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
diff --git a/cc/private/toolchain/cc_configure.bzl b/cc/private/toolchain/cc_configure.bzl
index ce0dac5..d8d8139 100644
--- a/cc/private/toolchain/cc_configure.bzl
+++ b/cc/private/toolchain/cc_configure.bzl
@@ -33,12 +33,17 @@ def cc_autoconf_toolchains_impl(repository_ctx):
should_detect_cpp_toolchain = "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN" not in env or env["BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN"] != "1"
if should_detect_cpp_toolchain:
+ if repository_ctx.os.name.find("windows") != -1:
+ build_path = "@rules_cc//cc/private/toolchain:BUILD.windows_toolchains.tpl"
+ else:
+ build_path = "@rules_cc//cc/private/toolchain:BUILD.toolchains.tpl"
paths = resolve_labels(repository_ctx, [
- "@rules_cc//cc/private/toolchain:BUILD.toolchains.tpl",
+ build_path,
])
+
repository_ctx.template(
"BUILD",
- paths["@rules_cc//cc/private/toolchain:BUILD.toolchains.tpl"],
+ paths[build_path],
{"%{name}": get_cpu_value(repository_ctx)},
)
else:
@@ -113,6 +118,7 @@ cc_autoconf = repository_rule(
"BAZEL_COMPILER",
"BAZEL_HOST_SYSTEM",
"BAZEL_CONLYOPTS",
+ "BAZEL_COPTS",
"BAZEL_CXXOPTS",
"BAZEL_LINKOPTS",
"BAZEL_LINKLIBS",
diff --git a/cc/private/toolchain/unix_cc_configure.bzl b/cc/private/toolchain/unix_cc_configure.bzl
index 6a6f38a..50270a1 100644
--- a/cc/private/toolchain/unix_cc_configure.bzl
+++ b/cc/private/toolchain/unix_cc_configure.bzl
@@ -459,6 +459,12 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overridden_tools):
},
)
+ c_opts = split_escaped(get_env_var(
+ repository_ctx,
+ "BAZEL_COPTS",
+ "",
+ False,
+ ), ":")
conly_opts = split_escaped(get_env_var(
repository_ctx,
"BAZEL_CONLYOPTS",
@@ -662,6 +668,7 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overridden_tools):
False,
)),
"%{conly_flags}": get_starlark_list(conly_opts),
+ "%{c_flags}": get_starlark_list(c_opts),
"%{coverage_compile_flags}": coverage_compile_flags,
"%{coverage_link_flags}": coverage_link_flags,
"%{cxx_builtin_include_directories}": get_starlark_list(builtin_include_directories),
diff --git a/cc/private/toolchain/unix_cc_toolchain_config.bzl b/cc/private/toolchain/unix_cc_toolchain_config.bzl
index ee26a55..23da019 100644
--- a/cc/private/toolchain/unix_cc_toolchain_config.bzl
+++ b/cc/private/toolchain/unix_cc_toolchain_config.bzl
@@ -407,6 +407,14 @@ def _impl(ctx):
] if ctx.attr.opt_compile_flags else []),
with_features = [with_feature_set(features = ["opt"])],
),
+ flag_set(
+ actions = all_compile_actions,
+ flag_groups = ([
+ flag_group(
+ flags = ctx.attr.c_flags,
+ ),
+ ] if ctx.attr.c_flags else []),
+ ),
flag_set(
actions = [ACTION_NAMES.c_compile],
flag_groups = ([
@@ -1916,6 +1924,7 @@ cc_toolchain_config = rule(
"compile_flags": attr.string_list(),
"compiler": attr.string(mandatory = True),
"conly_flags": attr.string_list(),
+ "c_flags": attr.string_list(),
"coverage_compile_flags": attr.string_list(),
"coverage_link_flags": attr.string_list(),
"cpu": attr.string(mandatory = True),
diff --git a/cc/private/toolchain/windows_cc_configure.bzl b/cc/private/toolchain/windows_cc_configure.bzl
index 66ca5fb..7581ce7 100644
--- a/cc/private/toolchain/windows_cc_configure.bzl
+++ b/cc/private/toolchain/windows_cc_configure.bzl
@@ -21,7 +21,9 @@ load(
"auto_configure_warning_maybe",
"escape_string",
"execute",
+ "get_starlark_list",
"resolve_labels",
+ "split_escaped",
"write_builtin_include_directory_paths",
)
@@ -848,6 +850,42 @@ def _get_msvc_deps_scanner_vars(repository_ctx, paths, template_vars, target_arc
"%{msvc_deps_scanner_wrapper_path_" + target_arch + "}": "msvc_deps_scanner_wrapper_" + target_arch + ".bat",
}
+def _get_copts(repository_ctx):
+ """Get the variables we need to populate the msys/mingw toolchains."""
+ conly_opts = split_escaped(_get_env_var(
+ repository_ctx,
+ "BAZEL_CONLYOPTS",
+ "",
+ ), ":")
+ c_opts = split_escaped(_get_env_var(
+ repository_ctx,
+ "BAZEL_COPTS",
+ "",
+ ), ":")
+ cxx_opts = split_escaped(_get_env_var(
+ repository_ctx,
+ "BAZEL_CXXOPTS",
+ "",
+ ), ":")
+ link_opts = split_escaped(_get_env_var(
+ repository_ctx,
+ "BAZEL_LINKOPTS",
+ "",
+ ), ":")
+ win32_winnt_opts = _get_env_var(
+ repository_ctx,
+ "BAZEL_WIN32_WINNT",
+ "/D_WIN32_WINNT=0x0601",
+ )
+ copts_vars = {
+ "%{c_flags}": get_starlark_list(c_opts),
+ "%{conly_flags}": get_starlark_list(conly_opts),
+ "%{cxx_flags}": get_starlark_list(cxx_opts),
+ "%{link_flags}": get_starlark_list(link_opts),
+ "%{win32_winnt_flag}": escape_string(win32_winnt_opts),
+ }
+ return copts_vars
+
def configure_windows_toolchain(repository_ctx):
"""Configure C++ toolchain on Windows.
@@ -882,6 +920,7 @@ def configure_windows_toolchain(repository_ctx):
template_vars.update(msvc_vars_x64)
template_vars.update(_get_clang_cl_vars(repository_ctx, paths, msvc_vars_x64, "x64"))
template_vars.update(_get_msys_mingw_vars(repository_ctx))
+ template_vars.update(_get_copts(repository_ctx))
template_vars.update(_get_msvc_vars(repository_ctx, paths, "x86", msvc_vars_x64))
template_vars.update(_get_msvc_vars(repository_ctx, paths, "arm", msvc_vars_x64))
msvc_vars_arm64 = _get_msvc_vars(repository_ctx, paths, "arm64", msvc_vars_x64)
diff --git a/cc/private/toolchain/windows_cc_toolchain_config.bzl b/cc/private/toolchain/windows_cc_toolchain_config.bzl
index d8cf50e..f1c97ab 100644
--- a/cc/private/toolchain/windows_cc_toolchain_config.bzl
+++ b/cc/private/toolchain/windows_cc_toolchain_config.bzl
@@ -88,6 +88,12 @@ all_link_actions = [
ACTION_NAMES.cpp_link_nodeps_dynamic_library,
]
+lto_index_actions = [
+ ACTION_NAMES.lto_index_for_executable,
+ ACTION_NAMES.lto_index_for_dynamic_library,
+ ACTION_NAMES.lto_index_for_nodeps_dynamic_library,
+]
+
def _use_msvc_toolchain(ctx):
return ctx.attr.cpu in ["x64_windows", "arm64_windows"] and (ctx.attr.compiler == "msvc-cl" or ctx.attr.compiler == "clang-cl")
@@ -579,7 +585,11 @@ def _impl(ctx):
ACTION_NAMES.cpp20_module_compile,
ACTION_NAMES.cpp20_module_codegen,
],
- flag_groups = [
+ flag_groups = ([
+ flag_group(
+ flags = ctx.attr.c_flags,
+ ),
+ ] if ctx.attr.c_flags else []) + [
flag_group(
flags = ["%{user_compile_flags}"],
iterate_over = "user_compile_flags",
@@ -587,6 +597,30 @@ def _impl(ctx):
),
],
),
+ flag_set(
+ actions = [ACTION_NAMES.c_compile],
+ flag_groups = ([
+ flag_group(
+ flags = ctx.attr.conly_flags,
+ ),
+ ] if ctx.attr.conly_flags else []),
+ ),
+ flag_set(
+ actions = [
+ ACTION_NAMES.linkstamp_compile,
+ ACTION_NAMES.cpp_compile,
+ ACTION_NAMES.cpp_header_parsing,
+ ACTION_NAMES.cpp_module_compile,
+ ACTION_NAMES.cpp_module_codegen,
+ ACTION_NAMES.lto_backend,
+ ACTION_NAMES.clif_match,
+ ],
+ flag_groups = ([
+ flag_group(
+ flags = ctx.attr.cxx_flags,
+ ),
+ ] if ctx.attr.cxx_flags else []),
+ ),
],
)
@@ -725,9 +759,33 @@ def _impl(ctx):
),
],
),
+ flag_set(
+ actions = all_link_actions + lto_index_actions,
+ flag_groups = ([
+ flag_group(
+ flags = ctx.attr.link_flags,
+ ),
+ ] if ctx.attr.link_flags else []),
+ ),
],
)
+ default_compile_flags_list = [
+ "/DCOMPILER_MSVC",
+ "/DNOMINMAX",
+ "/D_CRT_SECURE_NO_DEPRECATE",
+ "/D_CRT_SECURE_NO_WARNINGS",
+ "/bigobj",
+ "/Zm500",
+ "/EHsc",
+ "/wd4351",
+ "/wd4291",
+ "/wd4250",
+ "/wd4996",
+ ]
+ if ctx.attr.win32_winnt_flag:
+ default_compile_flags_list.append(ctx.attr.win32_winnt_flag)
+
default_compile_flags_feature = feature(
name = "default_compile_flags",
enabled = True,
@@ -750,20 +808,7 @@ def _impl(ctx):
],
flag_groups = [
flag_group(
- flags = [
- "/DCOMPILER_MSVC",
- "/DNOMINMAX",
- "/D_WIN32_WINNT=0x0601",
- "/D_CRT_SECURE_NO_DEPRECATE",
- "/D_CRT_SECURE_NO_WARNINGS",
- "/bigobj",
- "/Zm500",
- "/EHsc",
- "/wd4351",
- "/wd4291",
- "/wd4250",
- "/wd4996",
- ],
+ flags = default_compile_flags_list,
),
],
),
@@ -1534,7 +1579,11 @@ def _impl(ctx):
ACTION_NAMES.lto_backend,
ACTION_NAMES.clif_match,
],
- flag_groups = [
+ flag_groups = ([
+ flag_group(
+ flags = ctx.attr.c_flags,
+ ),
+ ] if ctx.attr.c_flags else []) + [
flag_group(
flags = ["%{user_compile_flags}"],
iterate_over = "user_compile_flags",
@@ -1542,6 +1591,30 @@ def _impl(ctx):
),
],
),
+ flag_set(
+ actions = [ACTION_NAMES.c_compile],
+ flag_groups = ([
+ flag_group(
+ flags = ctx.attr.conly_flags,
+ ),
+ ] if ctx.attr.conly_flags else []),
+ ),
+ flag_set(
+ actions = [
+ ACTION_NAMES.linkstamp_compile,
+ ACTION_NAMES.cpp_compile,
+ ACTION_NAMES.cpp_header_parsing,
+ ACTION_NAMES.cpp_module_compile,
+ ACTION_NAMES.cpp_module_codegen,
+ ACTION_NAMES.lto_backend,
+ ACTION_NAMES.clif_match,
+ ],
+ flag_groups = ([
+ flag_group(
+ flags = ctx.attr.cxx_flags,
+ ),
+ ] if ctx.attr.cxx_flags else []),
+ ),
],
)
@@ -1642,14 +1715,18 @@ cc_toolchain_config = rule(
"abi_libc_version": attr.string(),
"abi_version": attr.string(),
"archiver_flags": attr.string_list(default = []),
+ "c_flags": attr.string_list(),
"compiler": attr.string(),
+ "conly_flags": attr.string_list(),
"cpu": attr.string(mandatory = True),
"cxx_builtin_include_directories": attr.string_list(),
+ "cxx_flags": attr.string_list(),
"dbg_mode_debug_flag": attr.string(default = ""),
"default_compile_flags": attr.string_list(default = []),
"default_link_flags": attr.string_list(default = []),
"fastbuild_mode_debug_flag": attr.string(default = ""),
"host_system_name": attr.string(),
+ "link_flags": attr.string_list(),
"msvc_cl_path": attr.string(default = "vc_installation_error.bat"),
"msvc_env_include": attr.string(default = "msvc_not_found"),
"msvc_env_lib": attr.string(default = "msvc_not_found"),
@@ -1664,6 +1741,7 @@ cc_toolchain_config = rule(
"tool_bin_path": attr.string(default = "not_found"),
"tool_paths": attr.string_dict(),
"toolchain_identifier": attr.string(),
+ "win32_winnt_flag": attr.string(default = "/D_WIN32_WINNT=0x0601"),
},
provides = [CcToolchainConfigInfo],
)

View File

@@ -1,4 +1,6 @@
load("@build_bazel_apple_support//rules:universal_binary.bzl", "universal_binary")
load("@rules_cc//cc:action_names.bzl", "CPP_LINK_STATIC_LIBRARY_ACTION_NAME")
load("@rules_cc//cc:cc_shared_library.bzl", "cc_shared_library")
load("@rules_cc//cc:defs.bzl", "CcInfo", "cc_library")
load("@rules_cc//cc:find_cc_toolchain.bzl", "CC_TOOLCHAIN_ATTRS", "find_cpp_toolchain", "use_cc_toolchain")
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
@@ -153,26 +155,38 @@ def wpilib_cc_shared_library(
name,
auto_export_windows_symbols = True,
**kwargs):
folder, lib = _folder_prefix(name)
features = []
if auto_export_windows_symbols:
features.append("windows_export_all_symbols")
native.cc_shared_library(
cc_shared_library(
name = name,
features = features,
**kwargs
)
pkg_files(
name = name + "-shared.pkg",
srcs = [":" + name],
tags = ["manual"],
universal_name = "universal/lib" + lib + ".lib"
universal_binary(
name = universal_name,
binary = name,
target_compatible_with = [
"@platforms//os:osx",
],
)
pkg_zip(
name = name + "-shared-zip",
srcs = ["//:license_pkg_files", name + "-shared.pkg"],
tags = ["no-remote", "manual"],
pkg_files(
name = folder + "/lib" + lib + "-shared-files",
srcs = select({
"@rules_bzlmodrio_toolchains//conditions:osx": [universal_name],
"//conditions:default": [
":" + name,
],
}),
strip_prefix = select({
"@rules_bzlmodrio_toolchains//conditions:osx": "universal",
"//conditions:default": folder,
}),
)
CcStaticLibraryInfo = provider(

View File

@@ -1,6 +1,9 @@
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
load("@rules_java//java:defs.bzl", "java_library")
load("@rules_java//java/common:java_info.bzl", "JavaInfo")
load("@rules_pkg//:mappings.bzl", "filter_directory")
def _jni_headers_impl(ctx):

View File

@@ -0,0 +1,142 @@
"""Bazel rules for publishing maven artifacts."""
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@com_wpilib_allwpilib_publishing_config//:publishing_config.bzl", "CLASSIFIER_FILTER")
load("@platforms//host:constraints.bzl", _host_constraints = "HOST_CONSTRAINTS")
load("@rules_jvm_external//:defs.bzl", "maven_export")
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load("//shared/bazel/rules:transitions.bzl", "platform_transition_filegroup")
def _get_host_os():
if "@platforms//os:linux" in _host_constraints:
return "linux"
if "@platforms//os:osx" in _host_constraints:
return "osx"
if "@platforms//os:windows" in _host_constraints:
return "windows"
fail("Unsupported host OS. Must be one of linux, osx, or windows.")
HOST_OS = _get_host_os()
def publish_all(name, targets):
"""Macro to publish multiple maven artifacts with 1 call."""
publish_name = name + "_publish_all"
write_file(
name = publish_name,
out = publish_name + ".sh",
content = [
"#!/bin/bash",
"set -e",
"",
'for arg in "$@";',
"do",
' "$arg"',
"done",
],
)
sh_binary(
name = name,
srcs = [publish_name + ".sh"],
args = ["$(location " + x + ".publish)" for x in targets],
data = [x + ".publish" for x in targets],
)
# Unfortunately, rules_jvm_external really wants each of the classifier
# artifacts to have a unique name so they can go in the runfiles together and
# not collide.
def architectures_pkg_zip(
name,
compilation_modes = ["dbg", "opt"],
architectures = {
"@rules_bzlmodrio_toolchains//platforms/linux_x86_64": "linux-x86-64",
"@rules_bzlmodrio_toolchains//platforms/osx": "osxuniversal",
"@rules_bzlmodrio_toolchains//platforms/systemcore": "systemcore",
"@rules_bzlmodrio_toolchains//platforms/windows_arm64": "windows-arm64",
"@rules_bzlmodrio_toolchains//platforms/windows_x86_64": "windows-x86-64",
},
**kwargs):
architectures_target_compatible_with = {
"linux-x86-64": ["@platforms//os:linux"],
"osxuniversal": ["@platforms//os:osx"],
"systemcore": None,
"windows-arm64": ["@platforms//os:windows"],
"windows-x86-64": ["@platforms//os:windows"],
}
for compilation_mode in compilation_modes:
for platform, shortname in architectures.items():
zip_name = name + "-" + compilation_mode + "-arch-" + shortname
pkg_zip(
name = zip_name,
**kwargs
)
package_name = name + "-" + compilation_mode + "-" + shortname
platform_transition_filegroup(
name = package_name,
srcs = [":" + zip_name],
target_platform = platform,
compilation_mode = compilation_mode,
target_compatible_with = architectures_target_compatible_with[shortname],
)
def platform_prefix(t):
return select({
"@rules_bzlmodrio_toolchains//conditions:linux_x86_64": "linux/x86-64/" + t,
"@rules_bzlmodrio_toolchains//conditions:osx": "osx/universal/" + t,
"@rules_bzlmodrio_toolchains//conditions:windows_arm64": "windows/arm64/" + t,
"@rules_bzlmodrio_toolchains//conditions:windows_x86_64": "windows/x86-64/" + t,
"@rules_bzlmodrio_toolchains//constraints/is_roborio:roborio": "linux/roborio/" + t,
"@rules_bzlmodrio_toolchains//constraints/is_systemcore:systemcore": "linux/systemcore/" + t,
})
def _wpilib_maven_export_impl(
name,
maven_coordinates,
classifier_artifacts,
linux_artifacts,
osx_artifacts,
windows_artifacts,
lib_name = None,
visibility = None):
"""Implementation of wpilib_maven_export."""
all_artifacts = {}
all_artifacts.update(classifier_artifacts)
if HOST_OS == "linux":
all_artifacts.update(linux_artifacts)
elif HOST_OS == "osx":
all_artifacts.update(osx_artifacts)
elif HOST_OS == "windows":
all_artifacts.update(windows_artifacts)
if CLASSIFIER_FILTER:
allowed_classifiers = CLASSIFIER_FILTER.split(",")
filtered_artifacts = {
key: value
for key, value in all_artifacts.items()
if key in allowed_classifiers
}
else:
filtered_artifacts = all_artifacts
maven_export(
name = name,
maven_coordinates = maven_coordinates,
classifier_artifacts = filtered_artifacts,
lib_name = lib_name,
visibility = visibility,
)
wpilib_maven_export = macro(
implementation = _wpilib_maven_export_impl,
attrs = {
"classifier_artifacts": attr.string_keyed_label_dict(default = {}, configurable = False),
"lib_name": attr.string(configurable = False),
"linux_artifacts": attr.string_keyed_label_dict(default = {}, configurable = False),
"maven_coordinates": attr.string(mandatory = True, configurable = False),
"osx_artifacts": attr.string_keyed_label_dict(default = {}, configurable = False),
"windows_artifacts": attr.string_keyed_label_dict(default = {}, configurable = False),
},
doc = "A symbolic macro that wraps maven_export for wpilib.",
)

View File

@@ -0,0 +1,26 @@
# Copyright (c) FIRST and other WPILib contributors.
# Open Source Software; you can modify and/or share it under the terms of
# the WPILib BSD license file in the root directory of this project.
"""Bazel rule definition for publishing maven artifacts."""
def _publishing_repo_impl(repository_ctx):
"""Implementation of the publishing_repo rule."""
classifier_filter = repository_ctx.os.environ.get("WPI_PUBLISH_CLASSIFIER_FILTER", "")
content = """# Generated by publishing_repo rule. DO NOT EDIT.
CLASSIFIER_FILTER = "{classifier_filter}"
""".format(
classifier_filter = classifier_filter,
)
repository_ctx.file("publishing_config.bzl", content)
repository_ctx.file("BUILD.bazel", content = "# Generated file")
publishing_repo = repository_rule(
implementation = _publishing_repo_impl,
environ = ["WPI_PUBLISH_CLASSIFIER_FILTER"],
doc = "Repository rule to determine host OS and classifier filter for publishing. " +
"This rule must be instantiated in the WORKSPACE file with the name " +
"'com_wpilib_allwpilib_publishing_config'.",
)

View File

@@ -0,0 +1,54 @@
"Rules for working with transitions."
def _transition_platform_impl(_, attr):
return {
"//command_line_option:compilation_mode": attr.compilation_mode,
"//command_line_option:platforms": str(attr.target_platform),
}
# Transition from any input configuration to one that includes the
# --platforms command-line flag.
_transition_platform = transition(
implementation = _transition_platform_impl,
inputs = [],
outputs = [
"//command_line_option:platforms",
"//command_line_option:compilation_mode",
],
)
def _platform_transition_filegroup_impl(ctx):
files = []
runfiles = ctx.runfiles()
for src in ctx.attr.srcs:
files.append(src[DefaultInfo].files)
runfiles = runfiles.merge_all([src[DefaultInfo].default_runfiles for src in ctx.attr.srcs])
return [DefaultInfo(
files = depset(transitive = files),
runfiles = runfiles,
)]
platform_transition_filegroup = rule(
_platform_transition_filegroup_impl,
attrs = {
"compilation_mode": attr.string(
doc = "The compilation mode to transition the srcs.",
mandatory = True,
),
"srcs": attr.label_list(
allow_empty = False,
cfg = _transition_platform,
doc = "The input to be transitioned to the target platform.",
),
"target_platform": attr.label(
doc = "The target platform to transition the srcs.",
mandatory = True,
),
# Required to Opt-in to the transitions feature.
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
doc = "Transitions the srcs to use the provided platform. The filegroup will contain artifacts for the target platform.",
)