mirror of
https://github.com/openlibrecommunity/olcrtc.git
synced 2026-05-26 07:08:11 +00:00
chore: add mage build automation
This commit is contained in:
1
go.mod
1
go.mod
@@ -5,6 +5,7 @@ go 1.25.0
|
||||
require (
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/magefile/mage v1.17.1
|
||||
github.com/pion/webrtc/v4 v4.2.11
|
||||
golang.org/x/crypto v0.49.0
|
||||
)
|
||||
|
||||
2
go.sum
2
go.sum
@@ -4,6 +4,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/magefile/mage v1.17.1 h1:F1d2lnLSlbQDM0Plq6Ac4NtaHxkxTK8t5nrMY9SkoNA=
|
||||
github.com/magefile/mage v1.17.1/go.mod h1:Yj51kqllmsgFpvvSzgrZPK9WtluG3kUhFaBUVLo4feA=
|
||||
github.com/pion/datachannel v1.6.0 h1:XecBlj+cvsxhAMZWFfFcPyUaDZtd7IJvrXqlXD/53i0=
|
||||
github.com/pion/datachannel v1.6.0/go.mod h1:ur+wzYF8mWdC+Mkis5Thosk+u/VOL287apDNEbFpsIk=
|
||||
github.com/pion/dtls/v3 v3.1.2 h1:gqEdOUXLtCGW+afsBLO0LtDD8GnuBBjEy6HRtyofZTc=
|
||||
|
||||
190
magefile.go
Normal file
190
magefile.go
Normal file
@@ -0,0 +1,190 @@
|
||||
//go:build mage
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/magefile/mage/mg"
|
||||
"github.com/magefile/mage/sh"
|
||||
)
|
||||
|
||||
const (
|
||||
module = "github.com/openlibrecommunity/olcrtc"
|
||||
buildDir = "build"
|
||||
ldflags = "-s -w"
|
||||
goVersion = "1.25"
|
||||
)
|
||||
|
||||
var (
|
||||
goexe = mg.GoCmd()
|
||||
goos = envOr("GOOS", runtime.GOOS)
|
||||
goarch = envOr("GOARCH", runtime.GOARCH)
|
||||
)
|
||||
|
||||
// Build builds both olcrtc CLI and UI binaries.
|
||||
func Build() error {
|
||||
mg.Deps(BuildCLI, BuildUI)
|
||||
return nil
|
||||
}
|
||||
|
||||
// BuildCLI builds the olcrtc server/client binary.
|
||||
func BuildCLI() error {
|
||||
mg.Deps(Deps)
|
||||
return buildBinary("olcrtc", "./cmd/olcrtc", goos, goarch)
|
||||
}
|
||||
|
||||
// BuildUI builds the Fyne desktop UI binary.
|
||||
func BuildUI() error {
|
||||
return buildUIBinary(goos, goarch)
|
||||
}
|
||||
|
||||
// Cross builds olcrtc for all supported platforms.
|
||||
func Cross() error {
|
||||
mg.Deps(Deps)
|
||||
|
||||
targets := []struct{ os, arch string }{
|
||||
{"linux", "amd64"},
|
||||
{"linux", "arm64"},
|
||||
{"windows", "amd64"},
|
||||
{"darwin", "amd64"},
|
||||
{"darwin", "arm64"},
|
||||
}
|
||||
|
||||
for _, t := range targets {
|
||||
if err := buildBinary("olcrtc", "./cmd/olcrtc", t.os, t.arch); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Podman builds the image using podman.
|
||||
func Podman() error {
|
||||
tag := envOr("DOCKER_TAG", "olcrtc:latest")
|
||||
return sh.RunV("podman", "build", "-t", tag, ".")
|
||||
}
|
||||
|
||||
// Docker builds the image using docker.
|
||||
func Docker() error {
|
||||
tag := envOr("DOCKER_TAG", "olcrtc:latest")
|
||||
return sh.RunV("docker", "build", "-t", tag, ".")
|
||||
}
|
||||
|
||||
// Lint runs golangci-lint.
|
||||
func Lint() error {
|
||||
if err := ensureTool("golangci-lint"); err != nil {
|
||||
return fmt.Errorf("golangci-lint not found, install it:\n go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest")
|
||||
}
|
||||
return sh.RunV("golangci-lint", "run", "./...")
|
||||
}
|
||||
|
||||
// Test runs all tests.
|
||||
func Test() error {
|
||||
return sh.RunV(goexe, "test", "-race", "-count=1", "./...")
|
||||
}
|
||||
|
||||
// Deps downloads and tidies Go module dependencies.
|
||||
func Deps() error {
|
||||
if err := sh.RunV(goexe, "mod", "download"); err != nil {
|
||||
return err
|
||||
}
|
||||
return sh.RunV(goexe, "mod", "tidy")
|
||||
}
|
||||
|
||||
// Clean removes build artifacts.
|
||||
func Clean() error {
|
||||
return os.RemoveAll(buildDir)
|
||||
}
|
||||
|
||||
// Mobile builds the Android AAR via gomobile.
|
||||
func Mobile() error {
|
||||
if err := ensureTool("gomobile"); err != nil {
|
||||
return fmt.Errorf("gomobile not found: run 'go install golang.org/x/mobile/cmd/gomobile@latest && gomobile init'")
|
||||
}
|
||||
return sh.RunV("gomobile", "bind",
|
||||
"-target=android",
|
||||
"-o", filepath.Join(buildDir, "olcrtc.aar"),
|
||||
"./mobile",
|
||||
)
|
||||
}
|
||||
|
||||
func buildBinary(name, pkg, os_, arch string) error {
|
||||
if err := ensureBuildDir(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
out := filepath.Join(buildDir, binaryName(name, os_))
|
||||
fmt.Printf("building %s (%s/%s) -> %s\n", name, os_, arch, out)
|
||||
|
||||
env := map[string]string{
|
||||
"GOOS": os_,
|
||||
"GOARCH": arch,
|
||||
"CGO_ENABLED": "0",
|
||||
}
|
||||
|
||||
return sh.RunWithV(env, goexe, "build",
|
||||
"-trimpath",
|
||||
"-ldflags", ldflags,
|
||||
"-o", out,
|
||||
pkg,
|
||||
)
|
||||
}
|
||||
|
||||
func buildUIBinary(os_, arch string) error {
|
||||
if err := ensureBuildDir(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
absOut, err := filepath.Abs(filepath.Join(buildDir, binaryName("olcrtc-ui", os_)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("building olcrtc-ui (%s/%s)\n", os_, arch)
|
||||
|
||||
cmd := exec.Command(goexe, "build",
|
||||
"-trimpath",
|
||||
"-ldflags", ldflags,
|
||||
"-o", absOut,
|
||||
".",
|
||||
)
|
||||
cmd.Dir = "ui"
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Env = append(os.Environ(),
|
||||
"GOOS="+os_,
|
||||
"GOARCH="+arch,
|
||||
)
|
||||
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func binaryName(name, os_ string) string {
|
||||
if os_ == "windows" {
|
||||
return name + ".exe"
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func ensureBuildDir() error {
|
||||
return os.MkdirAll(buildDir, 0o755)
|
||||
}
|
||||
|
||||
func ensureTool(name string) error {
|
||||
_, err := exec.LookPath(name)
|
||||
return err
|
||||
}
|
||||
|
||||
func envOr(key, fallback string) string {
|
||||
if v := strings.TrimSpace(os.Getenv(key)); v != "" {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
Reference in New Issue
Block a user