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')
|
2022-09-14 03:37:24 +00:00
|
|
|
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
|
2022-09-14 04:58:08 +00:00
|
|
|
|
|
|
|
package(default_visibility = ['//visibility:public'])
|
|
|
|
|
|
|
|
platform(name = 'host',
|
|
|
|
# Auto-detected host platform constraints.
|
|
|
|
constraint_values = HOST_CONSTRAINTS,
|
|
|
|
)
|
|
|
|
|
2022-09-13 03:45:48 +00:00
|
|
|
bzl_library(
|
|
|
|
name = "constraints",
|
|
|
|
srcs = ["constraints.bzl"],
|
|
|
|
visibility = ["//visibility:public"],
|
|
|
|
)
|
2022-09-14 04:58:08 +00:00
|
|
|
""")
|
|
|
|
|
|
|
|
# TODO: we can detect the host CPU in the future as well if needed;
|
|
|
|
# see the repo_utils.platform(rctx) function for an example of this
|
|
|
|
if repo_utils.is_darwin(rctx):
|
|
|
|
rctx.file("constraints.bzl", content = """HOST_CONSTRAINTS = [
|
|
|
|
'@platforms//cpu:x86_64',
|
|
|
|
'@platforms//os:osx',
|
|
|
|
]
|
|
|
|
""")
|
|
|
|
elif repo_utils.is_windows(rctx):
|
|
|
|
rctx.file("constraints.bzl", content = """HOST_CONSTRAINTS = [
|
|
|
|
'@platforms//cpu:x86_64',
|
|
|
|
'@platforms//os:windows',
|
|
|
|
]
|
|
|
|
""")
|
|
|
|
else:
|
|
|
|
rctx.file("constraints.bzl", content = """HOST_CONSTRAINTS = [
|
|
|
|
'@platforms//cpu:x86_64',
|
|
|
|
'@platforms//os:linux',
|
|
|
|
]
|
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.
|
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
|
|
|
)
|