2022-09-14 03:37:24 +00:00
|
|
|
"""local_config_platform repository rule
|
2022-09-13 03:45:48 +00:00
|
|
|
"""
|
|
|
|
|
2022-09-14 04:58:08 +00:00
|
|
|
load(":repo_utils.bzl", "repo_utils")
|
2022-09-13 03:45:48 +00:00
|
|
|
|
2022-09-14 04:58:08 +00:00
|
|
|
def _impl(rctx):
|
|
|
|
rctx.file("BUILD.bazel", """load(':constraints.bzl', 'HOST_CONSTRAINTS')
|
|
|
|
|
|
|
|
package(default_visibility = ['//visibility:public'])
|
|
|
|
|
|
|
|
platform(name = 'host',
|
|
|
|
# Auto-detected host platform constraints.
|
|
|
|
constraint_values = HOST_CONSTRAINTS,
|
|
|
|
)
|
|
|
|
|
2022-11-04 22:11:14 +00:00
|
|
|
exports_files([
|
|
|
|
# Export constraints.bzl for use in downstream bzl_library targets.
|
|
|
|
'constraints.bzl',
|
|
|
|
])
|
2022-09-14 04:58:08 +00:00
|
|
|
""")
|
|
|
|
|
2022-10-07 19:41:31 +00:00
|
|
|
[os, cpu] = repo_utils.platform(rctx).split("_")
|
|
|
|
cpu_constraint = "@platforms//cpu:{0}".format("x86_64" if cpu == "amd64" else cpu)
|
|
|
|
os_constraint = "@platforms//os:{0}".format("osx" if os == "darwin" else os)
|
|
|
|
|
|
|
|
rctx.file("constraints.bzl", content = """HOST_CONSTRAINTS = [
|
|
|
|
'{0}',
|
|
|
|
'{1}',
|
2022-09-14 04:58:08 +00:00
|
|
|
]
|
2022-10-07 19:41:31 +00:00
|
|
|
""".format(cpu_constraint, os_constraint))
|
2022-09-13 03:45:48 +00:00
|
|
|
|
|
|
|
local_config_platform = repository_rule(
|
|
|
|
implementation = _impl,
|
2022-09-14 04:58:08 +00:00
|
|
|
doc = """Generates a repository in the same shape as the auto-generated @local_config_platform repository with an added bzl_library.
|
2023-02-17 18:12:41 +00:00
|
|
|
|
2022-09-14 03:37:24 +00:00
|
|
|
This is useful for rules that want to load `HOST_CONSTRAINTS` from `@local_config_platform//:constraints.bzl` and
|
|
|
|
also want to use stardoc for generating documentation.
|
|
|
|
""",
|
2022-09-13 03:45:48 +00:00
|
|
|
)
|