Exec
The pluginexec plugin provides two execution drivers — exec and bash —
for running shell commands inside sandboxed target builds. It wires
up dependency injection, sets up environment variables, resolves the tools a
target needs on its PATH, and supports interactive shell debugging with PTY
allocation. Whenever a target runs a command to produce its outputs, one of
these drivers is doing the work.
Driver
A driver is the component that knows how to execute a target's action and
turn its inputs into outputs. This plugin registers the drivers named exec
and bash.
Enabling it
Built-in. Register in .hephconfig under plugins with builtin: exec or
builtin: bash. Options:
| Option | Meaning |
|---|---|
path | Host directories to put on a target's PATH. Empty by default — see The PATH a target sees. |
coreutils | Builtin tools on every target's PATH. true by default; false opts out. |
runner | Workspace-wide default runner for every target using this driver. |
Configuration
plugins:
- builtin: exec
options:
path: # optional; host directories, none by default
- /usr/local/bin
- /usr/bin
- /bin
coreutils: true # optional; the default
runner: "//tools/devenv:runner" # optional; see Runners
- builtin: bash
options:
path:
- /usr/local/bin
- /usr/bin
- /bin
runner: "//tools/devenv:runner" # optional; see Runners
Usage
target(
name = "hello",
driver = "bash",
run = "echo hello world > $OUT",
out = "greeting.txt",
env = {"MY_VAR": "value"},
pass_env = ["HOME", "USER"],
deps = {"src": "//src:files"},
tools = "//toolchain:gcc",
cache = {"enabled": True, "remote": True, "history": 5},
)
Notes
There are two driver variants:
| Driver | Behavior |
|---|---|
exec | Direct command execution. |
bash | Bash shell with job control, run with -o pipefail so a failing stage in a pipeline fails the target. |
The bash driver supports an interactive --shell mode with PTY
allocation, which is useful for debugging a target's sandbox.
The following target config keys are available:
| Key | Meaning |
|---|---|
run | List of commands to execute. Accepts deferred values. |
deps | Hashed build-time dependencies. |
hash_deps | Hash-only dependencies. |
runtime_deps | Runtime-only dependencies. |
tools | Executables placed on PATH. See Tool files. |
out | Output groups and paths. |
support_files | Non-output artifacts. |
env | Literal environment variables. |
pass_env | Host vars passed at parse time and hashed into the cache key. Accepts ["*"] to pass all. |
runtime_pass_env | Host vars passed at run time only, not hashed. Accepts ["*"] to pass all. |
runtime_env | Runtime literal environment variables. |
cache | True/False toggles local + remote together; dict: {enabled, remote, history}. |
codegen | Write generated outputs into the source tree (copy, in_place or in_place_on_success). |
failure_out | Files to keep when the run fails, same shape as out. Not hashed. See Failed targets. |
runner | Exec runner this command runs under — a target address producing a runner.json, or "local" to opt out of a workspace-wide default. See Runners. |
These environment variables are available inside the sandbox:
| Variable | Meaning |
|---|---|
SRC / SRC_<group> | Dependency paths. |
LIST_SRC / LIST_SRC_<group> | Dependency list files. |
TOOL / TOOL_<group> | Tool paths. |
TOOL_ROOT / TOOL_<group>_ROOT | Each tool's package directory, as staged. See Tool files. |
HEPH_TOOLS_DIR | Directory every tool of the target is staged under. See Launchers that find their own files. |
OUT / OUT_<group> | Output paths. |
WORKSPACE_ROOT | Root of the workspace. |
PATH | Executables search path. |
The PATH a target sees
A target's PATH holds its tools, any PATH it declares through
env, and heph's builtin utilities. The host's directories are not on it.
A command that relies on an undeclared host binary fails with command not found instead of passing on whichever machine happens to have it.
target(
name = "pack",
driver = "bash",
tools = "//toolchain:tar", # declared: on PATH
run = "tar -cf $OUT $SRC", # declared tool, or a builtin
deps = "//src:files",
out = "pack.tar",
)
If a command needs something else, declare it as a tools entry, call it by
absolute path, or list host directories in the driver's path option:
plugins:
- builtin: bash
options:
path: [/usr/local/bin, /usr/bin, /bin]
The bash driver itself finds bash on the PATH heph was launched with, so
you don't need path for the shell. That same shell, and only it, is also on the
target's PATH, so a recipe can call bash -c … or run a #!/usr/bin/env bash
script. A bash you declare as a tool wins over it. Under a runner,
the runner's environment supplies the PATH and path is not applied. The
interactive --shell session keeps the host's directories.
Builtin utilities
heph appends its builtin tools (cp, sed,
install, …) to every target's PATH. They fill gaps only: a tool the target
declares, or a binary the runner's environment ships, wins over the builtin of
the same name. Inside an OCI container they are not
available; the image's own utilities apply. Set coreutils: false on the driver
to use the host's utilities instead.
Tool files
A tool often ships more than its executable: headers, data, a standard
library. Declare them as the tool's support_files, and the consumer reaches
them through $TOOL_ROOT ($TOOL_<group>_ROOT for a named group) — the
tool's package directory, holding its outputs and support files at the paths
its BUILD file declares them:
target(
name = "sdk",
driver = "bash",
run = [
"mkdir -p sdk/bin sdk/include",
"echo hello > sdk/include/greeting.txt",
"printf '#!/bin/sh\\ncat \"$1/greeting.txt\"\\n' > sdk/bin/greet",
"chmod +x sdk/bin/greet",
],
out = "sdk/bin/greet",
support_files = "sdk/include/",
)
target(
name = "hello",
driver = "bash",
tools = "//sdk:sdk",
run = "greet $TOOL_ROOT/sdk/include > $OUT",
out = "hello.txt",
)
- One entry per tool package. When a group holds tools from several
packages, the variable lists each package directory once, sorted and
space-separated. A
grouptarget used as a tool counts each member's package. Treat it as a single path only when the group has one tool package. - It can be unset. A workspace source file, a host binary, or a tool whose outputs are not under its own package contributes no entry; a group with none of them gets no variable.
- Tools from a dependency's
transitivetools get a root like any other. - The path is absolute and machine-specific. If it can end up embedded in
an output, strip it with your compiler's prefix-map flag
(
-ffile-prefix-map,-trimpath) to keep outputs reproducible.
A target is refused when one of these names would be ambiguous:
- a group's root variable is another group's tool variable —
tools = {"": …, "root": …}puts both onTOOL_ROOT. Group names are uppercased and other characters become_, so different spellings can collide; env,runtime_env,pass_env,runtime_pass_env, or a dependency'stransitiveenv declares one of the target's root variables. heph sets it, so drop the entry or rename the tool group.
Launchers that find their own files
$HEPH_TOOLS_DIR is the directory every tool of a target is staged under. A
tool that is a launcher script reads it to find the files shipped beside it:
the launcher runs as part of the consumer, so it sees the consumer's variable.
Below it, a tool target's outputs and support_files sit at
<package>/<path>. The package is written without //, and the root package
adds nothing in front. That path stays the same whichever group the consumer
lists the tool in and whatever else the group holds. It also holds for tools
brought in through another tool's transitive tools. $TOOL_ROOT does not
give you that: it lists several directories when the group holds several tool
packages.
target(
name = "cli",
driver = "bash",
run = [
"mkdir -p lib",
"echo hello > lib/data.txt",
"printf '#!/bin/sh\\ncat \"$HEPH_TOOLS_DIR/greetcli/lib/data.txt\"\\n' > greet",
"chmod +x greet",
],
out = "greet",
support_files = "lib/",
)
target(
name = "hello",
driver = "bash",
tools = ["//greetcli:cli"],
run = "greet > $OUT", # the launcher finds lib/data.txt
out = "out.txt",
)
- It is set only for a target with tools. It is unset when none of the
tools staged a file (an empty
group). - Some tools have no package directory. A relocating
group(prefix,strip_prefix,rename), a workspace source file and a host binary are not under a package directory of their own. - The path is absolute and machine-specific. It is not hashed.
- heph owns the name on a target with tools. Setting
HEPH_TOOLS_DIRthroughenv,runtime_env,pass_env,runtime_pass_envor a dependency'stransitiveenv is refused, by the same rule as a root variable. A target without tools keeps its own value. - A
"*"passthrough never carries the host'sHEPH_TOOLS_DIR. This holds for bothpass_envandruntime_pass_env.
A wrong path fails inside the launcher with "No such file or directory",
naming the full path. Add ls -R "$HEPH_TOOLS_DIR" to the consumer's run to
see what was staged.
Dependencies
deps accepts either a list or a dict. The dict form names each group,
and that name becomes the suffix on the sandbox variables — deps = {"src": …}
surfaces as $SRC_SRC (and $LIST_SRC_SRC, a file listing every path in the
group, handy when a group expands to many files):
target(
name = "bundle",
driver = "bash",
deps = {
"code": glob("*.go"),
"assets": "//web:assets",
},
run = "cat $LIST_SRC_CODE; cp -r $SRC_ASSETS $OUT",
out = "bundle",
)
Group names are uppercased, and any character that isn't a letter, digit, or
underscore becomes _ — a group named my-group surfaces as $SRC_MY_GROUP,
not $SRC_MY-GROUP (which isn't a valid environment variable name). The same
rule applies to out and tools group names.
A plain list lands in the default group, available as $SRC and $LIST_SRC.
heph distinguishes three dependency kinds by how they affect the cache:
| Field | Hashed into the key? | Present in the sandbox? | Use for |
|---|---|---|---|
deps | yes | yes | Normal build inputs. |
hash_deps | yes | no | Inputs that must invalidate the cache but the command never reads. |
runtime_deps | no | yes (at run only) | Things needed to run an output, not to build it — changing them is a cache hit. |
Output groups
out mirrors deps: a string or list is the default group ($OUT), a dict
names groups ($OUT_<group>). Other targets select a specific group with the
|group suffix on the address:
target(
name = "compile",
driver = "bash",
run = "go build -o $OUT_BIN .; go doc . > $OUT_DOC",
out = {"bin": "app", "doc": "app.txt"},
)
target(
name = "package",
driver = "bash",
deps = ["//app:compile|bin"], # just the bin group
run = "cp $SRC $OUT",
out = "app.tar",
)
support_files declares files a target produces that are not outputs — kept
in the sandbox for the command's own use but not published to dependents.
Output and support-file paths are lexically normalized: ./ prefixes and empty
segments are stripped, .. resolves against the package path, and a path that
escapes the workspace root is an error.
Symlinks in outputs must stay inside their own output group; see symlinks in outputs.
Environment passthrough
pass_env and runtime_pass_env each accept a list of variable names to
inherit from the host environment. Both also accept the special value "*" to
pass through every host environment variable:
| Field | Hashed into the cache key? | When applied |
|---|---|---|
pass_env | yes | At parse time. The full environment snapshot is folded into the input hash. |
runtime_pass_env | no | At run time only. Variables are not hashed and do not affect the cache. |
Because pass_env = ["*"] hashes the entire host environment, any change to
any env var forces a rebuild. Only use it on targets where cache is disabled:
target(
name = "local-tool",
driver = "exec",
run = ["./build.sh"],
out = "tool",
pass_env = ["*"], # full env snapshot — only for uncached targets
cache = False,
)
Use runtime_pass_env = ["*"] when the command needs the full environment at
run time but you still want caching — the environment will not affect the cache
key:
target(
name = "run-tool",
driver = "exec",
run = ["./tool"],
out = "result",
runtime_pass_env = ["*"], # full env at run time, not hashed
)
Cache control
cache accepts a bare bool or a dict with up to three keys:
| Key | Type | Default | Meaning |
|---|---|---|---|
enabled | bool | true | Enable local caching for this target. |
remote | bool | true | Enable remote caching for this target. Set false when outputs embed host-local paths that cannot be safely shared across machines. |
history | int | 1 | Number of past revisions to retain in the local cache (minimum 1). |
A bare True sets both enabled and remote to true. A bare False disables both.
Use cache = {"remote": False} to keep local caching on but opt a specific
target out of remote push and pull — useful for targets whose outputs reference
paths that only exist on the machine that built them:
target(
name = "wrapper",
driver = "exec",
run = ["./gen-wrapper.sh"],
out = "wrapper.sh",
cache = {"remote": False},
)
The target still builds and caches locally; it is never uploaded to or pulled from a remote cache.
Timeouts
timeout bounds how long a target's run may take. Past it, heph stops the
run and fails the target.
target(
name = "integration",
driver = "bash",
run = "./run-integration-tests.sh",
timeout = "10m",
)
The value is a duration string ("90s", "10m", "1h30m") or a whole number
of seconds (600). It must be above zero; leave it out for no limit. Anything
else is rejected when the target is parsed.
When the limit is hit:
- The command's process group is sent
SIGINT, thenSIGKILLonce the command has exited or after a 2s grace. Processes it started are killed too. - If the run still hasn't returned 10s after being cancelled, heph stops waiting and the failure says the process may still be running.
- The target fails with
//p:integration timed out after 10m (itstimeout). The log tail is shown, the log andfailure_outmatches are kept in the failure slot, and nothing is cached, so the next build runs the target again. - If heph stopped waiting on the run, its sandbox is left on disk (the process
may still be writing to it) and the target's next run removes it. Otherwise
the sandbox is removed like any failed target's; pass
--keep-failed-sandboxesto keep it.
The clock covers only the command's process, from the moment it starts until it exits. Nothing heph does around it counts: waiting for resources, building dependencies, staging inputs into the sandbox, preparing the runner and collecting outputs are all off the clock. Under a runner, the process is the runner's wrapper, so whatever the wrapper does before starting your command is timed. A cache hit runs nothing, so it never times out.
timeout is not part of the cache key: adding, changing or removing it never
rebuilds a target. heph run holds an entrypoint to its timeout like any
build (a timed-out entrypoint exits 125); --shell is never timed.
timeout is set per target; there is no workspace-wide default. Only exec
and bash accept it today.
Runners
By default a command runs on this host. Point it at a runner target instead to run inside a described environment — a devenv shell, a container:
target(
name = "build",
driver = "bash",
run = "make",
out = "out/",
runner = "//tools/devenv:runner",
)
Set runner on the driver's own options (see Configuration)
to apply it to every exec/bash target in the workspace by default; a
target's own runner field overrides that default, and runner = "local"
opts a single target back onto the host. See Runners
for the full picture, including what environment a target actually sees.
Deferred values
run, and the values of env and runtime_env, can reference another
target's output instead of a literal — ${read://pkg:name} for its contents,
${src://pkg:name} for its sandbox path — and heph resolves the reference once
that target has run. See Deferred values.
target(
name = "deploy",
driver = "bash",
run = 'echo "deploying $VERSION"',
env = {"VERSION": "${read://:version}"},
)
Builtin coreutils
heph ships 64 common POSIX utilities in its own binary and puts them on every
target's PATH, so cp, install or sha256sum behave the same on Linux and
macOS instead of resolving to GNU or BSD variants. The full list is on the
builtin tools page.
It is on by default. Opt out per driver:
plugins:
- builtin: exec
options:
coreutils: false
- builtin: bash
options:
coreutils: false
The builtins fill gaps, they don't override anything: they come last on PATH,
after the target's tools, its declared dependencies and the
runner's environment. A tool you provide yourself
always wins. Targets under a container runner (such as oci) use the image's own
utilities.
Turning the toolbox on changes the cache key of every exec and bash target.
A new heph release that changes the toolbox does so again.
Inspect the set from the CLI:
heph tool coreutils list # the bundled utilities and the toolbox version
heph tool coreutils which cp # is `cp` builtin, and what the host provides instead
heph tool coreutils run cp -r a b # run one directly, outside a sandbox
Interactive debugging with --shell
When a target fails, drop into its sandbox with the exact inputs, tools, and environment it would run with:
heph run //app:server --shell
The bash driver allocates a PTY and starts an interactive shell inside
the prepared sandbox, so you can inspect $SRC_*, re-run the command by hand,
and see why it broke.
To shell into a dependency without building it on its own, name it with
--shell=ADDRESS and run the target that depends on it:
heph run --shell=//app:lib //app:server # build //app:server, enter //app:lib
heph run --shell=//app:lib # same as `heph run --shell //app:lib`
| Form | Which target gets the terminal |
|---|---|
--shell | The single target the run names. A group of exactly one member counts as that member; a group of two or more, or a multi-target selection, is refused. |
--shell=ADDRESS | ADDRESS, which may be any target the run resolves: a selected target, a member of a group, or a dependency of either. Every other target builds without a terminal. |
ADDRESS takes the same forms as the target argument, so :lib is relative
to the current package. An address that no target has, or that the run never
reaches, prints a warning and no shell is opened; the build still runs.
The target you enter always executes, never a cache hit, and its outputs are
not cached. --shell needs a terminal.