blob: 4b7767a22a0f3f735dda280a962215c8cd3012a0 [file] [log] [blame]
Nathaniel Brough82cf6872021-02-16 15:51:57 +08001# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7# https://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, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15def _toolchain_upstream_repository_impl(rctx):
16 """Creates a remote repository with a set of toolchain components.
17
18 The bazel embedded toolchain expects two targets injected_headers
19 and polyfill. This is rule generates these targets so that
20 bazel-embedded can depend on them and so that the targets can depend
21 on pigweeds implementation of polyfill. This rule is only ever
22 intended to be instantiated with the name
23 "bazel_embedded_upstream_toolchain", and should only be used from
24 the "toolchain_upstream_deps" macro.
25
26 The bazel-embedded package expects to be able to access these
27 targets as @bazel_embedded_upstream_toolchain//:polyfill and
28 @bazel_embedded_upstream_toolchain//:injected_headers.
29
30 Args:
31 rctx: Repository context.
32 """
33 rctx.file("BUILD", """
34package(default_visibility = ["//visibility:public"])
35load(
36 "@bazel_embedded//toolchains/tools/include_tools:defs.bzl",
37 "cc_injected_toolchain_header_library",
38 "cc_polyfill_toolchain_library",
39)
40
41cc_polyfill_toolchain_library(
42 name = "polyfill",
43 deps = ["@pigweed//pw_polyfill:toolchain_polyfill_overrides"],
44)
45
46cc_injected_toolchain_header_library(
47 name = "injected_headers",
48 deps = ["@pigweed//pw_polyfill:toolchain_injected_headers"],
49)
50""")
51
52_toolchain_upstream_repository = repository_rule(
53 _toolchain_upstream_repository_impl,
54 doc = """
55toolchain_upstream_repository creates a remote repository that can be
56accessed by a toolchain repository to configure system includes.
57
58It's recommended to use this rule through the 'toolchain_upstream_deps'
59macro rather than using this rule directly.
60""",
61)
62
63def toolchain_upstream_deps():
64 """Implements the set of dependencies that bazel-embedded requires.
65
66 These targets are used to override the default toolchain
67 requirements in the remote bazel-embedded toolchain. The remote
68 toolchain expects to find two targets;
69 - "@bazel_embedded_upstream_toolchain//:polyfill" -> Additional
70 system headers for the toolchain
71 - "@bazel_embedded_upstream_toolchain//:injected_headers" ->
72 Headers that are injected into the toolchain via the -include
73 command line argument
74 """
75 _toolchain_upstream_repository(
76 name = "bazel_embedded_upstream_toolchain",
77 )