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/rules_coreutils
1 result
Show changes
Commits on Source (10)
Showing
with 4089 additions and 998 deletions
# `bzlmod` pre-release registries
common --registry https://bcr.bazel.build
common --registry=https://gitlab.arm.com/bazel/rules_toolchain/-/releases/v1.0.0-alpha.9/downloads
common --registry=https://gitlab.arm.com/bazel/rules_download/-/releases/v1.0.0-alpha.4/downloads
common --registry=https://gitlab.arm.com/bazel/rules_toolchain/-/releases/v1.0.0-alpha.11/downloads
common --registry=https://gitlab.arm.com/bazel/rules_download/-/releases/v1.0.0-alpha.5/downloads
# Build cache
build --experimental_guard_against_concurrent_changes
......
# [1.0.0-alpha.2](https://git.gitlab.arm.com/bazel/rules_coreutils/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2023-12-13)
### Bug Fixes
- correct resolved basename ([e60af5f](https://git.gitlab.arm.com/bazel/rules_coreutils/commit/e60af5f849e2709e6a09ac003728dea0b74ad35a))
### chore
- remove `symlinks` target ([0df7df6](https://git.gitlab.arm.com/bazel/rules_coreutils/commit/0df7df64b42985f09630dd3f2d9f7511637a9ce9))
### Features
- export `coreutils` ([3cb27e5](https://git.gitlab.arm.com/bazel/rules_coreutils/commit/3cb27e563575e863bdb1d5bd0c6c8b12366c7fda))
- expose all toolchains ([5b68793](https://git.gitlab.arm.com/bazel/rules_coreutils/commit/5b68793aadd9632b060339d7db1c3efa3f82b4f5))
- local toolchains fail fast when tool is not found ([e1009be](https://git.gitlab.arm.com/bazel/rules_coreutils/commit/e1009be1a8a76e3520d300ae93dff1bf8fa53a36))
### BREAKING CHANGES
- Remove `symlinks` target.
Is not supported on Windows unless `--enable-symlinks` is provided.
We _really_ want this ruleset to provide a common base for rulessets.
Having something that only works on certain platforms is not what we want.
Users of the ruleset should use the individual toolchains or multi-call binaries.
# 1.0.0-alpha.1 (2023-12-13)
### Bug Fixes
......
module(
name = "rules_coreutils",
version = "1.0.0-alpha.1",
version = "1.0.0-alpha.2",
bazel_compatibility = [
">=7.0.0",
],
compatibility_level = 1,
)
bazel_dep(name = "rules_toolchain", version = "1.0.0-alpha.9")
bazel_dep(name = "rules_download", version = "1.0.0-alpha.4")
bazel_dep(name = "rules_toolchain", version = "1.0.0-alpha.11")
bazel_dep(name = "rules_download", version = "1.0.0-alpha.5")
archive = use_repo_rule("@rules_download//download/archive:defs.bzl", "download_archive")
archive(
name = "coreutils-arm64-linux-gnu",
srcs = ["coreutils"],
srcs = ["entrypoint"],
integrity = "sha256-8wMVMgAgf8JQ2+2LdoewkyDo416VEsf9RlMJl4jiBjk=",
strip_prefix = "coreutils-0.0.23-aarch64-unknown-linux-gnu",
symlinks = {
"coreutils": "entrypoint",
},
urls = ["https://github.com/uutils/coreutils/releases/download/0.0.23/coreutils-0.0.23-aarch64-unknown-linux-gnu.tar.gz"],
)
archive(
name = "coreutils-amd64-linux-gnu",
srcs = ["coreutils"],
srcs = ["entrypoint"],
integrity = "sha256-u7OMW43Y46aXRRIKULfKdfUW51WJn6G70s5Xxwb6/1g=",
strip_prefix = "coreutils-0.0.23-x86_64-unknown-linux-gnu",
symlinks = {
"coreutils": "entrypoint",
},
urls = ["https://github.com/uutils/coreutils/releases/download/0.0.23/coreutils-0.0.23-x86_64-unknown-linux-gnu.tar.gz"],
)
archive(
name = "coreutils-amd64-windows-msvc",
srcs = ["coreutils"],
commands = {
"hardlink": ["$(location //coreutils:hardlink.bat)"],
},
srcs = ["entrypoint"],
integrity = "sha256-aglIj5JvFGLm2ABwRzWAsZRTTD3X444V3GxHM9pGJS4=",
strip_prefix = "coreutils-0.0.23-x86_64-pc-windows-msvc",
tools = [
"//coreutils:hardlink.bat",
],
symlinks = {
"coreutils.exe": "entrypoint",
},
urls = ["https://github.com/uutils/coreutils/releases/download/0.0.23/coreutils-0.0.23-x86_64-pc-windows-msvc.zip"],
)
select = use_repo_rule("@rules_toolchain//toolchain/local/select:defs.bzl", "toolchain_local_select")
select(
name = "coreutils",
map = {
"amd64-linux-gnu": "@coreutils-amd64-linux-gnu",
"arm64-linux-gnu": "@coreutils-arm64-linux-gnu",
"amd64-windows": "@coreutils-amd64-windows-msvc",
},
)
export = use_extension("@rules_toolchain//toolchain/export:defs.bzl", "toolchain_export")
export.symlink(
name = "coreutils",
target = "@coreutils",
)
deb = use_repo_rule("@rules_download//download/deb:defs.bzl", "download_deb")
deb(
......@@ -62,37 +82,87 @@ deb(
resolved = use_repo_rule("@rules_toolchain//toolchain/resolved:defs.bzl", "toolchain_resolved")
which = use_repo_rule("@rules_toolchain//toolchain/local/which:defs.bzl", "toolchain_local_which")
[
(
resolved(
name = tool,
name = "resolved-{}".format(tool),
basename = tool,
toolchain_type = "//coreutils/toolchain/{}:type".format(tool),
),
register_toolchains("//coreutils/toolchain/{}:all".format(tool)),
)
for tool in (
"busybox",
"coreutils",
)
]
which = use_repo_rule("@rules_toolchain//toolchain/local/which:defs.bzl", "toolchain_local_which")
[
(
which(
name = tool,
name = "which-{}".format(tool),
basename = tool,
toolchain_type = "//coreutils/toolchain/{}:type".format(tool),
),
register_toolchains("//coreutils/toolchain/{}:all".format(tool)),
)
for tool in (
"busybox",
"coreutils",
"arch",
"base64",
"basename",
"cat",
"cp",
"cut",
"date",
"dd",
"truncate",
"df",
"dirname",
"du",
"echo",
"env",
"expand",
"expr",
"factor",
"false",
"fold",
"head",
"hostname",
"link",
"ln",
"ls",
"md5sum",
"mkdir",
"cp",
"mktemp",
"more",
"mv",
"nl",
"nproc",
"od",
"paste",
"printf",
"pwd",
"readlink",
"realpath",
"rm",
"rmdir",
"seq",
"sha1sum",
"sha256sum",
"sha3sum",
"sha512sum",
"shred",
"shuf",
"sleep",
"sort",
"sync",
"tac",
"tail",
"tee",
"test",
"touch",
"tr",
"true",
"truncate",
"uname",
"unexpand",
"uniq",
"unlink",
"wc",
"whoami",
"yes",
)
]
register_toolchains("//coreutils/toolchain/...")
This diff is collapsed.
......@@ -29,22 +29,21 @@ something = rule(
)
```
### Symlinks
### Entrypoint
The preference is for declaring each toolchain needed in a rule.
The `coreutils` multi-call binary is exported for use in hermetic repository rules.
A convenience target is provided that symlinks all core utilites under the `coreutils/bin` directory in the sandbox:
Use the repository from the export extension in `MODULE.bazel`:
```
some = rule(
data = [
"@rules_coreutils//coreutils:bin",
],
```py
export = use_extension("@rules_toolchain//toolchain/export:defs.bzl", "toolchain_export")
use_repo(export, "coreutils")
some_repo_rule(
coreutils = "@coreutils",
)
```
If the rule implementation adds `coreutils/bin` to the `PATH` it will have access to hermetically resolved `coreutils`.
## Implementations
Various implementations of the core utilties are resolved depending on the platform.
......@@ -55,10 +54,4 @@ Toolchains _may_ resolve to particular implementations such as GNU on certain pl
It is recommended to stick to the [POSIX specified usage][posix] of the core utilities.
Individual toolchains can be overridden on the command line to different implementations:
```sh
bazelisk --extra_toolchains=@rules_coreutils//coreutils/toolchain/cp:coreutils
```
[posix]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap04.html#tag_20
load(":tools.bzl", "SUBCOMMANDS")
load(":symlinks.bzl", "symlinks")
symlinks(
name = "symlinks",
)
alias(
name = "bin",
actual = "symlinks",
visibility = ["//visibility:public"],
)
alias(
name = "coreutils",
actual = "bin",
visibility = ["//visibility:public"],
)
sh_test(
name = "sh",
srcs = ["symlinks.sh"],
args = SUBCOMMANDS,
data = [":symlinks"],
# TODO: re-enable this when `sh_test` does not require a C/C++ toolchain
tags = ["manual"],
)
@mklink /h coreutils coreutils.exe
\ No newline at end of file
Hello, world!
load(":tools.bzl", "SUBCOMMANDS")
visibility("//coreutils/...")
DOC = """Provides core utilities symlinked at the `coreutils` directory in the sandbox.
```py
symlinks(
name = "coreutils",
)
something(
name = "foobar",
data = [
":coreutils",
],
)
```
It is recommended to use the canonial `@rules_coreutils//coreutils` target.
"""
ATTRS = {
"path": attr.string(
doc = "A path to symlink the core utilites.",
default = "coreutils/bin",
),
}
def implementation(ctx):
toolchains = {s: ctx.toolchains["//coreutils/toolchain/{}:type".format(s)] for s in SUBCOMMANDS}
symlinks = {"{}/{}".format(ctx.attr.path, k): v.executable for k, v in toolchains.items()}
runfiles = ctx.runfiles(symlinks = symlinks)
return DefaultInfo(runfiles = runfiles)
symlinks = rule(
doc = DOC,
attrs = ATTRS,
implementation = implementation,
toolchains = ["//coreutils/toolchain/{}:type".format(s) for s in SUBCOMMANDS],
)
#! /bin/sh
# e: quit on command errors
# u: quit on undefined variables
set -eu
# Redirect `stderr` to JUnit file
if ! test -z ${XML_OUTPUT_FILE+x}; then
exec 2>&-
exec 2<>"${XML_OUTPUT_FILE}"
fi
# Output TAP to `stdout`
# Output JUnit to `stderr`
printf "1..%i\n" "${#}"
printf >&2 '<testsuite tests="%s">\n' "${#}"
INDEX=0
FAILS=0
for SUBCOMMAND in "${@}"; do
INDEX=$((INDEX + 1))
FILEPATH="coreutils/bin/${SUBCOMMAND}"
if ! test -f "${FILEPATH}"; then
printf >&2 '<testcase name "%s"/>\n' "${FILEPATH}"
printf >&2 '<failure type="NotFound">%s is not found</failure>\n' "${FILEPATH}"
printf >&2 '</testcase>\n'
printf 'not ok %i - %s is not found\n' "${INDEX}" "${FILEPATH}"
FAILS=$((FAILS + 1))
continue
elif ! test -L "${FILEPATH}"; then
printf >&2 '<testcase name "%s"/>\n' "${FILEPATH}"
printf >&2 '<failure type="NotLink">%s is not a symlink</failure>\n' "${FILEPATH}"
printf >&2 '</testcase>\n'
printf 'not ok %i - %s is not a symlink\n' "${INDEX}" "${FILEPATH}"
FAILS=$((FAILS + 1))
continue
elif ! test -x "${FILEPATH}"; then
printf >&2 '<testcase name "%s"/>\n' "${FILEPATH}"
printf >&2 '<failure type="NotExecutable">%s is not executable</failure>\n' "${FILEPATH}"
printf >&2 '</testcase>\n'
printf 'not ok %i - %s is not executable\n' "${INDEX}" "${FILEPATH}"
FAILS=$((FAILS + 1))
continue
else
printf >&2 '<testcase name="%s"/>\n' "${FILEPATH}"
printf 'ok %i - %s\n' "${INDEX}" "${FILEPATH}"
fi
done
printf >&2 '</testsuite>\n'
exit "${FAILS}"
load("@rules_toolchain//toolchain/test:defs.bzl", "toolchain_test")
load("//coreutils/toolchain/busybox:toolchains.bzl", busybox = "toolchains")
load("//coreutils/toolchain/coreutils:toolchains.bzl", coreutils = "toolchains")
toolchain_type(
name = "type",
visibility = ["//visibility:public"],
)
toolchain(
name = "local",
toolchain = "@which-arch",
toolchain_type = ":type",
)
coreutils(
basename = "arch",
toolchain_type = ":type",
)
busybox(
basename = "arch",
toolchain_type = ":type",
)
alias(
name = "resolved",
actual = "@resolved-arch",
)
toolchain_test(
name = "test",
size = "small",
args = ["--help"],
stderr = "@rules_toolchain//toolchain/test:any",
stdout = "@rules_toolchain//toolchain/test:any",
toolchains = [":resolved"],
)
load("@rules_toolchain//toolchain/test:defs.bzl", "toolchain_test")
load("//coreutils/toolchain/busybox:toolchains.bzl", busybox = "toolchains")
load("//coreutils/toolchain/coreutils:toolchains.bzl", coreutils = "toolchains")
toolchain_type(
name = "type",
visibility = ["//visibility:public"],
)
toolchain(
name = "local",
toolchain = "@which-base64",
toolchain_type = ":type",
)
coreutils(
basename = "base64",
toolchain_type = ":type",
)
busybox(
basename = "base64",
toolchain_type = ":type",
)
alias(
name = "resolved",
actual = "@resolved-base64",
)
toolchain_test(
name = "test",
size = "small",
args = ["--help"],
stderr = "@rules_toolchain//toolchain/test:any",
stdout = "@rules_toolchain//toolchain/test:any",
toolchains = [":resolved"],
)
load("@rules_toolchain//toolchain/test:defs.bzl", "toolchain_test")
load("//coreutils/toolchain/busybox:toolchains.bzl", busybox = "toolchains")
load("//coreutils/toolchain/coreutils:toolchains.bzl", coreutils = "toolchains")
toolchain_type(
name = "type",
visibility = ["//visibility:public"],
)
toolchain(
name = "local",
toolchain = "@which-basename",
toolchain_type = ":type",
)
coreutils(
basename = "basename",
toolchain_type = ":type",
)
busybox(
basename = "basename",
toolchain_type = ":type",
)
alias(
name = "resolved",
actual = "@resolved-basename",
)
toolchain_test(
name = "test",
size = "small",
args = ["--help"],
stderr = "@rules_toolchain//toolchain/test:any",
stdout = "@rules_toolchain//toolchain/test:any",
toolchains = [":resolved"],
)
......@@ -6,6 +6,12 @@ toolchain_type(
visibility = ["//visibility:public"],
)
toolchain(
name = "local",
toolchain = "@which-coreutils",
toolchain_type = ":type",
)
toolchains(
basename = "busybox",
toolchain_type = ":type",
......@@ -13,7 +19,7 @@ toolchains(
alias(
name = "resolved",
actual = "@busybox//:resolved",
actual = "@resolved-busybox",
)
toolchain_test(
......
load("@rules_toolchain//toolchain/test:defs.bzl", "toolchain_test")
load("//coreutils/toolchain/busybox:toolchains.bzl", busybox = "toolchains")
load("//coreutils/toolchain/coreutils:toolchains.bzl", coreutils = "toolchains")
toolchain_type(
name = "type",
visibility = ["//visibility:public"],
)
toolchain(
name = "local",
toolchain = "@which-cat",
toolchain_type = ":type",
)
coreutils(
basename = "cat",
toolchain_type = ":type",
)
busybox(
basename = "cat",
toolchain_type = ":type",
)
alias(
name = "resolved",
actual = "@resolved-cat",
)
toolchain_test(
name = "test",
size = "small",
args = ["--help"],
stderr = "@rules_toolchain//toolchain/test:any",
stdout = "@rules_toolchain//toolchain/test:any",
toolchains = [":resolved"],
)
......@@ -6,6 +6,12 @@ toolchain_type(
visibility = ["//visibility:public"],
)
toolchain(
name = "local",
toolchain = "@which-coreutils",
toolchain_type = ":type",
)
toolchains(
basename = "coreutils",
toolchain_type = ":type",
......@@ -13,7 +19,7 @@ toolchains(
alias(
name = "resolved",
actual = "@coreutils//:resolved",
actual = "@resolved-coreutils",
)
toolchain_test(
......
......@@ -8,21 +8,21 @@ def toolchains(*, basename, toolchain_type, variable = None):
toolchain_symlink_target(
name = "coreutils-amd64-linux-gnu",
target = "@coreutils-amd64-linux-gnu//:coreutils",
target = "@coreutils-amd64-linux-gnu//:entrypoint",
basename = basename,
variable = variable,
)
toolchain_symlink_target(
name = "coreutils-arm64-linux-gnu",
target = "@coreutils-arm64-linux-gnu//:coreutils",
target = "@coreutils-arm64-linux-gnu//:entrypoint",
basename = basename,
variable = variable,
)
toolchain_symlink_target(
name = "coreutils-amd64-windows-msvc",
target = "@coreutils-amd64-windows-msvc//:coreutils",
target = "@coreutils-amd64-windows-msvc//:entrypoint",
basename = basename,
variable = variable,
)
......
......@@ -9,7 +9,7 @@ toolchain_type(
toolchain(
name = "local",
toolchain = "@cp",
toolchain = "@which-cp",
toolchain_type = ":type",
)
......@@ -25,7 +25,7 @@ busybox(
alias(
name = "resolved",
actual = "@cp//:resolved",
actual = "@resolved-cp",
)
toolchain_test(
......
load("@rules_toolchain//toolchain/test:defs.bzl", "toolchain_test")
load("//coreutils/toolchain/busybox:toolchains.bzl", busybox = "toolchains")
load("//coreutils/toolchain/coreutils:toolchains.bzl", coreutils = "toolchains")
toolchain_type(
name = "type",
visibility = ["//visibility:public"],
)
toolchain(
name = "local",
toolchain = "@which-cut",
toolchain_type = ":type",
)
coreutils(
basename = "cut",
toolchain_type = ":type",
)
busybox(
basename = "cut",
toolchain_type = ":type",
)
alias(
name = "resolved",
actual = "@resolved-cut",
)
toolchain_test(
name = "test",
size = "small",
args = ["--help"],
stderr = "@rules_toolchain//toolchain/test:any",
stdout = "@rules_toolchain//toolchain/test:any",
toolchains = [":resolved"],
)
load("@rules_toolchain//toolchain/test:defs.bzl", "toolchain_test")
load("//coreutils/toolchain/busybox:toolchains.bzl", busybox = "toolchains")
load("//coreutils/toolchain/coreutils:toolchains.bzl", coreutils = "toolchains")
toolchain_type(
name = "type",
visibility = ["//visibility:public"],
)
toolchain(
name = "local",
toolchain = "@which-date",
toolchain_type = ":type",
)
coreutils(
basename = "date",
toolchain_type = ":type",
)
busybox(
basename = "date",
toolchain_type = ":type",
)
alias(
name = "resolved",
actual = "@resolved-date",
)
toolchain_test(
name = "test",
size = "small",
args = ["--help"],
stderr = "@rules_toolchain//toolchain/test:any",
stdout = "@rules_toolchain//toolchain/test:any",
toolchains = [":resolved"],
)