Skip to content

Commit

Permalink
feat: add bazel tests and defines (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: Ezekiel Warren <[email protected]>
andrewkatson and zaucy authored Apr 8, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f2bf974 commit cadb8e5
Showing 10 changed files with 5,441 additions and 4 deletions.
1 change: 0 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

common --enable_bzlmod
build --incompatible_use_platforms_repo_for_constraints
build --incompatible_enable_cc_toolchain_resolution
build --incompatible_strict_action_env
build --enable_runfiles
17 changes: 17 additions & 0 deletions .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: bazel

on: [pull_request]

jobs:
test:
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- run: bazelisk test ...
working-directory: test
67 changes: 64 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -2,12 +2,63 @@ load("@rules_cc//cc:defs.bzl", "cc_library")

package(default_visibility = ["//visibility:public"])

_WINDOWS_HDRS = [
"**/win/*.hpp"
]

_POSIX_HDRS = [
"**/posix/*.hpp"
]

_MAC_HDRS = [
"**/mac/*.hpp"
]


cc_library(
name = "chrono_posix",
target_compatible_with = select({
"@platforms//os:windows": ["@platforms//:incompatible"],
"@platforms//os:macos": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
hdrs = glob(_POSIX_HDRS),
includes = ["include"],
defines = ["BOOST_THREAD_DONT_USE_ATOMIC"],
)

cc_library(
name = "chrono_windows",
target_compatible_with = select({
"@platforms//os:windows": [],
"@platforms//os:macos": ["@platforms//:incompatible"],
"//conditions:default": ["@platforms//:incompatible"],
}),
hdrs = glob(_WINDOWS_HDRS),
includes = ["include"],
linkopts = ["-DEFAULTLIB:shell32"],
)

cc_library(
name = "chrono_mac",
target_compatible_with = select({
"@platforms//os:windows": ["@platforms//:incompatible"],
"@platforms//os:macos": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
hdrs = glob(_MAC_HDRS),
includes = ["include"],
linkopts = ["-DEFAULTLIB:shell32"],
)

cc_library(
name = "boost.chrono",
hdrs = glob([
"include/**/*.hpp",
"include/**/*.h",
]),
], exclude = _POSIX_HDRS + _WINDOWS_HDRS + _MAC_HDRS),
srcs = glob(["src/**/*.cpp"]),
defines = ["BOOST_ALL_NO_LIB"],
includes = ["include"],
deps = [
"@boost.assert",
@@ -24,6 +75,16 @@ cc_library(
"@boost.type_traits",
"@boost.typeof",
"@boost.utility",
"@boost.winapi",
],
] + select({
"@platforms//os:windows": [
":chrono_windows",
"@boost.winapi",
],
"@platforms//os:macos": [
":chrono_mac",
],
"//conditions:default": [
":chrono_posix",
],
})
)
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ module(
)

bazel_dep(name = "rules_cc", version = "0.0.8")
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "boost.assert", version = "1.83.0.bzl.1")
bazel_dep(name = "boost.config", version = "1.83.0.bzl.6")
bazel_dep(name = "boost.core", version = "1.83.0.bzl.1")
2,249 changes: 2,249 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import %workspace%/../.bazelrc
5 changes: 5 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/bazel-*
/external
/.cache
/compile_commands.json
user.bazelrc
45 changes: 45 additions & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
load("@rules_cc//cc:defs.bzl", "cc_test")

_TESTS = {
"test_7868": [],
# Fails intentionally so not tested "test_9337": [],
"test_10631": [],
# Fails intentionally so not tested "test_10778": [],
"test_11006": [],
"test_11012": [],
"test_12176": [],
}

[cc_test(
name = test,
srcs = glob(["{}.cpp".format(test)], exclude = ["**/win32_test.cpp"]),
defines = select({
"@platforms//os:windows": ["WIN32_LEAN_AND_MEAN=1"],
"//conditions:default": [],
}),
deps = [
"@boost.chrono",
"@boost.test",
] + _TESTS[test],
) for test in _TESTS]

cc_test (
name = "win32_test",
target_compatible_with = select({
"@platforms//os:windows": [],
"@platforms//os:macos": ["@platforms//:incompatible"],
"//conditions:default": ["@platforms//:incompatible"],
}),
srcs =
select({
"@platforms//os:windows": glob([
"**/win32_test.cpp"
]),
"//conditions:default": [
],
}),
deps = [
"@boost.chrono",
"@boost.test"
]
)
11 changes: 11 additions & 0 deletions test/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module(
name = "boost.chrono.test",
)

local_path_override(
module_name = "boost.chrono",
path = ".."
)

bazel_dep(name = "boost.test", version = "1.83.0.bzl.4")
bazel_dep(name = "boost.chrono")
3,048 changes: 3,048 additions & 0 deletions test/MODULE.bazel.lock

Large diffs are not rendered by default.

0 comments on commit cadb8e5

Please sign in to comment.