mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[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:
9
.bazelrc
9
.bazelrc
@@ -2,6 +2,8 @@ try-import %workspace%/bazel_auth.rc
|
||||
try-import %workspace%/user.bazelrc
|
||||
|
||||
common --noenable_bzlmod
|
||||
# Resolves to --config=linux on Linux, --config=macos on Mac, --windows on windows
|
||||
common --enable_platform_specific_config
|
||||
|
||||
# Make bazel 8 work for us.
|
||||
common --enable_workspace
|
||||
@@ -17,7 +19,6 @@ test --test_output=errors
|
||||
test --test_verbose_timeout_warnings
|
||||
|
||||
import %workspace%/shared/bazel/compiler_flags/sanitizers.rc
|
||||
import %workspace%/shared/bazel/compiler_flags/base_linux_flags.rc
|
||||
import %workspace%/shared/bazel/compiler_flags/linux_flags.rc
|
||||
import %workspace%/shared/bazel/compiler_flags/osx_flags.rc
|
||||
import %workspace%/shared/bazel/compiler_flags/roborio_flags.rc
|
||||
@@ -60,3 +61,9 @@ build:ci --config=build_buddy
|
||||
build:ci --remote_download_minimal
|
||||
|
||||
build --build_metadata=REPO_URL=https://github.com/wpilibsuite/allwpilib.git
|
||||
|
||||
common --define="WPILIB_VERSION=2025.424242.3.1-unknown"
|
||||
|
||||
# List of artifact types to build in CI.
|
||||
# Anything else gets skipped to speed up CI.
|
||||
common:ci --repo_env="WPI_PUBLISH_CLASSIFIER_FILTER=headers,sources,linuxsystemcore,linuxsystemcoredebug,linuxsystemcorestatic,linuxsystemcorestaticdebug,linuxx86-64,linuxx86-64debug,linuxx86-64static,linuxx86-64staticdebug,osxuniversal,osxuniversaldebug,osxuniversalstatic,osxuniversalstaticdebug,windowsarm64,windowsarm64debug,windowsarm64static,windowsarm64staticdebug,windowsx86-64,windowsx86-64debug,windowsx86-64static,windowsx86-64staticdebug"
|
||||
|
||||
5
.github/workflows/bazel.yml
vendored
5
.github/workflows/bazel.yml
vendored
@@ -48,7 +48,7 @@ jobs:
|
||||
token: ${{ secrets.BUILDBUDDY_API_KEY }}
|
||||
|
||||
- name: bazel test (release)
|
||||
run: bazel test -k ... --config=ci -c opt --config=macos --nojava_header_compilation --verbose_failures
|
||||
run: bazel test -k ... --config=ci -c opt --nojava_header_compilation --verbose_failures
|
||||
shell: bash
|
||||
|
||||
build-linux:
|
||||
@@ -56,8 +56,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- { name: "Linux (native)", os: ubuntu-24.04, container: "wpilib/ubuntu-base:24.04", action: "test", config: "--config=linux", }
|
||||
- { name: "Linux (systemcore)", os: ubuntu-24.04, container: "wpilib/ubuntu-base:24.04", action: "build", config: "--config=systemcore", }
|
||||
- { name: "Linux", os: ubuntu-24.04, container: "wpilib/ubuntu-base:24.04", action: "test", config: "", }
|
||||
name: "${{ matrix.name }}"
|
||||
runs-on: ${{ matrix.os }}
|
||||
container: ${{ matrix.container }}
|
||||
|
||||
@@ -24,6 +24,15 @@ Examples:
|
||||
build --local_cpu_resources=HOST_CPUS-1 # Leave one core alone
|
||||
```
|
||||
|
||||
The default settings build all the release artifact variants relevant for your platform. The overall list of options ends up being, essentially, all the variants of (linux, osx, windows) x (debug, release) x (static, shared) x (aarch64, x86). OSX and Windows are hard to compile for from any other OS, so we by default build for your local OS and the system core, with all the variants.
|
||||
|
||||
This can be a bit expensive. If you would like to build a subset, you can specify the repo environmental variable, `WPI_PUBLISH_CLASSIFIER_FILTER`, and pick what you build for. The default is, in the .bazelrc file,
|
||||
```
|
||||
common --repo_env="WPI_PUBLISH_CLASSIFIER_FILTER=headers,sources,linuxsystemcore,linuxsystemcoredebug,linuxsystemcorestatic,linuxsystemcorestaticdebug,linuxx86-64,linuxx86-64debug,linuxx86-64static,linuxx86-64staticdebug,osxuniversal,osxuniversaldebug,osxuniversalstatic,osxuniversalstaticdebug,windowsarm64,windowsarm64debug,windowsarm64static,windowsarm64staticdebug,windowsx86-64,windowsx86-64debug,windowsx86-64static,windowsx86-64staticdebug"
|
||||
```
|
||||
|
||||
Modify this to your likings if you want to build less.
|
||||
|
||||
## Pregenerating Files
|
||||
allwpilib uses extensive use of pre-generating files that are later used to build C++ / Java libraries that are tracked by version control. Quite often,
|
||||
these pre-generation scripts use some configuration file to create multipile files inside of an output directory. While this process could be accomplished
|
||||
|
||||
20
WORKSPACE
20
WORKSPACE
@@ -7,17 +7,26 @@ http_archive(
|
||||
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.31.0/bazel_features-v1.31.0.tar.gz",
|
||||
)
|
||||
|
||||
# TODO(austin): Upgrade when the patches land.
|
||||
# https://github.com/bazelbuild/rules_cc/pull/430
|
||||
# https://github.com/bazelbuild/rules_cc/pull/431
|
||||
# https://github.com/bazelbuild/rules_cc/pull/432
|
||||
http_archive(
|
||||
name = "rules_cc",
|
||||
patch_args = ["-p1"],
|
||||
patches = ["//:shared/bazel/patches/rules_cc_windows.patch"],
|
||||
sha256 = "712d77868b3152dd618c4d64faaddefcc5965f90f5de6e6dd1d5ddcd0be82d42",
|
||||
strip_prefix = "rules_cc-0.1.1",
|
||||
url = "https://github.com/bazelbuild/rules_cc/releases/download/0.1.1/rules_cc-0.1.1.tar.gz",
|
||||
)
|
||||
|
||||
# TODO(austinschuh): Update to the next released apple_support once it lands.
|
||||
# This needs to contain https://github.com/bazelbuild/apple_support/commit/7009b77c98a67d3fea081c9db4dbcee8effc3b7e and should be the next release after 1.22.1
|
||||
http_archive(
|
||||
name = "build_bazel_apple_support",
|
||||
sha256 = "b265beacfa477081caaf2bd05978ee7d11fdb8c202a1b76d0ef28d901d1e7b33",
|
||||
url = "https://github.com/bazelbuild/apple_support/releases/download/1.22.0/apple_support.1.22.0.tar.gz",
|
||||
sha256 = "7d542be113180bc1da3660e51fe4792a867fb85537c9ef36a0d3366665a76803",
|
||||
strip_prefix = "apple_support-7009b77c98a67d3fea081c9db4dbcee8effc3b7e",
|
||||
url = "https://github.com/bazelbuild/apple_support/archive/7009b77c98a67d3fea081c9db4dbcee8effc3b7e.tar.gz",
|
||||
)
|
||||
|
||||
http_archive(
|
||||
@@ -354,3 +363,10 @@ rules_proto_setup()
|
||||
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
|
||||
|
||||
rules_pkg_dependencies()
|
||||
|
||||
# Capture the repository environmental variables which specify the filter list for what architectures to build in CI.
|
||||
load("//shared/bazel/rules:publishing_rule.bzl", "publishing_repo")
|
||||
|
||||
publishing_repo(
|
||||
name = "com_wpilib_allwpilib_publishing_config",
|
||||
)
|
||||
|
||||
@@ -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'
|
||||
@@ -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
|
||||
|
||||
@@ -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'"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
524
shared/bazel/patches/rules_cc_windows.patch
Normal file
524
shared/bazel/patches/rules_cc_windows.patch
Normal 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],
|
||||
)
|
||||
@@ -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(
|
||||
|
||||
@@ -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):
|
||||
|
||||
142
shared/bazel/rules/publishing.bzl
Normal file
142
shared/bazel/rules/publishing.bzl
Normal 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.",
|
||||
)
|
||||
26
shared/bazel/rules/publishing_rule.bzl
Normal file
26
shared/bazel/rules/publishing_rule.bzl
Normal 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'.",
|
||||
)
|
||||
54
shared/bazel/rules/transitions.bzl
Normal file
54
shared/bazel/rules/transitions.bzl
Normal 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.",
|
||||
)
|
||||
@@ -2,12 +2,14 @@ load("@allwpilib_pip_deps//:requirements.bzl", "requirement")
|
||||
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
|
||||
load("@rules_java//java:defs.bzl", "java_binary")
|
||||
load("@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files")
|
||||
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
|
||||
load("@rules_python//python:defs.bzl", "py_binary")
|
||||
load("//shared/bazel/rules:cc_rules.bzl", "third_party_cc_lib_helper", "wpilib_cc_library", "wpilib_cc_shared_library", "wpilib_cc_static_library")
|
||||
load("//shared/bazel/rules:java_rules.bzl", "wpilib_java_junit5_test")
|
||||
load("//shared/bazel/rules:jni_rules.bzl", "wpilib_jni_cc_library", "wpilib_jni_java_library")
|
||||
load("//shared/bazel/rules:packaging.bzl", "pkg_java_files")
|
||||
load("//shared/bazel/rules:publishing.bzl", "architectures_pkg_zip", "platform_prefix", "wpilib_maven_export")
|
||||
load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources")
|
||||
load("//wpiutil:generate.bzl", "generate_wpiutil")
|
||||
|
||||
@@ -229,6 +231,7 @@ wpilib_jni_java_library(
|
||||
name = "wpiutil-java",
|
||||
srcs = glob(["src/main/java/**/*.java"]),
|
||||
native_libs = [":wpiutiljni"],
|
||||
tags = ["maven_coordinates=edu.wpi.first.wpiutil:wpiutil-java:$(WPILIB_VERSION)"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"@maven//:com_fasterxml_jackson_core_jackson_annotations",
|
||||
@@ -301,3 +304,81 @@ java_binary(
|
||||
":wpiutil-java",
|
||||
],
|
||||
)
|
||||
|
||||
pkg_files(
|
||||
name = "wpiutil-static-files",
|
||||
srcs = [
|
||||
":static/wpiutil",
|
||||
],
|
||||
prefix = platform_prefix("static"),
|
||||
strip_prefix = "static",
|
||||
)
|
||||
|
||||
pkg_filegroup(
|
||||
name = "wpiutil-shared-files",
|
||||
srcs = [
|
||||
":shared/libwpiutil-shared-files",
|
||||
":shared/libwpiutiljni-shared-files",
|
||||
],
|
||||
prefix = platform_prefix("shared"),
|
||||
)
|
||||
|
||||
architectures_pkg_zip(
|
||||
name = "wpiutil_static_zip",
|
||||
srcs = [
|
||||
":wpiutil-static-files",
|
||||
"//:license_pkg_files",
|
||||
],
|
||||
)
|
||||
|
||||
architectures_pkg_zip(
|
||||
name = "wpiutil_shared_zip",
|
||||
srcs = [
|
||||
":wpiutil-shared-files",
|
||||
"//:license_pkg_files",
|
||||
],
|
||||
)
|
||||
|
||||
wpilib_maven_export(
|
||||
name = "wpiutil-cpp_publish",
|
||||
classifier_artifacts = {
|
||||
"headers": ":wpiutil-hdrs-zip",
|
||||
"linuxsystemcore": ":wpiutil_shared_zip-opt-systemcore",
|
||||
"linuxsystemcoredebug": ":wpiutil_shared_zip-dbg-systemcore",
|
||||
"linuxsystemcorestatic": ":wpiutil_static_zip-opt-systemcore",
|
||||
"linuxsystemcorestaticdebug": ":wpiutil_static_zip-dbg-systemcore",
|
||||
"sources": ":wpiutil-srcs-zip",
|
||||
},
|
||||
linux_artifacts = {
|
||||
"linuxx86-64": ":wpiutil_shared_zip-opt-linux-x86-64",
|
||||
"linuxx86-64debug": ":wpiutil_shared_zip-dbg-linux-x86-64",
|
||||
"linuxx86-64static": ":wpiutil_static_zip-opt-linux-x86-64",
|
||||
"linuxx86-64staticdebug": ":wpiutil_static_zip-dbg-linux-x86-64",
|
||||
},
|
||||
maven_coordinates = "edu.wpi.first.wpiutil:wpiutil-cpp:$(WPILIB_VERSION)",
|
||||
osx_artifacts = {
|
||||
"osxuniversal": ":wpiutil_shared_zip-opt-osxuniversal",
|
||||
"osxuniversaldebug": ":wpiutil_shared_zip-dbg-osxuniversal",
|
||||
"osxuniversalstatic": ":wpiutil_static_zip-opt-osxuniversal",
|
||||
"osxuniversalstaticdebug": ":wpiutil_static_zip-dbg-osxuniversal",
|
||||
},
|
||||
visibility = ["//visibility:public"],
|
||||
windows_artifacts = {
|
||||
"windowsarm64": ":wpiutil_shared_zip-opt-windows-arm64",
|
||||
"windowsarm64debug": ":wpiutil_shared_zip-dbg-windows-arm64",
|
||||
"windowsarm64static": ":wpiutil_static_zip-opt-windows-arm64",
|
||||
"windowsarm64staticdebug": ":wpiutil_static_zip-dbg-windows-arm64",
|
||||
"windowsx86-64": ":wpiutil_shared_zip-opt-windows-x86-64",
|
||||
"windowsx86-64debug": ":wpiutil_shared_zip-dbg-windows-x86-64",
|
||||
"windowsx86-64static": ":wpiutil_static_zip-opt-windows-x86-64",
|
||||
"windowsx86-64staticdebug": ":wpiutil_static_zip-dbg-windows-x86-64",
|
||||
},
|
||||
)
|
||||
|
||||
wpilib_maven_export(
|
||||
name = "wpiutil-java_publish",
|
||||
classifier_artifacts = {"sources": ":libwpiutil-java-sources.jar"},
|
||||
lib_name = "wpiutil-java",
|
||||
maven_coordinates = "edu.wpi.first.wpiutil:wpiutil-java:$(WPILIB_VERSION)",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user