Home > User Guide > Advanced Topics
This page covers cross-compilation, dry-run mode, CI integration, and debugging.
Produce a standalone binary instead of running targets:
stave --compile=./build/stave-linux --goos=linux --goarch=amd64The compiled binary can run on machines without Go installed.
| Flag | Description |
|---|---|
--compile=PATH |
Output path for compiled binary |
--goos=OS |
Target operating system |
--goarch=ARCH |
Target architecture |
--ldflags=FLAGS |
Linker flags (e.g., -s -w for smaller binary) |
Build for multiple platforms:
func Release() error {
platforms := []struct{ os, arch string }{
{"linux", "amd64"},
{"darwin", "amd64"},
{"darwin", "arm64"},
{"windows", "amd64"},
}
for _, p := range platforms {
output := fmt.Sprintf("dist/app-%s-%s", p.os, p.arch)
if p.os == "windows" {
output += ".exe"
}
err := sh.RunWith(
map[string]string{"GOOS": p.os, "GOARCH": p.arch, "CGO_ENABLED": "0"},
"go", "build", "-o", output, ".",
)
if err != nil {
return err
}
}
return nil
}Preview commands without executing them:
stave --dryrun build- All
sh.Run*functions printDRYRUN: command args...instead of executing sh.Rmandsh.Copyalso print instead of acting- The stavefile itself still runs (only shell commands are skipped)
Delegate environment variable management to direnv directly from Stave:
stave --direnv [direnv-subcommand] [args...]If you are using direnv to manage your environment variables, you can run direnv commands through Stave:
stave --direnv allow
stave --direnv reloadThis is particularly useful in CI environments where you might want to leverage direnv's environment-loading capabilities without having to install the direnv binary separately, as Stave includes direnv as a library.
- Stave delegates the execution to the embedded
direnvlibrary. - Environment variables set via
direnvare made available to the subsequent execution within that process (though typically you use--direnvas its own command). - The
--direnvflag acts as a "pseudo-flag" that triggers a dedicated execution mode, similar to--hooksor--config.
name: Build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
- name: Install Stave
run: go install github.com/yaklabco/stave@latest
- name: Build
run: stave build
- name: Test
run: stave testCache the Stave binary cache to speed up CI:
- uses: actions/cache@v4
with:
path: ~/.cache/stave
key: stave-${{ runner.os }}-${{ hashFiles('stavefile.go') }}Limit parallelism in resource-constrained environments:
- name: Build
env:
STAVE_NUM_PROCESSORS: 2
run: stave buildGit hooks are typically not needed in CI (tests run explicitly). Disable them:
- name: Build
env:
STAVE_HOOKS: "0"
run: |
stave build
stave testbuild:
image: golang:1.21
script:
- go install github.com/yaklabco/stave@latest
- stave build
- stave test
cache:
paths:
- ~/.cache/stavePrint target execution and command details:
stave -v buildOr set the environment variable:
STAVEFILE_VERBOSE=true stave buildPrint internal Stave operations (parsing, compilation, caching):
stave -d buildOr:
STAVEFILE_DEBUG=true stave buildRetain the generated mainfile for inspection:
stave --keep buildThe generated file is stave_output_file_<hash>_<pid>.go in the stavefile directory.
Bypass the cache and recompile:
stave -f buildThis section will be expanded as issues are reported.
Run hooks manually to debug issues:
stave --hooks run pre-commitEnable debug output in hook scripts:
STAVE_HOOKS=debug git commit -m "test"Set STAVE_HOOKS=0 to disable all hooks:
STAVE_HOOKS=0 git commit -m "WIP"This is preferable to git commit --no-verify as it still allows the hook script to run (and log that hooks are disabled).
If hooks fail in GUI clients (SourceTree, VS Code, etc.) due to missing stave on PATH, create a user init script:
mkdir -p ~/.config/stave/hooks
cat > ~/.config/stave/hooks/init.sh << 'EOF'
export PATH="$PATH:/usr/local/go/bin:$HOME/go/bin"
EOFThis script is sourced by all hook scripts before running Stave.
- Configuration - Config files and environment variables
- Git Hooks - Complete hooks documentation
- CLI Reference - All command-line flags
- Shell Commands - Command execution details
- Home