yabs

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

README

yabs

GitHub Workflow Status Apache-2.0 license Go Report Card Releases

[y]et [a]nother [b]uild [s]ystem

a build system, configurable in risor, a go-like scripting language

Installation

go install github.com/jakegut/yabs/cmd/yabs@latest

Usage

Make a build.yb file at the root of your project with the logic for your builds

register('hello', [], func(bc) {
    sh("echo 'hello world!'")
})
> yabs hello
2023/08/11 20:22:12 running "hello"
hello world!
Build Multiple Go Binaries
// use a go toolchain with a specific version, returns the name of the target
go_tc := go("go1.20.5")

// depend on files using `fs(name, list of globs)`, returns the name of the target
go_files := fs("go_files", ["go.mod", "go.sum", "**/*.go"])

// create a target `register(name, list of deps, task func)`
register("go_download", [go_tc, go_files], func(bc){
    go_bin := bc.GetDep(go_tc) + "/go"

    sh('{go_bin} mod download')
})

build_all := []

for _, goos := range ["windows", "darwin", "linux"] {
    for _, goarch := range ["amd64", "arm64"] {
        name := 'build_{goos}_{goarch}'
        build_all.append(name)
        register(name, [go_tc, go_files, "go_download"], func(bc) {
            goos := goos
            goarch := goarch
            
            go_bin := bc.GetDep(go_tc) + "/go"

            // Put any outputs in bc.Out to cache them with yabs
            sh('GOOS={goos} GOARCH={goarch} {go_bin} build -o {bc.Out} .')
        })
    }
}

register("build_all", build_all, func(bc) {
    for _, build := range build_all {
        // direct dependencies' outputs are available at `bc.GetDep(target)`
        bin_loc := bc.GetDep(build)
        print(build, bin_loc)
    }
})
> yabs build_all
2023/08/11 20:33:15 running "go_files"
2023/08/11 20:33:15 running "go1.20.5"
2023/08/11 20:33:15 downloading "go1.20.5" from https://go.dev/dl/go1.20.5.linux-amd64.tar.gz
2023/08/11 20:33:15 extracting tar.gz
2023/08/11 20:33:19 running "go_download"
2023/08/11 20:33:23 running "build_linux_arm64"
2023/08/11 20:33:26 running "build_linux_amd64"
2023/08/11 20:33:26 running "build_windows_arm64"
2023/08/11 20:33:27 running "build_darwin_amd64"
2023/08/11 20:33:27 running "build_darwin_arm64"
2023/08/11 20:33:27 running "build_windows_amd64"
2023/08/11 20:33:28 running "build_all"
build_windows_amd64 /abs/path/to/project/.yabs/out/yabs-out-650635068
build_windows_arm64 /abs/path/to/project/.yabs/out/yabs-out-3597857295
build_darwin_amd64 /abs/path/to/project/.yabs/out/yabs-out-3821563234
build_darwin_arm64 /abs/path/to/project/.yabs/out/yabs-out-2023236471
build_linux_amd64 /abs/path/to/project/.yabs/out/yabs-out-2379893467
build_linux_arm64 /abs/path/to/project/.yabs/out/yabs-out-1121798096

Design

Goals
  • Composable, write Go for targets, rules
  • Distribute yabs as a binary, not as a module
  • Build ~15 projects efficiently
  • Replace make
  • Run in CI and locally
Non-goals
  • Build millions+ LoC

Documentation

Index

Constants

View Source
const POOL_SIZE = 5

Variables

This section is empty.

Functions

func Fs

func Fs(y *Yabs, name string, globs []string) string

Types

type BuildCtx

type BuildCtx struct {
	// Run func(name string, args ...string) *RunConfig
	Out string
	Dep map[string]string
}

func NewBuildCtx

func NewBuildCtx(out string) BuildCtx

func (*BuildCtx) GetDep

func (bc *BuildCtx) GetDep(name string) string

func (BuildCtx) Run

func (BuildCtx) Run(name string, args ...string) *RunConfig

type BuildCtxFunc

type BuildCtxFunc func(BuildCtx)

type OutType

type OutType int
const (
	None OutType = iota
	File
	Dir
)

type RunConfig

type RunConfig struct {
	Cmd []string
	// contains filtered or unexported fields
}

func (*RunConfig) Exec

func (r *RunConfig) Exec() error

func (*RunConfig) StdoutToFile

func (r *RunConfig) StdoutToFile(file string) *RunConfig

func (*RunConfig) WithEnv

func (r *RunConfig) WithEnv(key, value string) *RunConfig

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

func NewScheduler

func NewScheduler() *Scheduler

func (*Scheduler) Schedule

func (s *Scheduler) Schedule(t *Task) chan *Task

func (*Scheduler) Start

func (s *Scheduler) Start()

type Task

type Task struct {
	Name     string
	Fn       BuildCtxFunc
	Dep      []string
	Out      string
	Checksum string
	Dirty    bool
	Time     int64
}

type TaskRecord

type TaskRecord struct {
	Name     string
	Checksum string
	Deps     []string
	Time     int64
}

type Yabs

type Yabs struct {
	// contains filtered or unexported fields
}

func New

func New() *Yabs

func (*Yabs) ExecWithDefault

func (y *Yabs) ExecWithDefault(def string) error

func (*Yabs) GetTaskNames

func (y *Yabs) GetTaskNames() []string

func (*Yabs) Prune

func (y *Yabs) Prune()

func (*Yabs) Register

func (y *Yabs) Register(name string, deps []string, fn BuildCtxFunc)

func (*Yabs) RestoreTasks

func (y *Yabs) RestoreTasks()

func (*Yabs) SaveTasks

func (y *Yabs) SaveTasks()

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL