Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
# rules_shell
# Bazel `rules_shell`

This repository contains the Bazel ruleset for shell scripts.
[`rules_shell`](https://github.com/bazelbuild/rules_shell) is an experimental Bazel ruleset maintained by the Bazel team that enables modern, hermetic support for writing Bazel targets using shell scripts.

---

## Purpose

The goal of `rules_shell` is to make working with shell scripts in Bazel more robust and reproducible, similar to how Bazel handles other languages like Go (`rules_go`) or Python (`rules_python`).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a stab at this, but I fear that we don't really live up to this promise just yet. This ruleset is more or less a faithful port of the formerly native shell rules, it's not (yet) more robust or reproducible.

There is an active proposal for integrating ctx.actions.run_shell with rules_shell as well as providing a PATH of hermetic shell tools. I would like to wait for that to be implemented before we claim this.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any README.md that you'd be able to add to give some indication to how rules_shell is supposed to be used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filmil
Thanks for your response

Sorry I'm not sure who you are asking

In general, this merge request was mostly intended to highlight that rules_shell isn't well documented. In particular, it is unclear [at least to a fool like me] what rules_shell is intending to achieve.

I strongly suspect that that team who wrote rules_shell did have a clear intent and do understand what rules_shell all about. - It would really help others to document this even minimally. It might even help the experts who do understand to stay on track :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question was for @fmeum . It would be nice if a maintainer would bootstrap a README.md with main points to know about the rule set.


---

## Key Features

- **Hermetic `sh_binary` and `sh_test` rules**
- Declare and manage script dependencies explicitly
- Scripts only access files and tools declared as inputs

- **Shell toolchain support**
- Customizable shell interpreter (e.g., specific `bash` version)
- Cross-platform support via toolchain configuration

- **Reproducibility and sandboxing**
- Ensures scripts only access declared inputs
- Improves remote caching and build determinism

---

## Example

Here’s a simple example of a shell binary using `rules_shell`:

```python
load("@rules_shell//shell:defs.bzl", "sh_binary")

sh_binary(
name = "hello",
srcs = ["hello.sh"],
data = [":greeting.txt"],
deps = ["@bash//:bin/bash"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this could be realized as the script needs some shebang that would run first. If we want it to be truly hermetic, we would need to involve a launcher binary, a simple dep wouldn't help.

)
```

## Dependancies

Please note that rules_shell depends on bash outside of the Bazel sandbox

```
_DEFAULT_SHELL_PATHS = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention that these are the default paths, but that you can register your own toolchains and/or set BAZEL_SH.

"windows": "c:/msys64/usr/bin/bash.exe",
"linux": "/bin/bash",
"osx": "/bin/bash",
"freebsd": "/usr/local/bin/bash",
"openbsd": "/usr/local/bin/bash",
}
```
[sh_config.bzl](https://github.com/bazelbuild/rules_shell/blob/main/shell/private/repositories/sh_config.bzl#L18)