Nathaniel Brough | 82cf687 | 2021-02-16 15:51:57 +0800 | [diff] [blame] | 1 | # 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 Mohr | d1a1406 | 2021-08-16 12:38:38 -0700 | [diff] [blame] | 14 | """Implements the set of dependencies that bazel-embedded requires.""" |
Nathaniel Brough | 82cf687 | 2021-02-16 15:51:57 +0800 | [diff] [blame] | 15 | |
| 16 | def _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", """ |
| 35 | package(default_visibility = ["//visibility:public"]) |
| 36 | load( |
| 37 | "@bazel_embedded//toolchains/tools/include_tools:defs.bzl", |
| 38 | "cc_injected_toolchain_header_library", |
| 39 | "cc_polyfill_toolchain_library", |
| 40 | ) |
| 41 | |
| 42 | cc_polyfill_toolchain_library( |
| 43 | name = "polyfill", |
| 44 | deps = ["@pigweed//pw_polyfill:toolchain_polyfill_overrides"], |
| 45 | ) |
| 46 | |
| 47 | cc_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 = """ |
| 56 | toolchain_upstream_repository creates a remote repository that can be |
| 57 | accessed by a toolchain repository to configure system includes. |
| 58 | |
| 59 | It's recommended to use this rule through the 'toolchain_upstream_deps' |
| 60 | macro rather than using this rule directly. |
| 61 | """, |
| 62 | ) |
| 63 | |
| 64 | def 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 | ) |