• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 Code Intelligence GmbH
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15def _add_cxxopt_std_17_impl(settings, attr):
16    STD_CXX_17_CXXOPTS = ["/std:c++17" if attr.is_windows else "-std=c++17"]
17    return {
18        "//command_line_option:cxxopt": settings["//command_line_option:cxxopt"] + STD_CXX_17_CXXOPTS,
19    }
20
21_add_cxxopt_std_17 = transition(
22    implementation = _add_cxxopt_std_17_impl,
23    inputs = [
24        "//command_line_option:cxxopt",
25    ],
26    outputs = [
27        "//command_line_option:cxxopt",
28    ],
29)
30
31def _cc_17_library_impl(ctx):
32    library = ctx.attr.library[0]
33    return [
34        # Workaround for https://github.com/bazelbuild/bazel/issues/9442.
35        DefaultInfo(
36            data_runfiles = library[DefaultInfo].data_runfiles,
37            default_runfiles = library[DefaultInfo].default_runfiles,
38            files = library[DefaultInfo].files,
39        ),
40        library[CcInfo],
41    ]
42
43_cc_17_library = rule(
44    implementation = _cc_17_library_impl,
45    attrs = {
46        "is_windows": attr.bool(),
47        "library": attr.label(
48            cfg = _add_cxxopt_std_17,
49            mandatory = True,
50            providers = [CcInfo],
51        ),
52        "_allowlist_function_transition": attr.label(
53            default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
54        ),
55    },
56    provides = [CcInfo],
57)
58
59# A cc_library that is built with -std=c++17, including all its transitive
60# dependencies. This is redundant while developing Jazzer itself as the .bazelrc
61# sets this flag for all build commands, but is needed when Jazzer is included
62# as an external workspace.
63def cc_17_library(name, visibility = None, **kwargs):
64    library_name = name + "_original_do_not_use_"
65    kwargs.setdefault("tags", []).append("manual")
66    native.cc_library(
67        name = library_name,
68        visibility = ["//visibility:private"],
69        **kwargs
70    )
71
72    _cc_17_library(
73        name = name,
74        is_windows = select({
75            "@platforms//os:windows": True,
76            "//conditions:default": False,
77        }),
78        library = library_name,
79        visibility = visibility,
80    )
81