forked from bazelregistry/mongo-cxx-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.bzl
165 lines (144 loc) · 4.97 KB
/
config.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
_bsoncxx_config_build_file_contents = """
load("@rules_cc//cc:defs.bzl", "cc_library")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "bsoncxx_config",
includes = ["."],
strip_include_prefix = ".",
include_prefix = "bsoncxx/config",
hdrs = ["config.hpp"],
)
cc_library(
name = "bsoncxx_version",
includes = ["."],
strip_include_prefix = ".",
include_prefix = "bsoncxx/config",
hdrs = ["version.hpp"],
)
"""
_mongocxx_config_build_file_contents = """
load("@rules_cc//cc:defs.bzl", "cc_library")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "mongocxx_config",
includes = ["."],
strip_include_prefix = ".",
include_prefix = "mongocxx/config",
hdrs = ["config.hpp"],
)
cc_library(
name = "mongocxx_private_config",
includes = ["."],
strip_include_prefix = ".",
include_prefix = "mongocxx/config",
hdrs = ["private/config.hh"],
)
cc_library(
name = "mongocxx_version",
includes = ["."],
strip_include_prefix = ".",
include_prefix = "mongocxx/config",
hdrs = ["version.hpp"],
)
"""
def _bsoncxx_config_implementation(rctx):
bsoncxx_version = "3.6.1."
rctx.template(
"config.hpp",
rctx.path(rctx.attr.bsoncxx_config_template),
executable = False,
substitutions = {
"#cmakedefine BSONCXX_POLY_USE_STD_EXPERIMENTAL": "",
"#cmakedefine BSONCXX_POLY_USE_MNMLSTC": "",
"#cmakedefine BSONCXX_POLY_USE_SYSTEM_MNMLSTC": "",
"#cmakedefine BSONCXX_POLY_USE_BOOST": "",
"#cmakedefine BSONCXX_POLY_USE_STD": "#define BSONCXX_POLY_USE_STD 1",
"@BSONCXX_INLINE_NAMESPACE@": "no_abi",
},
)
rctx.template(
"version.hpp",
rctx.path(rctx.attr.bsoncxx_version_template),
executable = False,
substitutions = {
"@BSONCXX_VERSION_MAJOR@": "({})".format(bsoncxx_version.split('.')[0]),
"@BSONCXX_VERSION_MINOR@": "({})".format(bsoncxx_version.split('.')[1]),
"@BSONCXX_VERSION_PATCH@": "({})".format(bsoncxx_version.split('.')[2]),
"@BSONCXX_VERSION_EXTRA@": "({})".format(bsoncxx_version.split('.')[3]),
},
)
rctx.file(
"BUILD.bazel",
content = _bsoncxx_config_build_file_contents,
executable = False,
)
_bsoncxx_config = repository_rule(
implementation = _bsoncxx_config_implementation,
attrs = {
"bsoncxx_config_template": attr.label(
default = Label("@bazelregistry_mongo_cxx_driver//src/bsoncxx:config/config.hpp.in"),
allow_single_file = True,
),
"bsoncxx_version_template": attr.label(
default = Label("@bazelregistry_mongo_cxx_driver//src/bsoncxx:config/version.hpp.in"),
allow_single_file = True,
),
},
)
def bsoncxx_config(**kwargs):
_bsoncxx_config(name = "bsoncxx_config", **kwargs)
def _mongocxx_config_implementation(rctx):
mongocxx_version = "3.6.1"
mongocxx_version_split = (mongocxx_version + ".").split('.')
rctx.template(
"config.hpp",
rctx.path(rctx.attr.mongocxx_config_template),
executable = False,
substitutions = {
"@MONGOCXX_INLINE_NAMESPACE@": "no_abi",
},
)
rctx.template(
"private/config.hh",
rctx.path(rctx.attr.mongocxx_private_config_template),
executable = False,
substitutions = {
"#cmakedefine MONGOCXX_ENABLE_SSL": "#define MONGOCXX_ENABLE_SSL",
},
)
rctx.template(
"version.hpp",
rctx.path(rctx.attr.mongocxx_version_template),
executable = False,
substitutions = {
"@MONGOCXX_VERSION@": mongocxx_version,
"@MONGOCXX_VERSION_MAJOR@": "({})".format(mongocxx_version_split[0]),
"@MONGOCXX_VERSION_MINOR@": "({})".format(mongocxx_version_split[1]),
"@MONGOCXX_VERSION_PATCH@": "({})".format(mongocxx_version_split[2]),
"@MONGOCXX_VERSION_EXTRA@": "({})".format(mongocxx_version_split[3]),
},
)
rctx.file(
"BUILD.bazel",
content = _mongocxx_config_build_file_contents,
executable = False,
)
_mongocxx_config = repository_rule(
implementation = _mongocxx_config_implementation,
attrs = {
"mongocxx_config_template": attr.label(
default = Label("@bazelregistry_mongo_cxx_driver//src/mongocxx:config/config.hpp.in"),
allow_single_file = True,
),
"mongocxx_private_config_template": attr.label(
default = Label("@bazelregistry_mongo_cxx_driver//src/mongocxx:config/private/config.hh.in"),
allow_single_file = True,
),
"mongocxx_version_template": attr.label(
default = Label("@bazelregistry_mongo_cxx_driver//src/mongocxx:config/version.hpp.in"),
allow_single_file = True,
),
},
)
def mongocxx_config(**kwargs):
_mongocxx_config(name = "mongocxx_config", **kwargs)