diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 00000000000..792570baee3 --- /dev/null +++ b/.bazelignore @@ -0,0 +1,20 @@ +build_cmake +build-cmake + +# Auto generated by vscode +apriltag/bin +cameraserver/bin +cameraserver/multiCameraServer/bin +cscore/bin +fieldImages/bin +hal/bin +developerRobot/bin +ntcore/bin +romiVendordep/bin +wpilibNewCommands/bin +wpilibj/bin +wpimath/bin +wpinet/bin +wpiutil/bin +wpiunits/bin +xrpVendordep/bin diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000000..051ff924bd8 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,51 @@ +try-import %workspace%/bazel_auth.rc +try-import %workspace%/user.bazelrc + +common --noenable_bzlmod + +build --java_language_version=17 +build --java_runtime_version=roboriojdk_17 +build --tool_java_language_version=17 +build --tool_java_runtime_version=remotejdk_17 + +test --test_output=errors +test --test_verbose_timeout_warnings + +import shared/bazel/compiler_flags/sanitizers.rc +import shared/bazel/compiler_flags/base_linux_flags.rc +import shared/bazel/compiler_flags/linux_flags.rc +import shared/bazel/compiler_flags/osx_flags.rc +import shared/bazel/compiler_flags/roborio_flags.rc +import shared/bazel/compiler_flags/windows_flags.rc +import shared/bazel/compiler_flags/coverage_flags.rc + +build:build_java --test_tag_filters=allwpilib-build-java --build_tag_filters=allwpilib-build-java +build:build_cpp --test_tag_filters=+allwpilib-build-cpp --build_tag_filters=+allwpilib-build-cpp +build:no_example --test_tag_filters=-wpi-example --build_tag_filters=-wpi-example +test:no_example --test_tag_filters=-wpi-example --build_tag_filters=-wpi-example + +# Build Buddy Cache Setup +build:build_buddy --bes_results_url=https://app.buildbuddy.io/invocation/ +build:build_buddy --bes_backend=grpcs://remote.buildbuddy.io +build:build_buddy --remote_cache=grpcs://remote.buildbuddy.io +build:build_buddy --remote_timeout=3600 + +# Additional suggestions from buildbuddy for speed +build:build_buddy --experimental_remote_cache_compression +build:build_buddy --experimental_remote_cache_compression_threshold=100 +build:build_buddy --noslim_profile +build:build_buddy --experimental_profile_include_target_label +build:build_buddy --experimental_profile_include_primary_output +build:build_buddy --nolegacy_important_outputs + +build:build_buddy_readonly --noremote_upload_local_results + +# This config should be used locally. It downloads more than the CI version +build:remote_user --config=build_buddy +build:remote_user --config=build_buddy_readonly +build:remote_user --remote_download_toplevel + +build:ci --config=build_buddy +build:ci --remote_download_minimal + +build --build_metadata=REPO_URL=https://github.com/wpilibsuite/allwpilib.git diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 00000000000..643916c03f1 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +7.3.1 diff --git a/.github/actions/setup-build-buddy/action.yml b/.github/actions/setup-build-buddy/action.yml new file mode 100644 index 00000000000..423398a0534 --- /dev/null +++ b/.github/actions/setup-build-buddy/action.yml @@ -0,0 +1,27 @@ +name: 'Setup BuildBuddy acache' +description: 'Sets up the build buddy cache to be readonly / writing based on the presence of environment variables' + +inputs: + token: + description: 'Build Buddy API token' + +runs: + using: "composite" + steps: + - name: Setup without key + env: + API_KEY: ${{ inputs.token }} + if: ${{ env.API_KEY == '' }} + shell: bash + run: | + echo "No API key secret detected, will setup readonly cache" + echo "build:ci --config=build_buddy_readonly" > bazel_auth.rc + + - name: Set with key + env: + API_KEY: ${{ inputs.token }} + if: ${{ env.API_KEY != '' }} + shell: bash + run: | + echo "API Key detected!" + echo "build:build_buddy --remote_header=x-buildbuddy-api-key=${{ env.API_KEY }}" > bazel_auth.rc diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml new file mode 100644 index 00000000000..98eb166b837 --- /dev/null +++ b/.github/workflows/bazel.yml @@ -0,0 +1,149 @@ +name: Bazel + +on: [pull_request, push] + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + build-windows: + strategy: + fail-fast: false + matrix: + include: + - { name: "Windows (native)", os: windows-2022, action: "test", config: "--config=windows", } + - { name: "Windows (arm)", os: windows-2022, action: "build", config: "--config=windows_arm", } + - { name: "Windows (roborio)", os: windows-2022, action: "build", config: "--config=roborio", } + + name: "Build ${{ matrix.name }}" + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: { fetch-depth: 0 } + - uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 17 + architecture: x64 + + - id: Setup_build_buddy + uses: ./.github/actions/setup-build-buddy + with: + token: ${{ secrets.BUILDBUDDY_API_KEY }} + + - name: Build Release + run: bazel --output_user_root=C:\\bazelroot ${{ matrix.action }} -k ... --config=ci -c opt ${{ matrix.config }} --verbose_failures + shell: bash + + - name: Build Debug + run: bazel --output_user_root=C:\\bazelroot ${{ matrix.action }} -k ... --config=ci -c dbg ${{ matrix.config }} --verbose_failures + shell: bash + + build-mac: + strategy: + fail-fast: false + matrix: + include: + - { name: "Mac (native)", os: macos-14, action: "test", config: "--config=macos", } + - { name: "Mac (roborio)", os: macos-14, action: "build", config: "--config=roborio", } + + name: "${{ matrix.name }}" + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: { fetch-depth: 0 } + + - id: Setup_build_buddy + uses: ./.github/actions/setup-build-buddy + with: + token: ${{ secrets.BUILDBUDDY_API_KEY }} + + - name: Build Release + run: bazel ${{ matrix.action }} -k ... --config=ci -c opt ${{ matrix.config }} --nojava_header_compilation --verbose_failures + shell: bash + + - name: Build Debug + run: bazel ${{ matrix.action }} -k ... --config=ci -c dbg ${{ matrix.config }} --nojava_header_compilation --verbose_failures + shell: bash + + build-linux: + strategy: + fail-fast: false + matrix: + include: + - { name: "Linux (native)", os: ubuntu-22.04, action: "test", config: "--config=linux", } + - { name: "Linux (roborio)", os: ubuntu-22.04, action: "build", config: "--config=roborio", } + name: "${{ matrix.name }}" + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: { fetch-depth: 0 } + - uses: bazelbuild/setup-bazelisk@v3 + + - id: Setup_build_buddy + uses: ./.github/actions/setup-build-buddy + with: + token: ${{ secrets.BUILDBUDDY_API_KEY }} + + - name: Build and Test Release + run: bazel ${{ matrix.action }} ... --config=ci -c opt ${{ matrix.config }} -k --verbose_failures + + - name: Build and Test Debug + run: bazel ${{ matrix.action }} ... --config=ci -c dbg ${{ matrix.config }} -k --verbose_failures + + build-sanitizers: + strategy: + fail-fast: false + matrix: + include: + - config: "asan" + - config: "ubsan" + runs-on: ubuntu-22.04 + name: "Sanitizer ${{ matrix.config }}" + steps: + - uses: actions/checkout@v4 + with: { fetch-depth: 0 } + - uses: bazelbuild/setup-bazelisk@v3 + + - id: Setup_build_buddy + uses: ./.github/actions/setup-build-buddy + with: + token: ${{ secrets.BUILDBUDDY_API_KEY }} + + - name: Build and Test + run: bazel test -k --config=ci --config=linux --config=${{ matrix.config }} //... + + buildifier: + name: "buildifier" + runs-on: ubuntu-22.04 + steps: + - name: Set up Go 1.15.x + uses: actions/setup-go@v5 + with: + go-version: 1.15.x + id: go + + - name: Install Buildifier + run: | + cd $(mktemp -d) + GO111MODULE=on go get github.com/bazelbuild/buildtools/buildifier@6.0.0 + + - uses: actions/checkout@v4 + with: { fetch-depth: 0 } + + - name: Run buildifier + run: buildifier -warnings all --lint=fix -r . + + - name: Check Output + run: git --no-pager diff --exit-code HEAD + + - name: Generate diff + run: git diff HEAD > bazel-lint-fixes.patch + if: ${{ failure() }} + + - uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.platform }}-bazel-lint-fixes + path: bazel-lint-fixes.patch + if: ${{ failure() }} diff --git a/.github/workflows/upstream-utils.yml b/.github/workflows/upstream-utils.yml index bd8ebb75a06..c9cd4d681c1 100644 --- a/.github/workflows/upstream-utils.yml +++ b/.github/workflows/upstream-utils.yml @@ -133,4 +133,4 @@ jobs: - name: Add untracked files to index so they count as changes run: git add -A - name: Check output - run: git --no-pager diff --exit-code HEAD + run: git --no-pager diff --exit-code HEAD ':!*.bazel' diff --git a/.gitignore b/.gitignore index 333895f9f39..ff4b8ff2265 100644 --- a/.gitignore +++ b/.gitignore @@ -249,6 +249,7 @@ imgui.ini /bazel-* user.bazelrc coverage_report/ +bazel_auth.rc # ctest /Testing/ diff --git a/README-Bazel.md b/README-Bazel.md new file mode 100644 index 00000000000..2a3bb45b756 --- /dev/null +++ b/README-Bazel.md @@ -0,0 +1,25 @@ +# WPILib Bazel Support + +WPILib is normally built with Gradle, but [Bazel](https://www.bazel.build/) can also be used to increase development speed due to the superior caching ability and the ability to use remote caching and remote execution (on select platforms) + + +## Prerequisites +- Install [Bazelisk](https://github.com/bazelbuild/bazelisk/releases) and add it to your path. Bazelisk is a wrapper that will download the correct version of bazel specified in the repository. Note: You can alias/rename the binary to `bazel` if you want to keep the familiar `bazel build` vs `bazelisk build` syntax. + +## Building +To build the entire repository, simply run `bazel build //...`. To run all of the unit tests, run `bazel test //...` +Other examples: +- `bazel build //wpimath/...` - Builds every target in the wpimath folder +- `bazel test //wpiutil:wpiutil-cpp-test` - Runs only the cpp test target in the wpiutil folder +- `bazel coverage //wpiutil/...` - (*Nix only) - Runs a code coverage report for both C++ and Java on all the targets under wpiutil + +## User settings +When invoking bazel, it will check if `user.bazelrc` exists for additional, user specified flags. You can use these settings to do things like always ignore buildin a specific folder, or limiting the CPU/RAM usage during a build. +Examples: +- `build --build_tag_filters=-wpi-example` - Do not build any targets tagged with `wpi-example` (Currently all of the targets in wpilibcExamples and wpilibjExamples contain this tag) +- `build -c opt` - Always build optimized targets. The default compiler flags were chosen to build as fast as possible, and thus don't contain many optimizations +- `build -k` - `-k` is analogous to the MAKE flag `--keep-going`, so the build will not stop on the first error. +- ``` + build --local_ram_resources=HOST_RAM*.5 # Don't use more than half my RAM when building + build --local_cpu_resources=HOST_CPUS-1 # Leave one core alone + ``` diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 00000000000..602b2ed4297 --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,100 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +# Download Extra java rules +http_archive( + name = "rules_jvm_external", + sha256 = "08ea921df02ffe9924123b0686dc04fd0ff875710bfadb7ad42badb931b0fd50", + strip_prefix = "rules_jvm_external-6.1", + url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/6.1/rules_jvm_external-6.1.tar.gz", +) + +load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps") + +rules_jvm_external_deps() + +load("@rules_jvm_external//:defs.bzl", "maven_install") + +maven_artifacts = [ + "org.ejml:ejml-simple:0.43.1", + "com.fasterxml.jackson.core:jackson-annotations:2.15.2", + "com.fasterxml.jackson.core:jackson-core:2.15.2", + "com.fasterxml.jackson.core:jackson-databind:2.15.2", + "us.hebi.quickbuf:quickbuf-runtime:1.3.3", + "com.google.code.gson:gson:2.10.1", +] + +maven_install( + name = "maven", + artifacts = maven_artifacts, + repositories = [ + "https://repo1.maven.org/maven2", + "https://frcmaven.wpi.edu/artifactory/release/", + ], +) + +# Download toolchains +http_archive( + name = "rules_bzlmodrio_toolchains", + sha256 = "2ef1cafce7f4fd4e909bb5de8b0dc771a934646afd55d5f100ff31f6b500df98", + url = "https://github.com/wpilibsuite/rules_bzlmodRio_toolchains/releases/download/2024-1.bcr1/rules_bzlmodRio_toolchains-2024-1.bcr1.tar.gz", +) + +load("@rules_bzlmodrio_toolchains//:maven_deps.bzl", "setup_legacy_setup_toolchains_dependencies") + +setup_legacy_setup_toolchains_dependencies() + +load("@rules_bzlmodrio_toolchains//toolchains:load_toolchains.bzl", "load_toolchains") + +load_toolchains() + +# +http_archive( + name = "rules_bzlmodrio_jdk", + sha256 = "a00d5fa971fbcad8a17b1968cdc5350688397035e90b0cb94e040d375ecd97b4", + url = "https://github.com/wpilibsuite/rules_bzlmodRio_jdk/releases/download/17.0.8.1-1/rules_bzlmodRio_jdk-17.0.8.1-1.tar.gz", +) + +load("@rules_bzlmodrio_jdk//:maven_deps.bzl", "setup_legacy_setup_jdk_dependencies") + +setup_legacy_setup_jdk_dependencies() + +register_toolchains( + "@local_roborio//:macos", + "@local_roborio//:linux", + "@local_roborio//:windows", + "@local_raspi_32//:macos", + "@local_raspi_32//:linux", + "@local_raspi_32//:windows", + "@local_bullseye_32//:macos", + "@local_bullseye_32//:linux", + "@local_bullseye_32//:windows", + "@local_bullseye_64//:macos", + "@local_bullseye_64//:linux", + "@local_bullseye_64//:windows", +) + +setup_legacy_setup_jdk_dependencies() + +http_archive( + name = "bzlmodrio-ni", + sha256 = "197fceac88bf44fb8427d5e000b0083118d3346172dd2ad31eccf83a5e61b3ce", + url = "https://github.com/wpilibsuite/bzlmodRio-ni/releases/download/2025.0.0/bzlmodRio-ni-2025.0.0.tar.gz", +) + +load("@bzlmodrio-ni//:maven_cpp_deps.bzl", "setup_legacy_bzlmodrio_ni_cpp_dependencies") + +setup_legacy_bzlmodrio_ni_cpp_dependencies() + +http_archive( + name = "bzlmodrio-opencv", + sha256 = "5314cce05b49451a46bf3e3140fc401342e53d5f3357612ed4473e59bb616cba", + url = "https://github.com/wpilibsuite/bzlmodRio-opencv/releases/download/2024.4.8.0-4.bcr1/bzlmodRio-opencv-2024.4.8.0-4.bcr1.tar.gz", +) + +load("@bzlmodrio-opencv//:maven_cpp_deps.bzl", "setup_legacy_bzlmodrio_opencv_cpp_dependencies") + +setup_legacy_bzlmodrio_opencv_cpp_dependencies() + +load("@bzlmodrio-opencv//:maven_java_deps.bzl", "setup_legacy_bzlmodrio_opencv_java_dependencies") + +setup_legacy_bzlmodrio_opencv_java_dependencies() diff --git a/cameraserver/BUILD.bazel b/cameraserver/BUILD.bazel new file mode 100644 index 00000000000..542f0f3c961 --- /dev/null +++ b/cameraserver/BUILD.bazel @@ -0,0 +1,32 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary") +load("@rules_java//java:defs.bzl", "java_binary", "java_library") + +java_library( + name = "cameraserver-java", + srcs = glob(["src/main/java/**/*.java"]), + visibility = ["//visibility:public"], + deps = [ + "//cscore:cscore-java", + "//hal:hal-java", + "//ntcore:networktables-java", + "//wpimath:wpimath-java", + "//wpinet:wpinet-java", + "//wpiutil:wpiutil-java", + "@bzlmodrio-opencv//libraries/java/opencv", + ], +) + +cc_binary( + name = "DevMain-Cpp", + srcs = ["src/dev/native/cpp/main.cpp"], + deps = [ + ], +) + +java_binary( + name = "DevMain-Java", + srcs = ["src/dev/java/edu/wpi/first/cameraserver/DevMain.java"], + main_class = "edu.wpi.first.cameraserver.DevMain", + deps = [ + ], +) diff --git a/cameraserver/multiCameraServer/BUILD.bazel b/cameraserver/multiCameraServer/BUILD.bazel new file mode 100644 index 00000000000..470e9c5bce4 --- /dev/null +++ b/cameraserver/multiCameraServer/BUILD.bazel @@ -0,0 +1,16 @@ +load("@rules_java//java:defs.bzl", "java_binary") + +java_binary( + name = "multiCameraServer-java", + srcs = ["src/main/java/edu/wpi/Main.java"], + main_class = "edu.wpi.Main", + deps = [ + "//cameraserver:cameraserver-java", + "//cscore:cscore-java", + "//hal:hal-java", + "//ntcore:networktables-java", + "//wpimath:wpimath-java", + "//wpiutil:wpiutil-java", + "@maven//:com_google_code_gson_gson", + ], +) diff --git a/cscore/BUILD.bazel b/cscore/BUILD.bazel new file mode 100644 index 00000000000..a2470f8afe1 --- /dev/null +++ b/cscore/BUILD.bazel @@ -0,0 +1,21 @@ +load("@rules_java//java:defs.bzl", "java_binary", "java_library") + +java_library( + name = "cscore-java", + srcs = glob(["src/main/java/**/*.java"]), + visibility = ["//visibility:public"], + deps = [ + "//wpiutil:wpiutil-java", + "@bzlmodrio-opencv//libraries/java/opencv", + ], +) + +java_binary( + name = "DevMain-Java", + srcs = ["src/dev/java/edu/wpi/first/cscore/DevMain.java"], + main_class = "edu.wpi.first.cscore.DevMain", + deps = [ + ":cscore-java", + "//wpiutil:wpiutil-java", + ], +) diff --git a/hal/BUILD.bazel b/hal/BUILD.bazel new file mode 100644 index 00000000000..340a74c65e0 --- /dev/null +++ b/hal/BUILD.bazel @@ -0,0 +1,91 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") +load("@rules_java//java:defs.bzl", "java_binary", "java_library") + +cc_library( + name = "generated_cc_headers", + hdrs = glob(["src/generated/main/native/include/**"]), + includes = ["src/generated/main/native/include"], + strip_include_prefix = "src/generated/main/native/include", + visibility = ["//hal:__subpackages__"], +) + +filegroup( + name = "generated_java", + srcs = glob(["src/generated/main/java/**/*.java"]), + visibility = ["//hal:__subpackages__"], +) + +ATHENA_SRCS = glob(["src/main/native/athena/**"]) + +ATHENA_DEPS = ["@bzlmodrio-ni//libraries/cpp/ni:shared"] + +SIM_SRCS = glob(["src/main/native/sim/**"]) + +SIM_DEPS = [] + +HAL_DEPS = select({ + "@rules_bzlmodrio_toolchains//constraints/is_roborio:roborio": ATHENA_DEPS, + "//conditions:default": SIM_DEPS, +}) + +filegroup( + name = "platform-srcs", + srcs = select({ + "@rules_bzlmodrio_toolchains//constraints/is_roborio:roborio": ATHENA_SRCS, + "//conditions:default": SIM_SRCS, + }), +) + +cc_library( + name = "wpiHal.static", + srcs = [":platform-srcs"] + glob( + ["src/main/native/cpp/**"], + exclude = ["src/main/native/cpp/jni/**"], + ), + hdrs = glob(["src/main/native/include/**/*"]), + includes = ["src/main/native/include"], + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + ":generated_cc_headers", + "//wpiutil:wpiutil.static", + ] + HAL_DEPS, +) + +java_library( + name = "hal-java", + srcs = [":generated_java"] + glob(["src/main/java/**/*.java"]), + visibility = ["//visibility:public"], + deps = [ + "//wpiutil:wpiutil-java", + ], +) + +cc_test( + name = "hal-cpp-test", + size = "small", + srcs = glob([ + "src/test/native/**/*.cpp", + "src/test/native/**/*.h", + ]), + deps = [ + ":wpiHal.static", + "//thirdparty/googletest:googletest.static", + ], +) + +cc_binary( + name = "DevMain-Cpp", + srcs = ["src/dev/native/cpp/main.cpp"], + deps = [ + ":wpiHal.static", + ], +) + +java_binary( + name = "DevMain-Java", + srcs = ["src/dev/java/edu/wpi/first/hal/DevMain.java"], + main_class = "edu.wpi.first.hal.DevMain", + deps = [ + ], +) diff --git a/ntcore/BUILD.bazel b/ntcore/BUILD.bazel new file mode 100644 index 00000000000..1156cff691e --- /dev/null +++ b/ntcore/BUILD.bazel @@ -0,0 +1,92 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") +load("@rules_java//java:defs.bzl", "java_binary", "java_library") + +cc_library( + name = "generated_cc_headers", + hdrs = glob(["src/generated/main/native/include/**"]), + includes = ["src/generated/main/native/include"], + strip_include_prefix = "src/generated/main/native/include", + visibility = ["//ntcore:__subpackages__"], +) + +filegroup( + name = "generated_cc_source", + srcs = glob( + ["src/generated/main/native/cpp/**"], + exclude = ["src/generated/main/native/cpp/jni/**"], + ), + visibility = ["//ntcore:__subpackages__"], +) + +filegroup( + name = "generated_java", + srcs = glob(["src/generated/main/java/**/*.java"]), + visibility = ["//ntcore:__subpackages__"], +) + +cc_library( + name = "ntcore.static", + srcs = glob( + ["src/main/native/cpp/**"], + exclude = ["src/main/native/cpp/jni/**"], + ) + [":generated_cc_source"], + hdrs = glob(["src/main/native/include/**/*"]), + includes = [ + "src/main/native/cpp", + "src/main/native/include", + ], + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + ":generated_cc_headers", + "//wpinet:wpinet.static", + "//wpiutil:wpiutil.static", + ], +) + +java_library( + name = "networktables-java", + srcs = glob(["src/main/java/**/*.java"]) + [":generated_java"], + visibility = ["//visibility:public"], + deps = [ + "//wpiutil:wpiutil-java", + "@maven//:us_hebi_quickbuf_quickbuf_runtime", + ], +) + +cc_test( + name = "ntcore-cpp-test", + size = "small", + srcs = glob([ + "src/test/native/**/*.cpp", + "src/test/native/**/*.h", + ]), + tags = [ + "exclusive", + "no-asan", + "no-tsan", + ], + deps = [ + ":ntcore.static", + "//thirdparty/googletest:googletest.static", + "//wpiutil:wpiutil-testlib", + ], +) + +cc_binary( + name = "DevMain-Cpp", + srcs = ["src/dev/native/cpp/main.cpp"], + deps = [ + ":ntcore.static", + ], +) + +java_binary( + name = "DevMain-Java", + srcs = ["src/dev/java/edu/wpi/first/ntcore/DevMain.java"], + main_class = "edu.wpi.first.ntcore.DevMain", + deps = [ + "networktables-java", + "//wpiutil:wpiutil-java", + ], +) diff --git a/shared/bazel/compiler_flags/base_linux_flags.rc b/shared/bazel/compiler_flags/base_linux_flags.rc new file mode 100644 index 00000000000..a49b0f14587 --- /dev/null +++ b/shared/bazel/compiler_flags/base_linux_flags.rc @@ -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' diff --git a/shared/bazel/compiler_flags/coverage_flags.rc b/shared/bazel/compiler_flags/coverage_flags.rc new file mode 100644 index 00000000000..0f0a02c470b --- /dev/null +++ b/shared/bazel/compiler_flags/coverage_flags.rc @@ -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 diff --git a/shared/bazel/compiler_flags/linux_flags.rc b/shared/bazel/compiler_flags/linux_flags.rc new file mode 100644 index 00000000000..0a19c1d73d1 --- /dev/null +++ b/shared/bazel/compiler_flags/linux_flags.rc @@ -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 diff --git a/shared/bazel/compiler_flags/osx_flags.rc b/shared/bazel/compiler_flags/osx_flags.rc new file mode 100644 index 00000000000..da12307993e --- /dev/null +++ b/shared/bazel/compiler_flags/osx_flags.rc @@ -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 diff --git a/shared/bazel/compiler_flags/roborio_flags.rc b/shared/bazel/compiler_flags/roborio_flags.rc new file mode 100644 index 00000000000..691da8d5e6e --- /dev/null +++ b/shared/bazel/compiler_flags/roborio_flags.rc @@ -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 diff --git a/shared/bazel/compiler_flags/sanitizers.rc b/shared/bazel/compiler_flags/sanitizers.rc new file mode 100644 index 00000000000..739a568a3fc --- /dev/null +++ b/shared/bazel/compiler_flags/sanitizers.rc @@ -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 diff --git a/shared/bazel/compiler_flags/windows_flags.rc b/shared/bazel/compiler_flags/windows_flags.rc new file mode 100644 index 00000000000..7e604e43c9f --- /dev/null +++ b/shared/bazel/compiler_flags/windows_flags.rc @@ -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 diff --git a/shared/bazel/rules/gen/BUILD.bazel b/shared/bazel/rules/gen/BUILD.bazel new file mode 100644 index 00000000000..49f2e10eb96 --- /dev/null +++ b/shared/bazel/rules/gen/BUILD.bazel @@ -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"], +) diff --git a/shared/bazel/rules/gen/gen-resources.bzl b/shared/bazel/rules/gen/gen-resources.bzl new file mode 100644 index 00000000000..65dbf3fedca --- /dev/null +++ b/shared/bazel/rules/gen/gen-resources.bzl @@ -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, + ) diff --git a/shared/bazel/rules/gen/gen-version-file.bzl b/shared/bazel/rules/gen/gen-version-file.bzl new file mode 100644 index 00000000000..7ec27f3c4cf --- /dev/null +++ b/shared/bazel/rules/gen/gen-version-file.bzl @@ -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, + ), + }, +) diff --git a/shared/bazel/rules/gen/gen_resources.py b/shared/bazel/rules/gen/gen_resources.py new file mode 100644 index 00000000000..869ff1d5914 --- /dev/null +++ b/shared/bazel/rules/gen/gen_resources.py @@ -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 +#include +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(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() diff --git a/thirdparty/googletest/BUILD.bazel b/thirdparty/googletest/BUILD.bazel new file mode 100644 index 00000000000..198ae1e0c2f --- /dev/null +++ b/thirdparty/googletest/BUILD.bazel @@ -0,0 +1,10 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "googletest.static", + srcs = glob(["src/**"]), + hdrs = glob(["include/**"]), + includes = ["src/googletest"], + strip_include_prefix = "include", + visibility = ["//visibility:public"], +) diff --git a/wpilibj/BUILD.bazel b/wpilibj/BUILD.bazel new file mode 100644 index 00000000000..f0a9359ae91 --- /dev/null +++ b/wpilibj/BUILD.bazel @@ -0,0 +1,82 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary") +load("@rules_java//java:defs.bzl", "java_binary", "java_library") +load("//shared/bazel/rules/gen:gen-version-file.bzl", "generate_version_file") + +generate_version_file( + name = "generate-version", + output_file = "WPILibVersion.java", + template = "src/generate/WPILibVersion.java.in", + visibility = ["//visibility:public"], +) + +filegroup( + name = "generated_java", + srcs = glob(["src/generated/main/java/**/*.java"]), + visibility = ["//wpilibj:__subpackages__"], +) + +java_library( + name = "wpilibj", + srcs = [ + ":generate-version", + ":generated_java", + ] + glob(["src/main/java/**/*.java"]), + visibility = ["//visibility:public"], + deps = [ + "//cameraserver:cameraserver-java", + "//cscore:cscore-java", + "//hal:hal-java", + "//ntcore:networktables-java", + "//wpimath:wpimath-java", + "//wpinet:wpinet-java", + "//wpiunits", + "//wpiutil:wpiutil-java", + "@maven//:org_ejml_ejml_core", + "@maven//:org_ejml_ejml_simple", + ], +) + +cc_binary( + name = "DevMain-Cpp", + srcs = ["src/dev/native/cpp/main.cpp"], + deps = [ + ], +) + +java_binary( + name = "DevMain-Java", + srcs = ["src/dev/java/edu/wpi/first/wpilibj/DevMain.java"], + main_class = "edu.wpi.first.wpilibj.DevMain", + deps = [ + "//hal:hal-java", + "//ntcore:networktables-java", + "//wpimath:wpimath-java", + "//wpiutil:wpiutil-java", + ], +) + +filegroup( + name = "hid_schema", + srcs = [ + "src/generate/hids.json", + "src/generate/hids.schema.json", + ], + visibility = ["//visibility:public"], +) + +filegroup( + name = "pwm_schema", + srcs = [ + "src/generate/pwm_motor_controllers.json", + ], + visibility = ["//visibility:public"], +) + +filegroup( + name = "templates", + srcs = glob(["src/generate/*.jinja"]) + [ + ":hid_schema", + ":pwm_schema", + ], + visibility = ["//visibility:public"], +) diff --git a/wpimath/BUILD.bazel b/wpimath/BUILD.bazel new file mode 100644 index 00000000000..2f650293fdb --- /dev/null +++ b/wpimath/BUILD.bazel @@ -0,0 +1,40 @@ +load("@rules_java//java:defs.bzl", "java_binary", "java_library") +load("@rules_python//python:defs.bzl", "py_binary") + +filegroup( + name = "generated_java", + srcs = glob(["src/generated/main/java/**/*.java"]), + visibility = ["//wpimath:__subpackages__"], +) + +java_library( + name = "wpimath-java", + srcs = [":generated_java"] + glob(["src/main/java/**/*.java"]), + visibility = ["//visibility:public"], + deps = [ + "//wpiunits", + "//wpiutil:wpiutil-java", + "@maven//:com_fasterxml_jackson_core_jackson_annotations", + "@maven//:com_fasterxml_jackson_core_jackson_core", + "@maven//:com_fasterxml_jackson_core_jackson_databind", + "@maven//:org_ejml_ejml_core", + "@maven//:org_ejml_ejml_ddense", + "@maven//:org_ejml_ejml_simple", + "@maven//:us_hebi_quickbuf_quickbuf_runtime", + ], +) + +java_binary( + name = "DevMain-Java", + srcs = ["src/dev/java/edu/wpi/first/math/DevMain.java"], + main_class = "edu.wpi.first.math.DevMain", + deps = [ + ":wpimath-java", + ], +) + +py_binary( + name = "ExponentialProfileModel", + srcs = ["algorithms/ExponentialProfileModel.py"], + tags = ["manual"], +) diff --git a/wpinet/BUILD.bazel b/wpinet/BUILD.bazel new file mode 100644 index 00000000000..c6bdebae7a0 --- /dev/null +++ b/wpinet/BUILD.bazel @@ -0,0 +1,218 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") +load("@rules_java//java:defs.bzl", "java_binary", "java_library") +load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources") + +WIN_UV_SRCS = glob([ + "src/main/native/thirdparty/libuv/src/win/*.cpp", + "src/main/native/thirdparty/libuv/src/win/*.h", +]) + +UNIX_UV_SRCS = [ + "src/main/native/thirdparty/libuv/src/unix/async.cpp", + "src/main/native/thirdparty/libuv/src/unix/core.cpp", + "src/main/native/thirdparty/libuv/src/unix/dl.cpp", + "src/main/native/thirdparty/libuv/src/unix/fs.cpp", + "src/main/native/thirdparty/libuv/src/unix/getaddrinfo.cpp", + "src/main/native/thirdparty/libuv/src/unix/getnameinfo.cpp", + "src/main/native/thirdparty/libuv/src/unix/loop-watcher.cpp", + "src/main/native/thirdparty/libuv/src/unix/loop.cpp", + "src/main/native/thirdparty/libuv/src/unix/pipe.cpp", + "src/main/native/thirdparty/libuv/src/unix/poll.cpp", + "src/main/native/thirdparty/libuv/src/unix/process.cpp", + "src/main/native/thirdparty/libuv/src/unix/random-devurandom.cpp", + "src/main/native/thirdparty/libuv/src/unix/random-getentropy.cpp", + "src/main/native/thirdparty/libuv/src/unix/random-getrandom.cpp", + "src/main/native/thirdparty/libuv/src/unix/signal.cpp", + "src/main/native/thirdparty/libuv/src/unix/stream.cpp", + "src/main/native/thirdparty/libuv/src/unix/tcp.cpp", + "src/main/native/thirdparty/libuv/src/unix/thread.cpp", + "src/main/native/thirdparty/libuv/src/unix/tty.cpp", + "src/main/native/thirdparty/libuv/src/unix/udp.cpp", +] + glob(["src/main/native/thirdparty/libuv/src/unix/*.h"]) + +MAC_UV_SRCS = [ + "src/main/native/thirdparty/libuv/src/unix/bsd-ifaddrs.cpp", + "src/main/native/thirdparty/libuv/src/unix/darwin.cpp", + "src/main/native/thirdparty/libuv/src/unix/darwin-proctitle.cpp", + "src/main/native/thirdparty/libuv/src/unix/fsevents.cpp", + "src/main/native/thirdparty/libuv/src/unix/kqueue.cpp", + "src/main/native/thirdparty/libuv/src/unix/proctitle.cpp", +] + +LINUX_UV_SRCS = [ + "src/main/native/thirdparty/libuv/src/unix/linux.cpp", + "src/main/native/thirdparty/libuv/src/unix/procfs-exepath.cpp", + "src/main/native/thirdparty/libuv/src/unix/proctitle.cpp", + "src/main/native/thirdparty/libuv/src/unix/random-sysctl-linux.cpp", +] + +cc_library( + name = "libuv-headers", + hdrs = glob([ + "src/main/native/thirdparty/libuv/include/**/*.h", + ]), + includes = ["src/main/native/thirdparty/libuv/src"], + strip_include_prefix = "src/main/native/thirdparty/libuv/include", + visibility = ["//wpinet:__subpackages__"], +) + +filegroup( + name = "libuv-srcs", + srcs = select({ + "@rules_bzlmodrio_toolchains//constraints/combined:is_unix": UNIX_UV_SRCS, + "//conditions:default": [], + }) + + select({ + "@bazel_tools//src/conditions:darwin": MAC_UV_SRCS, + "@bazel_tools//src/conditions:windows": WIN_UV_SRCS, + "@rules_bzlmodrio_toolchains//constraints/combined:is_linux": LINUX_UV_SRCS, + }) + glob(["src/main/native/thirdparty/libuv/src/*"]), + visibility = ["//wpinet:__subpackages__"], +) + +cc_library( + name = "tcpsockets-headers", + hdrs = glob([ + "src/main/native/thirdparty/tcpsockets/include/**/*.h", + ]), + includes = ["src/main/native/thirdparty/tcpsockets/include"], + strip_include_prefix = "src/main/native/thirdparty/tcpsockets/include", + visibility = ["//wpinet:__subpackages__"], +) + +filegroup( + name = "tcpsockets-srcs", + srcs = glob(["src/main/native/thirdparty/tcpsockets/cpp/**"]), + visibility = ["//wpinet:__subpackages__"], +) + +generate_resources( + name = "generate-resources", + namespace = "wpi", + prefix = "WPI", + resource_files = glob(["src/main/native/resources/*"]), +) + +filegroup( + name = "native-srcs", + srcs = ["generate-resources"] + select({ + "@bazel_tools//src/conditions:darwin": glob(["src/main/native/macOS/*"]), + "@bazel_tools//src/conditions:windows": glob(["src/main/native/windows/*"]), + "@rules_bzlmodrio_toolchains//constraints/combined:is_linux": glob(["src/main/native/linux/*"]), + }), +) + +cc_library( + name = "private_includes", + hdrs = glob([ + "src/main/native/cpp/*.h", + ]), + strip_include_prefix = "src/main/native/cpp", +) + +cc_library( + name = "wpinet.static", + srcs = glob( + ["src/main/native/cpp/**"], + exclude = ["src/main/native/cpp/jni/**"], + ) + [ + ":libuv-srcs", + ":tcpsockets-srcs", + ] + ["native-srcs"], + hdrs = glob(["src/main/native/include/**/*"]), + includes = ["src/main/native/include"], + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + ":libuv-headers", + ":private_includes", + ":tcpsockets-headers", + "//wpiutil:wpiutil.static", + ], +) + +java_library( + name = "wpinet-java", + srcs = glob(["src/main/java/**/*.java"]), + visibility = ["//visibility:public"], + deps = [ + "//wpiutil:wpiutil-java", + ], +) + +cc_test( + name = "wpinet-cpp-test", + size = "small", + srcs = glob([ + "src/test/native/**/*.cpp", + "src/test/native/**/*.h", + ]), + tags = ["no-asan"], + deps = [ + ":wpinet.static", + "//thirdparty/googletest:googletest.static", + "//wpiutil:wpiutil-testlib", + ], +) + +cc_binary( + name = "DevMain-Cpp", + srcs = ["src/dev/native/cpp/main.cpp"], + deps = [ + ":wpinet.static", + ], +) + +java_binary( + name = "DevMain-java", + srcs = ["src/dev/java/edu/wpi/first/net/DevMain.java"], + main_class = "edu.wpi.first.net.DevMain", + deps = [ + ":wpinet-java", + "//wpiutil:wpiutil-java", + ], +) + +cc_binary( + name = "netconsoleServer", + srcs = ["src/netconsoleServer/native/cpp/main.cpp"], + linkopts = select({ + "@rules_bzlmodrio_toolchains//constraints/combined:is_linux": ["-lutil"], + "//conditions:default": [], + }), + deps = [ + ":wpinet.static", + ], +) + +cc_binary( + name = "netconsoleTee", + srcs = ["src/netconsoleTee/native/cpp/main.cpp"], + deps = [ + ":wpinet.static", + ], +) + +cc_binary( + name = "dsclient", + srcs = ["examples/dsclient/dsclient.cpp"], + deps = [ + ":wpinet.static", + ], +) + +cc_binary( + name = "parallelconnect", + srcs = ["examples/parallelconnect/parallelconnect.cpp"], + deps = [ + ":wpinet.static", + ], +) + +cc_binary( + name = "webserver", + srcs = ["examples/webserver/webserver.cpp"], + deps = [ + ":wpinet.static", + ], +) diff --git a/wpiunits/BUILD.bazel b/wpiunits/BUILD.bazel new file mode 100644 index 00000000000..d6686308a97 --- /dev/null +++ b/wpiunits/BUILD.bazel @@ -0,0 +1,17 @@ +load("@rules_java//java:defs.bzl", "java_binary", "java_library") + +java_library( + name = "wpiunits", + srcs = glob(["src/main/java/**/*.java"]) + glob(["src/generated/main/java/**/*.java"]), + visibility = ["//visibility:public"], + deps = [], +) + +java_binary( + name = "DevMain-Java", + srcs = ["src/dev/java/edu/wpi/first/units/DevMain.java"], + main_class = "edu.wpi.first.units.DevMain", + deps = [ + ":wpiunits", + ], +) diff --git a/wpiutil/BUILD.bazel b/wpiutil/BUILD.bazel new file mode 100644 index 00000000000..d23d218ce49 --- /dev/null +++ b/wpiutil/BUILD.bazel @@ -0,0 +1,268 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") +load("@rules_java//java:defs.bzl", "java_binary", "java_library") +load("@rules_python//python:defs.bzl", "py_binary") +load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources") + +cc_library( + name = "argparse-headers", + hdrs = glob([ + "src/main/native/thirdparty/argparse/include/**/*", + ]), + includes = ["src/main/native/thirdparty/argparse/include"], + strip_include_prefix = "src/main/native/thirdparty/argparse/include", + visibility = ["//wpiutil:__subpackages__"], +) + +cc_library( + name = "expected-headers", + hdrs = glob([ + "src/main/native/thirdparty/expected/include/**/*", + ]), + includes = ["src/main/native/thirdparty/expected/include"], + strip_include_prefix = "src/main/native/thirdparty/expected/include", + visibility = ["//wpiutil:__subpackages__"], +) + +cc_library( + name = "concurrentqueue-headers", + hdrs = glob([ + "src/main/native/thirdparty/concurrentqueue/include/**/*", + ]), + includes = ["src/main/native/thirdparty/concurrentqueue/include"], + strip_include_prefix = "src/main/native/thirdparty/concurrentqueue/include", + visibility = ["//wpiutil:__subpackages__"], +) + +cc_library( + name = "fmtlib-headers", + hdrs = glob([ + "src/main/native/thirdparty/fmtlib/include/**/*.h", + ]), + includes = ["src/main/native/thirdparty/fmtlib/include"], + strip_include_prefix = "src/main/native/thirdparty/fmtlib/include", + visibility = ["//wpiutil:__subpackages__"], +) + +filegroup( + name = "fmtlib-srcs", + srcs = glob(["src/main/native/thirdparty/fmtlib/src/**"]), + visibility = ["//wpiutil:__subpackages__"], +) + +cc_library( + name = "json-headers", + hdrs = glob([ + "src/main/native/thirdparty/json/include/**/*.h", + ]), + includes = ["src/main/native/thirdparty/json/include"], + strip_include_prefix = "src/main/native/thirdparty/json/include", + visibility = ["//wpiutil:__subpackages__"], +) + +cc_library( + name = "llvm-headers", + hdrs = glob([ + "src/main/native/thirdparty/llvm/include/**/*.h", + ]), + includes = ["src/main/native/thirdparty/llvm/include"], + strip_include_prefix = "src/main/native/thirdparty/llvm/include", + visibility = ["//wpiutil:__subpackages__"], +) + +filegroup( + name = "llvm-srcs", + srcs = glob(["src/main/native/thirdparty/llvm/cpp/**"]), + visibility = ["//wpiutil:__subpackages__"], +) + +cc_library( + name = "memory-headers", + hdrs = glob([ + "src/main/native/thirdparty/memory/include/**/*.hpp", + ]), + includes = ["src/main/native/thirdparty/memory/include"], + strip_include_prefix = "src/main/native/thirdparty/memory/include", + visibility = ["//wpiutil:__subpackages__"], +) + +filegroup( + name = "memory-srcs", + srcs = glob(["src/main/native/thirdparty/memory/src/**"]), + visibility = ["//wpiutil:__subpackages__"], +) + +cc_library( + name = "mpack-headers", + hdrs = glob([ + "src/main/native/thirdparty/mpack/include/**/*.h", + ]), + includes = ["src/main/native/thirdparty/mpack/include"], + strip_include_prefix = "src/main/native/thirdparty/mpack/include", + visibility = ["//wpiutil:__subpackages__"], +) + +filegroup( + name = "mpack-srcs", + srcs = glob(["src/main/native/thirdparty/mpack/src/**"]), + visibility = ["//wpiutil:__subpackages__"], +) + +cc_library( + name = "protobuf-headers", + hdrs = glob([ + "src/main/native/thirdparty/protobuf/include/**/*.h", + "src/main/native/thirdparty/protobuf/include/**/*.inc", + ]), + includes = ["src/main/native/thirdparty/protobuf/include"], + strip_include_prefix = "src/main/native/thirdparty/protobuf/include", + visibility = ["//wpiutil:__subpackages__"], +) + +filegroup( + name = "protobuf-srcs", + srcs = glob(["src/main/native/thirdparty/protobuf/src/**"]), + visibility = ["//wpiutil:__subpackages__"], +) + +cc_library( + name = "sigslot-headers", + hdrs = glob([ + "src/main/native/thirdparty/sigslot/include/**/*.h", + ]), + includes = ["src/main/native/thirdparty/sigslot/include"], + strip_include_prefix = "src/main/native/thirdparty/sigslot/include", + visibility = ["//wpiutil:__subpackages__"], +) + +generate_resources( + name = "generate-resources", + namespace = "wpi", + prefix = "WPI", + resource_files = glob(["src/main/native/resources/*"]), +) + +filegroup( + name = "native-srcs", + srcs = select({ + "@bazel_tools//src/conditions:windows": glob([ + "src/main/native/windows/*.cpp", + "src/main/native/windows/*.h", + ]), + "@rules_bzlmodrio_toolchains//constraints/combined:is_unix": glob(["src/main/native/unix/*.cpp"]), + }), +) + +cc_library( + name = "wpiutil.static", + srcs = glob( + ["src/main/native/cpp/**"], + exclude = ["src/main/native/cpp/jni/**"], + ) + [ + ":fmtlib-srcs", + ":generate-resources", + ":llvm-srcs", + ":memory-srcs", + ":mpack-srcs", + ":native-srcs", + ":protobuf-srcs", + ], + hdrs = glob(["src/main/native/include/**/*"]), + includes = ["src/main/native/include"], + strip_include_prefix = "src/main/native/include", + visibility = ["//visibility:public"], + deps = [ + ":argparse-headers", + ":concurrentqueue-headers", + ":expected-headers", + ":fmtlib-headers", + ":json-headers", + ":llvm-headers", + ":memory-headers", + ":mpack-headers", + ":protobuf-headers", + ":sigslot-headers", + ] + select({ + "@rules_bzlmodrio_toolchains//constraints/is_roborio:roborio": ["@bzlmodrio-ni//libraries/cpp/ni:shared"], + "//conditions:default": [], + }), +) + +java_library( + name = "wpiutil-java", + srcs = glob(["src/main/java/**/*.java"]), + visibility = ["//visibility:public"], + deps = [ + "@maven//:com_fasterxml_jackson_core_jackson_annotations", + "@maven//:com_fasterxml_jackson_core_jackson_core", + "@maven//:com_fasterxml_jackson_core_jackson_databind", + "@maven//:us_hebi_quickbuf_quickbuf_runtime", + ], +) + +cc_library( + name = "wpiutil-testlib", + hdrs = glob(["src/test/native/include/**"]), + strip_include_prefix = "src/test/native/include", + visibility = ["//visibility:public"], +) + +cc_test( + name = "wpiutil-cpp-test", + size = "small", + srcs = glob(["src/test/native/cpp/**"]), + linkstatic = True, + tags = ["no-tsan"], # TODO(pj.reiniger) Find problem + deps = [ + ":wpiutil.static", + ":wpiutil-testlib", + "//thirdparty/googletest:googletest.static", + ], +) + +cc_binary( + name = "DevMain-Cpp", + srcs = ["src/dev/native/cpp/main.cpp"], + deps = [ + ":wpiutil.static", + ], +) + +java_binary( + name = "DevMain-Java", + srcs = ["src/dev/java/edu/wpi/first/util/DevMain.java"], + main_class = "edu.wpi.first.util.DevMain", + deps = [ + ":wpiutil-java", + ], +) + +py_binary( + name = "datalog", + srcs = ["examples/printlog/datalog.py"], + tags = ["manual"], +) + +cc_binary( + name = "printlog", + srcs = ["examples/printlog/printlog.cpp"], + deps = [ + ":wpiutil.static", + ], +) + +cc_binary( + name = "writelog", + srcs = ["examples/writelog/writelog.cpp"], + deps = [ + ":wpiutil.static", + ], +) + +java_binary( + name = "printlog-java", + srcs = ["src/printlog/java/printlog/PrintLog.java"], + main_class = "printlog.PrintLog", + deps = [ + ":wpiutil-java", + ], +)