Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Quick example:
- single binary, no required system tools besides what goomba downloads
- build matrix support for platforms and architectures
- optional tui progress and parallel builds
- predictable output layout under ./dist
- predictable output layout under ./dist (or --out)

## Install

Expand Down Expand Up @@ -69,16 +69,21 @@ goomba build --platforms macos --arch x64,arm64
goomba build -- --buildmode=c-shared -o dist/libshared.so
```

```
goomba build --out ../dist
```

### flags

- --platforms: comma separated list of linux, macos, windows
- --arch: comma separated list of amd64, arm64, x64
- --no-parallel: run builds one by one
- --no-tui: disable tui progress output (intended for CI environments)
- --no-validation: skip validation step
- --strict: fail if any target fails and remove dist output
- --strict: fail if any target fails and remove output directory
- --verbose: enable verbose logging
- --java-home: override JAVA_HOME for JNI includes
- --out: output base directory (default: dist, supports ../ paths)
- --go-args: append go build args, repeatable
- --cgo-enabled: enable CGO support and handle special platform dependencies, also implies --go-args=CGO_ENABLED=1

Expand All @@ -94,6 +99,8 @@ Artifacts are placed in:
./dist/<platform>/<arch>/<binary>
```

Use --out to change the base directory. Relative paths are resolved from the current working directory and can include .. segments.

## phases

1. preparing golang runtime (if not installed)
Expand Down
1 change: 1 addition & 0 deletions internal/build/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package build

type Config struct {
WorkDir string
OutputBase string
Platforms []string
Archs []string
NoParallel bool
Expand Down
25 changes: 22 additions & 3 deletions internal/build/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func printSummary(cfg Config, total int, errs []string, duration time.Duration)

fmt.Fprintf(os.Stdout, "summary: %s, total=%d, succeeded=%d, failed=%d, elapsed=%s\n", status, total, succeeded, failed, duration.Round(time.Second))
if cfg.Strict && failed > 0 {
fmt.Fprintln(os.Stdout, "summary: dist removed due to strict mode")
fmt.Fprintf(os.Stdout, "summary: output removed due to strict mode (%s)\n", outputBaseLabel(cfg))
}
}

Expand All @@ -183,7 +183,7 @@ func handleBuildErrors(cfg Config, errs []string) error {
return nil
}

if err := os.RemoveAll(filepath.Join(cfg.WorkDir, "dist")); err != nil {
if err := os.RemoveAll(outputBaseDir(cfg)); err != nil {
return err
}
return errors.New(strings.Join(errs, "; "))
Expand Down Expand Up @@ -221,7 +221,7 @@ func runValidation(ctx context.Context, cfg Config, goTool deps.GoTool, phase *t
}

func buildTarget(ctx context.Context, cfg Config, goTool deps.GoTool, target Target, zigTool *deps.ZigTool, macSDK *deps.MacSDK, ui *tui.UI, label string) error {
outDir := filepath.Join(cfg.WorkDir, "dist", target.Label, target.GOARCH)
outDir := filepath.Join(outputBaseDir(cfg), target.Label, target.GOARCH)
if err := os.MkdirAll(outDir, 0o755); err != nil {
return err
}
Expand Down Expand Up @@ -284,6 +284,25 @@ func buildDisplayLabel(target Target) string {
return fmt.Sprintf("Compiling os:%s arch:%s", target.Label, target.GOARCH)
}

func outputBaseDir(cfg Config) string {
base := strings.TrimSpace(cfg.OutputBase)
if base == "" {
base = "dist"
}
if filepath.IsAbs(base) {
return filepath.Clean(base)
}
return filepath.Clean(filepath.Join(cfg.WorkDir, base))
}

func outputBaseLabel(cfg Config) string {
base := strings.TrimSpace(cfg.OutputBase)
if base == "" {
return "dist"
}
return base
}

func runCommandWithLogs(cmd *exec.Cmd, logFn func(string), verbose bool, envKeys []string) error {
if verbose && logFn != nil {
logFn("cmd: " + strings.Join(cmd.Args, " "))
Expand Down
5 changes: 4 additions & 1 deletion internal/cli/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func runBuild(args []string) int {
var strict bool
var verbose bool
var javaHome string
var outputBase string
var goArgs argsList
var cgoEnabled bool

Expand All @@ -46,9 +47,10 @@ func runBuild(args []string) int {
fs.BoolVar(&noParallel, "no-parallel", false, "disable parallel builds")
fs.BoolVar(&noTui, "no-tui", false, "disable tui progress")
fs.BoolVar(&noValidation, "no-validation", false, "skip validation step")
fs.BoolVar(&strict, "strict", false, "fail if any target fails and remove dist output")
fs.BoolVar(&strict, "strict", false, "fail if any target fails and remove output directory")
fs.BoolVar(&verbose, "verbose", false, "enable verbose logging")
fs.StringVar(&javaHome, "java-home", "", "override JAVA_HOME for JNI includes")
fs.StringVar(&outputBase, "out", "", "output base directory (default: dist)")
fs.Var(&goArgs, "go-args", "additional go build arguments, repeatable")
fs.BoolVar(&cgoEnabled, "cgo-enabled", false, "enable CGO for builds")

Expand All @@ -69,6 +71,7 @@ func runBuild(args []string) int {

cfg := build.Config{
WorkDir: workDir,
OutputBase: outputBase,
Platforms: splitList(platforms),
Archs: splitList(archs),
NoParallel: noParallel,
Expand Down
6 changes: 4 additions & 2 deletions internal/cli/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ func printUsage(w io.Writer) {
fmt.Fprintln(w, " --no-parallel run builds one by one")
fmt.Fprintln(w, " --no-tui disable tui progress")
fmt.Fprintln(w, " --no-validation skip validation step")
fmt.Fprintln(w, " --strict fail if any target fails and remove dist output")
fmt.Fprintln(w, " --strict fail if any target fails and remove output directory")
fmt.Fprintln(w, " --verbose enable verbose logging")
fmt.Fprintln(w, " --java-home override JAVA_HOME for JNI includes")
fmt.Fprintln(w, " --out output base directory (default: dist)")
fmt.Fprintln(w, " --go-args append args to go build, repeatable")
fmt.Fprintln(w, " --cgo-enabled enable CGO for builds")
fmt.Fprintln(w, " --version display version number")
Expand All @@ -45,9 +46,10 @@ func printBuildUsage(w io.Writer) {
fmt.Fprintln(w, " --no-parallel run builds one by one")
fmt.Fprintln(w, " --no-tui disable tui progress")
fmt.Fprintln(w, " --no-validation skip validation step")
fmt.Fprintln(w, " --strict fail if any target fails and remove dist output")
fmt.Fprintln(w, " --strict fail if any target fails and remove output directory")
fmt.Fprintln(w, " --verbose enable verbose logging")
fmt.Fprintln(w, " --java-home override JAVA_HOME for JNI includes")
fmt.Fprintln(w, " --out output base directory (default: dist)")
fmt.Fprintln(w, " --go-args append args to go build, repeatable")
fmt.Fprintln(w, " --cgo-enabled enable CGO for builds")
fmt.Fprintln(w, " --version display version number")
Expand Down
23 changes: 15 additions & 8 deletions internal/deps/zig_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,24 @@ func zigWrapperScript(zigPath, mode, goos, goarch string) string {
target := zigTarget(goos, goarch)

return fmt.Sprintf(`#!/usr/bin/env sh
# Filter out incompatible flags
args=""
# Filter out incompatible flags without mangling the arg list.
filtered=""
for arg in "$@"; do
if [ "$arg" = "-Wl,--compress-debug-sections=zlib" ]; then
continue
fi
# This builds a list of arguments properly handled by 'set'
set -- "$@" "$arg"
shift
if [ "$arg" = "-Wl,--compress-debug-sections=zlib" ]; then
continue
fi
filtered="${filtered}
$arg"
done

old_ifs=$IFS
IFS='
'
set -f
set -- $filtered
set +f
IFS=$old_ifs

exec "%s" %s -target %s "$@"
`, quoted, mode, target)
}
4 changes: 4 additions & 0 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ platforms="${GOOMBA_PLATFORMS:-linux,macos,windows}"
arch="${GOOMBA_ARCH:-x64,arm64}"
cgo_enabled="${GOOMBA_CGO_ENABLED:-false}"
go_args="${GOOMBA_GO_ARGS:-}"
java_home="${GOOMBA_JAVA_HOME:-}"

if [ -n "$source_dir" ]; then
cd "$source_dir"
Expand All @@ -18,5 +19,8 @@ fi
if [ -n "$go_args" ]; then
args+=(--go-args "$go_args")
fi
if [ -n "$java_home" ]; then
args+=(--java-home "$java_home")
fi

goomba "${args[@]}"
Loading