Skip to content

Commit 03e6f80

Browse files
authored
feat: separate compilation + ssl + tests (#1)
1 parent 9e42a0e commit 03e6f80

File tree

10 files changed

+114
-4
lines changed

10 files changed

+114
-4
lines changed

.bazelignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test

.bazelrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
21
common --enable_bzlmod
2+
build --enable_platform_specific_config
33
build --incompatible_use_platforms_repo_for_constraints
44
build --incompatible_enable_cc_toolchain_resolution
55
build --incompatible_strict_action_env
66
build --enable_runfiles
77
build --registry=https://raw.githubusercontent.com/bazelboost/registry/main
88
build --registry=https://bcr.bazel.build
99

10+
# boringssl requires cpp14+
11+
build:linux --cxxopt=-std=c++14
12+
build:macos --cxxopt=-std=c++14
13+
1014
try-import %workspace%/user.bazelrc

.github/workflows/bazel.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: bazel
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
test:
7+
strategy:
8+
matrix:
9+
os:
10+
- ubuntu-latest
11+
- windows-latest
12+
- macos-latest
13+
runs-on: ${{ matrix.os }}
14+
steps:
15+
- uses: actions/checkout@v4
16+
- run: bazelisk test ...
17+
working-directory: test
18+
- run: bazelisk test ... [email protected]//:ssl=boringssl
19+
working-directory: test

BUILD.bazel

+55-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,62 @@
11
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
3+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
24

3-
package(default_visibility = ["//visibility:public"])
5+
string_flag(
6+
name = "ssl",
7+
visibility = ["//visibility:public"],
8+
values = ["no_ssl", "openssl", "boringssl"],
9+
build_setting_default = "no_ssl",
10+
)
11+
12+
config_setting(name = "no_ssl", flag_values = {":ssl": "no_ssl"})
13+
config_setting(name = "openssl", flag_values = {":ssl": "openssl"})
14+
config_setting(name = "boringssl", flag_values = {":ssl": "boringssl"})
15+
16+
write_file(
17+
name = "src",
18+
out = "boost.asio.src.cpp",
19+
content = select({
20+
":no_ssl": [
21+
"#include <boost/asio/impl/src.hpp>",
22+
],
23+
"//conditions:default": [
24+
"#include <boost/asio/impl/src.hpp>",
25+
"#include <boost/asio/ssl/impl/src.hpp>",
26+
],
27+
}),
28+
)
429

530
cc_library(
631
name = "boost.asio",
32+
visibility = ["//visibility:public"],
33+
defines = ["BOOST_ASIO_SEPARATE_COMPILATION"],
34+
linkopts = select({
35+
"@platforms//os:windows": [
36+
"-DEFAULTLIB:ws2_32",
37+
"-DEFAULTLIB:mswsock",
38+
],
39+
"//conditions:default": [
40+
"-lpthread",
41+
],
42+
}),
743
hdrs = glob([
844
"include/**/*.hpp",
945
"include/**/*.h",
46+
"include/**/*.ipp",
47+
], exclude = [
48+
"include/boost/asio/impl/src.hpp",
49+
"include/boost/asio/ssl/impl/src.hpp",
1050
]),
51+
srcs = [":src"] + select({
52+
":no_ssl": [
53+
"include/boost/asio/impl/src.hpp",
54+
],
55+
"//conditions:default": [
56+
"include/boost/asio/impl/src.hpp",
57+
"include/boost/asio/ssl/impl/src.hpp",
58+
],
59+
}),
1160
includes = ["include"],
1261
deps = [
1362
"@boost.align",
@@ -28,5 +77,9 @@ cc_library(
2877
"@boost.throw_exception",
2978
"@boost.type_traits",
3079
"@boost.utility",
31-
],
80+
] + select({
81+
":openssl": ["@openssl//:ssl"],
82+
":boringssl": ["@boringssl//:ssl"],
83+
":no_ssl": [],
84+
}),
3285
)

MODULE.bazel

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ module(
55
)
66

77
bazel_dep(name = "rules_cc", version = "0.0.8")
8+
bazel_dep(name = "platforms", version = "0.0.7")
9+
bazel_dep(name = "bazel_skylib", version = "1.4.2")
10+
bazel_dep(name = "boringssl", version = "0.0.0-20230215-5c22014")
811
bazel_dep(name = "boost.align", version = "1.83.0.bzl.1")
912
bazel_dep(name = "boost.array", version = "1.83.0.bzl.1")
1013
bazel_dep(name = "boost.assert", version = "1.83.0.bzl.1")
@@ -14,7 +17,7 @@ bazel_dep(name = "boost.config", version = "1.83.0.bzl.6")
1417
bazel_dep(name = "boost.context", version = "1.83.0.bzl.1")
1518
bazel_dep(name = "boost.core", version = "1.83.0.bzl.1")
1619
bazel_dep(name = "boost.coroutine", version = "1.83.0.bzl.1")
17-
bazel_dep(name = "boost.date_time", version = "1.83.0.bzl.1")
20+
bazel_dep(name = "boost.date_time", version = "1.83.0.bzl.2")
1821
bazel_dep(name = "boost.exception", version = "1.83.0.bzl.1")
1922
bazel_dep(name = "boost.function", version = "1.83.0.bzl.1")
2023
bazel_dep(name = "boost.regex", version = "1.83.0.bzl.1")

test/.bazelrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import %workspace%/../.bazelrc

test/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/bazel-*
2+
/external
3+
/.cache
4+
/compile_commands.json
5+
user.bazelrc

test/BUILD.bazel

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
2+
3+
cc_library(
4+
name = "unit_test",
5+
hdrs = ["unit_test.hpp"],
6+
)
7+
8+
cc_test(
9+
name = "any_completion_executor",
10+
srcs = ["any_completion_executor.cpp"],
11+
deps = [
12+
":unit_test",
13+
"@boost.asio",
14+
],
15+
)

test/MODULE.bazel

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module(name = "boost.asio.test")
2+
3+
bazel_dep(name = "rules_cc", version = "0.0.8")
4+
bazel_dep(name = "boost.asio")
5+
6+
local_path_override(
7+
module_name = "boost.asio",
8+
path = "..",
9+
)

test/WORKSPACE.bazel

Whitespace-only changes.

0 commit comments

Comments
 (0)