-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.nu
60 lines (44 loc) · 1.44 KB
/
main.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env nu
const output_path = "bin"
def build-all [build_options: list<string>] {
print "building all binaries..."
let architectures = ["amd64", "arm64"]
let operating_systems = ["windows", "linux", "darwin"]
$architectures | each { |arch|
$operating_systems | each { |os|
$env.GOOS = $os
$env.GOARCH = $arch
mut binary_path = $"($output_path)/sbot-($os)-($arch)"
if $os == "windows" {
$binary_path = $"($binary_path).exe"
}
let options = ["build", "-o", $binary_path] ++ $build_options
run-external go ...$options
print $"built ($binary_path)"
}
}
}
def build-local [build_options: list<string>] {
print "building local binary..."
let binary_path = $"($output_path)/sbot"
let options = ["build", "-o", $binary_path] ++ $build_options
run-external go ...$options
print $"built ($binary_path)"
}
def get-ldflags [version: string] {
const go_import_path = "github.com/restechnica/semverbot"
let ldflags = [
$"-X ($go_import_path)/internal/ldflags.Version=($version)"
] | str join ' '
return $ldflags
}
def "main build" [--all, --version: string = "dev"] {
let ldflags = get-ldflags $version
let options: list<string> = ["-ldflags", $ldflags]
if $all {
build-all $options
} else {
build-local $options
}
}
def main [] {}