blob: a77cce6bed05325b6c2940f952f25fadd8942c9d [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.
Rob Mohrd1a14062021-08-16 12:38:38 -070014"""Implements the set of dependencies that bazel-embedded requires."""
Nathaniel Brough82cf6872021-02-16 15:51:57 +080015
16def _toolchain_upstream_repository_impl(rctx):
17 """Creates a remote repository with a set of toolchain components.
18
19 The bazel embedded toolchain expects two targets injected_headers
20 and polyfill. This is rule generates these targets so that
21 bazel-embedded can depend on them and so that the targets can depend
22 on pigweeds implementation of polyfill. This rule is only ever
23 intended to be instantiated with the name
24 "bazel_embedded_upstream_toolchain", and should only be used from
25 the "toolchain_upstream_deps" macro.
26
27 The bazel-embedded package expects to be able to access these
28 targets as @bazel_embedded_upstream_toolchain//:polyfill and
29 @bazel_embedded_upstream_toolchain//:injected_headers.
30
31 Args:
32 rctx: Repository context.
33 """
34 rctx.file("BUILD", """
35package(default_visibility = ["//visibility:public"])
36load(
37 "@bazel_embedded//toolchains/tools/include_tools:defs.bzl",
38 "cc_injected_toolchain_header_library",
39 "cc_polyfill_toolchain_library",
40)
41
42cc_polyfill_toolchain_library(
43 name = "polyfill",
44 deps = ["@pigweed//pw_polyfill:toolchain_polyfill_overrides"],
45)
46
47cc_injected_toolchain_header_library(
48 name = "injected_headers",
49 deps = ["@pigweed//pw_polyfill:toolchain_injected_headers"],
50)
51""")
52
53_toolchain_upstream_repository = repository_rule(
54 _toolchain_upstream_repository_impl,
55 doc = """
56toolchain_upstream_repository creates a remote repository that can be
57accessed by a toolchain repository to configure system includes.
58
59It's recommended to use this rule through the 'toolchain_upstream_deps'
60macro rather than using this rule directly.
61""",
62)
63
64def toolchain_upstream_deps():
65 """Implements the set of dependencies that bazel-embedded requires.
66
67 These targets are used to override the default toolchain
68 requirements in the remote bazel-embedded toolchain. The remote
69 toolchain expects to find two targets;
70 - "@bazel_embedded_upstream_toolchain//:polyfill" -> Additional
71 system headers for the toolchain
72 - "@bazel_embedded_upstream_toolchain//:injected_headers" ->
73 Headers that are injected into the toolchain via the -include
74 command line argument
75 """
76 _toolchain_upstream_repository(
77 name = "bazel_embedded_upstream_toolchain",
78 )