mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[build] MVP for building with bazel (#6994)
This commit is contained in:
28
shared/bazel/compiler_flags/base_linux_flags.rc
Normal file
28
shared/bazel/compiler_flags/base_linux_flags.rc
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
###############################
|
||||
# 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'
|
||||
5
shared/bazel/compiler_flags/coverage_flags.rc
Normal file
5
shared/bazel/compiler_flags/coverage_flags.rc
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
coverage --combined_report=lcov
|
||||
coverage --build_tests_only
|
||||
coverage --cache_test_results=no
|
||||
coverage --coverage_report_generator=@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main
|
||||
14
shared/bazel/compiler_flags/linux_flags.rc
Normal file
14
shared/bazel/compiler_flags/linux_flags.rc
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
###############################
|
||||
# Linux
|
||||
###############################
|
||||
build:linux --config=base_linux
|
||||
|
||||
# Warning level
|
||||
build:linux --copt=-Wall
|
||||
build:linux --copt=-Wextra
|
||||
build:linux --copt=-Werror
|
||||
|
||||
# Not in nativetools
|
||||
build:linux --cxxopt=-Wno-deprecated-enum-enum-conversion
|
||||
44
shared/bazel/compiler_flags/osx_flags.rc
Normal file
44
shared/bazel/compiler_flags/osx_flags.rc
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
# Warning level
|
||||
build:macos --copt=-Wall
|
||||
build:macos --copt=-Wextra
|
||||
build:macos --copt=-Werror
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
# 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"
|
||||
|
||||
|
||||
build:macos --linkopt=-framework
|
||||
build:macos --linkopt=CoreFoundation
|
||||
build:macos --linkopt=-framework
|
||||
build:macos --linkopt=AVFoundation
|
||||
build:macos --linkopt=-framework
|
||||
build:macos --linkopt=Foundation
|
||||
build:macos --linkopt=-framework
|
||||
build:macos --linkopt=CoreMedia
|
||||
build:macos --linkopt=-framework
|
||||
build:macos --linkopt=CoreVideo
|
||||
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
|
||||
16
shared/bazel/compiler_flags/roborio_flags.rc
Normal file
16
shared/bazel/compiler_flags/roborio_flags.rc
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
###############################
|
||||
# Roborio
|
||||
###############################
|
||||
build:roborio --config=base_linux
|
||||
|
||||
build:roborio --platforms=@rules_bzlmodrio_toolchains//platforms/roborio
|
||||
build:roborio --build_tag_filters=-no-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
|
||||
27
shared/bazel/compiler_flags/sanitizers.rc
Normal file
27
shared/bazel/compiler_flags/sanitizers.rc
Normal file
@@ -0,0 +1,27 @@
|
||||
# ASAN (address sanitizer) config
|
||||
build:asan --copt -fsanitize=address
|
||||
build:asan --copt -fno-omit-frame-pointer
|
||||
build:asan --linkopt -fsanitize=address
|
||||
build:asan --build_tests_only
|
||||
build:asan --test_tag_filters=-no-asan
|
||||
|
||||
# TSAN (thread sanitizer)
|
||||
build:tsan --strip=never
|
||||
build:tsan --copt -fsanitize=thread
|
||||
build:tsan --copt -DTHREAD_SANITIZER
|
||||
build:tsan --copt -DDYNAMIC_ANNOTATIONS_ENABLED=1
|
||||
build:tsan --copt -DDYNAMIC_ANNOTATIONS_EXTERNAL_IMPL=1
|
||||
build:tsan --copt -O1
|
||||
build:tsan --copt -fno-omit-frame-pointer
|
||||
build:tsan --linkopt -fsanitize=thread
|
||||
build:tsan --build_tests_only
|
||||
build:tsan --test_tag_filters=-no-tsan
|
||||
|
||||
# USAN (Undefined Behavior Sanitizer)
|
||||
build:ubsan --copt -fsanitize=undefined
|
||||
build:ubsan --copt -fno-sanitize-recover=all
|
||||
build:ubsan --copt -fno-omit-frame-pointer
|
||||
build:ubsan --linkopt -fsanitize=undefined
|
||||
build:ubsan --linkopt -fno-sanitize-recover=all
|
||||
build:ubsan --build_tests_only
|
||||
build:ubsan --test_tag_filters=-no-ubsan
|
||||
53
shared/bazel/compiler_flags/windows_flags.rc
Normal file
53
shared/bazel/compiler_flags/windows_flags.rc
Normal file
@@ -0,0 +1,53 @@
|
||||
################################
|
||||
# Common Flags
|
||||
################################
|
||||
# Warning level
|
||||
build:windows_common --copt=/W3
|
||||
build:windows_common --copt=/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
|
||||
|
||||
# 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
|
||||
|
||||
################################
|
||||
# Standard Windows Flags
|
||||
################################
|
||||
build:windows --config=windows_common
|
||||
|
||||
build:windows --linkopt=/DEPENDENTLOADFLAG:0x1100
|
||||
|
||||
# TODO
|
||||
build:windows --copt=/D_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR
|
||||
|
||||
################################
|
||||
# ARM Windows Flags
|
||||
################################
|
||||
build:windows_arm --config=windows_common
|
||||
|
||||
build:windows_arm --cpu=arm64_windows
|
||||
|
||||
build:windows_arm --linkopt=/IGNORE:4099
|
||||
8
shared/bazel/rules/gen/BUILD.bazel
Normal file
8
shared/bazel/rules/gen/BUILD.bazel
Normal file
@@ -0,0 +1,8 @@
|
||||
load("@rules_python//python:defs.bzl", "py_binary")
|
||||
|
||||
py_binary(
|
||||
name = "gen_resources",
|
||||
srcs = ["gen_resources.py"],
|
||||
tags = ["manual"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
10
shared/bazel/rules/gen/gen-resources.bzl
Normal file
10
shared/bazel/rules/gen/gen-resources.bzl
Normal file
@@ -0,0 +1,10 @@
|
||||
def generate_resources(name, resource_files, prefix, namespace, visibility = None):
|
||||
cmd = "$(locations //shared/bazel/rules/gen:gen_resources) --prefix={} --namespace={} --resources $(SRCS) --output_files $(OUTS)".format(prefix, namespace, resource_files)
|
||||
native.genrule(
|
||||
name = name,
|
||||
srcs = resource_files,
|
||||
outs = ["{}.cpp".format(input_file) for input_file in resource_files],
|
||||
cmd = cmd,
|
||||
tools = ["//shared/bazel/rules/gen:gen_resources"],
|
||||
visibility = visibility,
|
||||
)
|
||||
19
shared/bazel/rules/gen/gen-version-file.bzl
Normal file
19
shared/bazel/rules/gen/gen-version-file.bzl
Normal file
@@ -0,0 +1,19 @@
|
||||
def _generate_version_file_impl(ctx):
|
||||
out = ctx.actions.declare_file(ctx.attr.output_file)
|
||||
ctx.actions.expand_template(
|
||||
output = out,
|
||||
template = ctx.file.template,
|
||||
substitutions = {"${wpilib_version}": "TODO - Built with bazel"},
|
||||
)
|
||||
return [DefaultInfo(files = depset([out]))]
|
||||
|
||||
generate_version_file = rule(
|
||||
implementation = _generate_version_file_impl,
|
||||
attrs = {
|
||||
"output_file": attr.string(mandatory = True),
|
||||
"template": attr.label(
|
||||
allow_single_file = True,
|
||||
mandatory = True,
|
||||
),
|
||||
},
|
||||
)
|
||||
58
shared/bazel/rules/gen/gen_resources.py
Normal file
58
shared/bazel/rules/gen/gen_resources.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import os
|
||||
import argparse
|
||||
import binascii
|
||||
|
||||
|
||||
def generate_file(resource_file, output_file, prefix, namespace):
|
||||
func_name = "GetResource_" + os.path.basename(resource_file).replace(
|
||||
"-", "_"
|
||||
).replace(".", "_")
|
||||
|
||||
with open(resource_file, "rb") as f:
|
||||
raw_data = f.read()
|
||||
hex = str(binascii.hexlify(raw_data), "ascii")
|
||||
data = ", ".join("0x" + hex[i : i + 2] for i in range(0, len(hex), 2))
|
||||
data_size = len(raw_data)
|
||||
|
||||
output = """#include <stddef.h>
|
||||
#include <string_view>
|
||||
extern "C" {{
|
||||
static const unsigned char contents[] = {{ {data} }};
|
||||
const unsigned char* {prefix}_{func_name}(size_t* len) {{
|
||||
*len = {data_size};
|
||||
return contents;
|
||||
}}
|
||||
}}
|
||||
namespace {namespace} {{
|
||||
std::string_view {func_name}() {{
|
||||
return std::string_view(reinterpret_cast<const char*>(contents), {data_size});
|
||||
}}
|
||||
}}
|
||||
""".format(
|
||||
func_name=func_name,
|
||||
data_size=data_size,
|
||||
prefix=prefix,
|
||||
data=data,
|
||||
namespace=namespace,
|
||||
)
|
||||
|
||||
with open(output_file, "w") as f:
|
||||
f.write(output)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--namespace")
|
||||
parser.add_argument("--prefix")
|
||||
parser.add_argument("--resources", nargs="+")
|
||||
parser.add_argument("--output_files", nargs="+")
|
||||
|
||||
args = parser.parse_args()
|
||||
assert len(args.resources) == len(args.output_files)
|
||||
|
||||
for i, resource in enumerate(args.resources):
|
||||
generate_file(resource, args.output_files[i], args.prefix, args.namespace)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user