All Projects → tweag → rules_sh

tweag / rules_sh

Licence: Apache-2.0 License
Shell rules for Bazel

Programming Languages

Starlark
911 projects

Labels

Projects that are alternatives of or similar to rules sh

migration-tooling
Migration tools for Bazel
Stars: ✭ 40 (+122.22%)
Mutual labels:  bazel
bazel-demo
Simple demo for building a TypeScript project with Bazel.
Stars: ✭ 40 (+122.22%)
Mutual labels:  bazel
bazel.cmake
bazel.cmake mimics the behavior of bazel to simplify the usability of CMake
Stars: ✭ 38 (+111.11%)
Mutual labels:  bazel
bazel-cache
Minimal cloud oriented Bazel gRPC cache
Stars: ✭ 33 (+83.33%)
Mutual labels:  bazel
bazel-vscode
Proof-of-concept (POC) of a Bazel Java development extension for VS Code
Stars: ✭ 16 (-11.11%)
Mutual labels:  bazel
rules poetry
Bazel rules that use Poetry for Python package management
Stars: ✭ 40 (+122.22%)
Mutual labels:  bazel
grab-bazel-common
Common rules and macros for Grab's Android projects built with Bazel.
Stars: ✭ 20 (+11.11%)
Mutual labels:  bazel
gobazel
gobazel is a tool to help golang bazel developers to map bazel's folder structure to golang's standard folder structure, through FUSE (thus only works for Linux and MacOS users).
Stars: ✭ 28 (+55.56%)
Mutual labels:  bazel
ios-bazel-users
Resources for using bazel for iOS development
Stars: ✭ 80 (+344.44%)
Mutual labels:  bazel
pazel
pazel - generate Bazel BUILD files for Python
Stars: ✭ 38 (+111.11%)
Mutual labels:  bazel
real-world-bazel
Bazel build files collected from real-world GitHub projects
Stars: ✭ 24 (+33.33%)
Mutual labels:  bazel
rules hugo
Bazel build rules for hugo static website generator
Stars: ✭ 41 (+127.78%)
Mutual labels:  bazel
bzl
Bzl - Integrated CLI + UI + VSCode Extension for Bazel
Stars: ✭ 43 (+138.89%)
Mutual labels:  bazel
airin
A framework for automated migration of your projects to Bazel build system.
Stars: ✭ 21 (+16.67%)
Mutual labels:  bazel
ng-qt
Build extremely powerful and efficient native cross-platform desktop applications using Angular and NodeGUI
Stars: ✭ 14 (-22.22%)
Mutual labels:  bazel
tools jvm autodeps
Automatic Dependency Management Tools for JVM Languages
Stars: ✭ 48 (+166.67%)
Mutual labels:  bazel
zorechka-bot
Github bot for keeping your Bazel dependencies up-to-date and clean
Stars: ✭ 25 (+38.89%)
Mutual labels:  bazel
bazel-packages
[WIP] Collection of Bazel packages
Stars: ✭ 14 (-22.22%)
Mutual labels:  bazel
rules node
Node rules for Bazel (unsupported)
Stars: ✭ 51 (+183.33%)
Mutual labels:  bazel
create-bazel-workspace
Generate a new polyglot Bazel workspace with minimal configuration
Stars: ✭ 16 (-11.11%)
Mutual labels:  bazel

Shell rules for Bazel

This project extends Bazel with a toolchain for common shell commands.

Setup

See the WORKSPACE setup section of the current release.

Or use the following template in your WORKSPACE file to install a development version of rules_sh:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "rules_sh",
    # Replace git revision and sha256.
    sha256 = "0000000000000000000000000000000000000000000000000000000000000000",
    strip_prefix = "rules_sh-0000000000000000000000000000000000000000",
    urls = ["https://github.com/tweag/rules_sh/archive/0000000000000000000000000000000000000000.tar.gz"],
)
load("@rules_sh//sh:repositories.bzl", "rules_sh_dependencies")
rules_sh_dependencies()

Usage

Configure the toolchain

Add the following to your WORKSPACE file to configure a local POSIX toolchain.

load("@rules_sh//sh:posix.bzl", "sh_posix_configure")
sh_posix_configure()

Bazel will query PATH for common Unix shell commands. You can override the path to individual commands with environment variables of the form POSIX_<COMMAND_NAME>. E.g. POSIX_MAKE=/usr/bin/gmake.

Note, this introduces an inhermeticity to the build as the contents of PATH may be specific to your machine's setup.

Refer to rules_nixpkgs's nixpkgs_posix_configure for a hermetic alternative.

Use Unix tools in genrules

The POSIX toolchain exposes custom make variables of the form POSIX_<COMMAND_NAME> for discovered commands. Use these as follows:

genrule(
    name = "example",
    srcs = [":some-input-file"],
    outs = ["some-output-file"],
    cmd = "$(POSIX_GREP) some-pattern $(execpath :some-input-file.bzl) > $(OUTS)",
    toolchains = ["@rules_sh//sh/posix:make_variables"],
)

See posix.commands defined in @rules_sh//sh/posix.bzl for the list of known POSIX commands.

Use Unix tools in custom rules

The POSIX toolchain provides two attributes:

  • commands: A dict mapping names of commands to their paths.
  • paths: A deduplicated list of bindir paths suitable for generating $PATH.
def _my_rule_impl(ctx):
    posix_info = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"]
    ctx.actions.run(
        executable = posix_info.commands["grep"],
        ...
    )
    ctx.actions.run_shell(
        command = "grep ...",
        env = {"PATH": ":".join(posix_info.paths)},
        ...
    )

my_rule = rule(
    _my_rule_impl,
    toolchains = ["@rules_sh//sh/posix:toolchain_type"],
    ...
)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].