Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • bazel/toolchain_utils
1 result
Show changes
Commits on Source (3)
  • Matthew Clarkson's avatar
    feat: add `toolchain_info` rule · 11ea2416
    Matthew Clarkson authored
    BREAKING CHANGE: The `toolchain_symlink_target` no longer exports
    `ToolchainInfo`/`TemplateVariableInfo`.
    
    The `toolchain_info` can provide those providers. The `toolchain_symlink_target`
    is purely for creating a symlink to a previous target. This still enables
    changing the basename for multi-call binaries.
    
    To gain the old functionality, if `basename` attribute is not being used,
    `toolchain_symlink_target` can be switched directly for `toolchain_info`. If
    `basename` is being used, an extra `toolchain_info` rule will need to be created
    to wrap the `toolchain_symlink_target` rule.
    Verified
    11ea2416
  • Matthew Clarkson's avatar
    Merge branch 'main' into beta · be3b8686
    Matthew Clarkson authored
    Verified
    be3b8686
  • Bot's avatar
    chore(release): 1.0.0-beta.9 [skip ci] · 8e701fdc
    Bot authored
    # [1.0.0-beta.9](https://git.gitlab.arm.com/bazel/toolchain_utils/compare/v1.0.0-beta.8...v1.0.0-beta.9) (2024-05-03)
    
    ### Features
    
    * add `toolchain_info` rule ([11ea2416](https://git.gitlab.arm.com/bazel/toolchain_utils/commit/11ea241647f87759bebd2c5ce7a7b0bdba55953a))
    
    ### BREAKING CHANGES
    
    * The `toolchain_symlink_target` no longer exports
    `ToolchainInfo`/`TemplateVariableInfo`.
    
    The `toolchain_info` can provide those providers. The `toolchain_symlink_target`
    is purely for creating a symlink to a previous target. This still enables
    changing the basename for multi-call binaries.
    
    To gain the old functionality, if `basename` attribute is not being used,
    `toolchain_symlink_target` can be switched directly for `toolchain_info`. If
    `basename` is being used, an extra `toolchain_info` rule will need to be created
    to wrap the `toolchain_symlink_target` rule.
    8e701fdc
# [1.0.0-beta.9](https://git.gitlab.arm.com/bazel/toolchain_utils/compare/v1.0.0-beta.8...v1.0.0-beta.9) (2024-05-03)
### Features
- add `toolchain_info` rule ([11ea241](https://git.gitlab.arm.com/bazel/toolchain_utils/commit/11ea241647f87759bebd2c5ce7a7b0bdba55953a))
### BREAKING CHANGES
- The `toolchain_symlink_target` no longer exports
`ToolchainInfo`/`TemplateVariableInfo`.
The `toolchain_info` can provide those providers. The `toolchain_symlink_target`
is purely for creating a symlink to a previous target. This still enables
changing the basename for multi-call binaries.
To gain the old functionality, if `basename` attribute is not being used,
`toolchain_symlink_target` can be switched directly for `toolchain_info`. If
`basename` is being used, an extra `toolchain_info` rule will need to be created
to wrap the `toolchain_symlink_target` rule.
# [1.0.0-beta.8](https://git.gitlab.arm.com/bazel/toolchain_utils/compare/v1.0.0-beta.7...v1.0.0-beta.8) (2024-05-03)
### Bug Fixes
......
module(
name = "toolchain_utils",
version = "1.0.0-beta.8",
version = "1.0.0-beta.9",
bazel_compatibility = [
">=7.0.0",
],
......
load("@toolchain_utils//toolchain/symlink/target:defs.bzl", "toolchain_symlink_target")
load("@toolchain_utils//toolchain/info:defs.bzl", "toolchain_info")
load("@toolchain_utils//toolchain/test:defs.bzl", "toolchain_test")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
......@@ -13,7 +13,7 @@ toolchain(
toolchain_type = ":type",
)
toolchain_symlink_target(
toolchain_info(
name = "script",
target = select({
"@toolchain_utils//toolchain/constraint/os:windows": ":echo.bat",
......
load(":rule.bzl", _info = "info")
visibility("public")
toolchain_info = _info
visibility("//toolchain/...")
DOC = """Provides toolchain information and Make variables around a target.
Often used with downloaded binary targets:
```py
load("@toolchain_utils//toolchain/triplet:defs.bzl", "ToolchainTripletInfo")
toolchain_type(
name = "type",
)
# Setup a toolchain for each downloaded binary
[
(
toolchain_info(
name = "something-{}".format(triplet.value),
target = "@downloaded-{}//:something".format(triplet),
),
toolchain(
name = triplet.value,
toolchain = ":something-{}".format(triplet.value),
exec_compatible_with = triplet.constraints,
)
)
for triplet in (
ToolchainTripletInfo("arm64-linux-gnu"),
ToolchainTripletInfo("arm64-linux-musl"),
)
]
```
`rules_download` has a `download.archive` and `download.file` extension that can help with retrieving remote binaries.
"""
ATTRS = {
"target": attr.label(
doc = "The binary file to symlink.",
mandatory = True,
allow_files = True,
executable = True,
cfg = "exec",
),
"variable": attr.string(
doc = "The variable name for Make or the execution environment. Defaults to `name.upper()`",
),
"_windows": attr.label(
providers = [platform_common.ConstraintValueInfo],
default = "//toolchain/constraint/os:windows",
),
}
def implementation(ctx):
basename = ctx.label.name
variable = ctx.attr.variable or basename.upper()
windows = ctx.attr._windows[platform_common.ConstraintValueInfo]
target = ctx.executable.target
extension = target.extension
if extension in (".bat", ".cmd"):
basename = basename + extension
elif extension in ("bat", "cmd"):
basename = "{}.{}".format(basename, extension)
elif not extension and "." not in basename and ctx.target_platform_has_constraint(windows):
basename = "{}.exe".format(basename)
executable = ctx.actions.declare_file("{}/{}".format(ctx.label.name, basename))
ctx.actions.symlink(
output = executable,
target_file = target,
is_executable = True,
)
variables = platform_common.TemplateVariableInfo({
variable: executable.path,
})
runfiles = ctx.runfiles([executable, ctx.executable.target])
runfiles = runfiles.merge(ctx.attr.target.default_runfiles)
default = DefaultInfo(
executable = executable,
files = depset([executable]),
runfiles = runfiles,
)
toolchain = platform_common.ToolchainInfo(
variables = variables,
default = ctx.attr.target[DefaultInfo],
executable = ctx.executable.target,
run = ctx.attr.target.files_to_run or ctx.executable.target,
)
return [variables, toolchain, default]
toolchain_info = rule(
doc = DOC,
attrs = ATTRS,
implementation = implementation,
provides = [
platform_common.TemplateVariableInfo,
platform_common.ToolchainInfo,
DefaultInfo,
],
executable = True,
)
info = toolchain_info
load("@toolchain_utils//toolchain/symlink/path:defs.bzl", "toolchain_symlink_path")
load("@toolchain_utils//toolchain/symlink/target:defs.bzl", "toolchain_symlink_target")
load("@toolchain_utils//toolchain/info:defs.bzl", "toolchain_info")
exports_files(
["entrypoint"],
......@@ -8,14 +8,13 @@ exports_files(
toolchain_symlink_path(
name = "symlink",
basename = "{{basename}}",
path = "{{path}}",
tags = ["no-remote"],
)
toolchain_symlink_target(
toolchain_info(
name = "{{target}}",
basename = "{{basename}}",
tags = ["no-remote"],
target = ":symlink",
variable = "{{variable}}",
visibility = ["//visibility:public"],
......
......@@ -2,38 +2,17 @@ visibility("//toolchain/...")
DOC = """Creates a executable symlink to a binary target file.
This rule can be used to symlink a executable target and export the necessary toolchain providers.
This rule can be used to symlink a executable target and change the basename. Useful for multi-call binaries.
Often used with downloaded binary targets:
```py
load("@toolchain_utils//toolchain/triplet:defs.bzl", "ToolchainTripletInfo")
toolchain_type(
name = "type",
toolchain_symlink_target(
name = "something",
basename = "ls",
target = ":busybox",
)
# Setup a toolchain for each downloaded binary
[
(
toolchain_symlink_target(
name = "something-{}".format(triplet.value),
target = "@downloaded-{}//:something".format(triplet),
),
toolchain(
name = triplet.value,
toolchain = ":something-{}".format(triplet.value),
exec_compatible_with = triplet.constraints,
)
)
for triplet in (
ToolchainTripletInfo("arm64-linux-gnu"),
ToolchainTripletInfo("arm64-linux-musl"),
)
]
```
`rules_download` has a `download.archive` and `download.file` extension that can help with retrieving remote binaries.
"""
ATTRS = {
......@@ -47,9 +26,6 @@ ATTRS = {
"basename": attr.string(
doc = "The basename for the symlink, which defaults to `name`",
),
"variable": attr.string(
doc = "The variable name for Make or the execution environment. Defaults to `basename.upper()`",
),
"_windows": attr.label(
providers = [platform_common.ConstraintValueInfo],
default = "//toolchain/constraint/os:windows",
......@@ -58,7 +34,6 @@ ATTRS = {
def implementation(ctx):
basename = ctx.attr.basename or ctx.label.name
variable = ctx.attr.variable or basename.upper()
windows = ctx.attr._windows[platform_common.ConstraintValueInfo]
target = ctx.executable.target
......@@ -77,36 +52,18 @@ def implementation(ctx):
is_executable = True,
)
variables = platform_common.TemplateVariableInfo({
variable: executable.path,
})
runfiles = ctx.runfiles([executable, ctx.executable.target])
runfiles = runfiles.merge(ctx.attr.target.default_runfiles)
default = DefaultInfo(
return DefaultInfo(
executable = executable,
files = depset([executable]),
runfiles = runfiles,
)
toolchain = platform_common.ToolchainInfo(
variables = variables,
default = ctx.attr.target[DefaultInfo],
executable = ctx.executable.target,
run = ctx.attr.target.files_to_run or ctx.executable.target,
)
return [variables, toolchain, default]
target = rule(
doc = DOC,
attrs = ATTRS,
implementation = implementation,
provides = [
platform_common.TemplateVariableInfo,
platform_common.ToolchainInfo,
DefaultInfo,
],
executable = True,
)