-
Notifications
You must be signed in to change notification settings - Fork 0
/
go.rb
120 lines (101 loc) · 3.92 KB
/
go.rb
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
class Go < Formula
desc "Open source programming language to build simple/reliable/efficient software"
homepage "https://go.dev/"
url "https://go.dev/dl/go1.23.0.src.tar.gz"
mirror "https://fossies.org/linux/misc/go1.23.0.src.tar.gz"
sha256 "42b7a8e80d805daa03022ed3fde4321d4c3bf2c990a144165d01eeecd6f699c6"
license "BSD-3-Clause"
head "https://go.googlesource.com/go.git", branch: "master"
livecheck do
url "https://go.dev/dl/?mode=json"
regex(/^go[._-]?v?(\d+(?:\.\d+)+)[._-]src\.t.+$/i)
strategy :json do |json, regex|
json.map do |release|
next if release["stable"] != true
next if release["files"].none? { |file| file["filename"].match?(regex) }
release["version"][/(\d+(?:\.\d+)+)/, 1]
end
end
end
# Don't update this unless this version cannot bootstrap the new version.
resource "gobootstrap" do
checksums = {
"darwin-arm64" => "6da3f76164b215053daf730a9b8f1d673dbbaa4c61031374a6744b75cb728641",
"darwin-amd64" => "754363489e2244e72cb49b4ec6ddfd6a2c60b0700f8c4876e11befb1913b11c5",
"linux-arm64" => "2096507509a98782850d1f0669786c09727053e9fe3c92b03c0d96f48700282b",
"linux-amd64" => "ff445e48af27f93f66bd949ae060d97991c83e11289009d311f25426258f9c44",
}
version "1.20.14"
on_arm do
on_macos do
url "https://storage.googleapis.com/golang/go#{version}.darwin-arm64.tar.gz"
sha256 checksums["darwin-arm64"]
end
on_linux do
url "https://storage.googleapis.com/golang/go#{version}.linux-arm64.tar.gz"
sha256 checksums["linux-arm64"]
end
end
on_intel do
on_macos do
url "https://storage.googleapis.com/golang/go#{version}.darwin-amd64.tar.gz"
sha256 checksums["darwin-amd64"]
end
on_linux do
url "https://storage.googleapis.com/golang/go#{version}.linux-amd64.tar.gz"
sha256 checksums["linux-amd64"]
end
end
end
def install
(buildpath/"gobootstrap").install resource("gobootstrap")
ENV["GOROOT_BOOTSTRAP"] = buildpath/"gobootstrap"
cd "src" do
ENV["GOROOT_FINAL"] = libexec
# Set portable defaults for CC/CXX to be used by cgo
with_env(CC: "cc", CXX: "c++") { system "./make.bash" }
end
rm_r("gobootstrap") # Bootstrap not required beyond compile.
libexec.install Dir["*"]
bin.install_symlink Dir[libexec/"bin/go*"]
system bin/"go", "install", "std", "cmd"
# Remove useless files.
# Breaks patchelf because folder contains weird debug/test files
rm_r(libexec/"src/debug/elf/testdata")
# Binaries built for an incompatible architecture
rm_r(libexec/"src/runtime/pprof/testdata")
end
test do
(testpath/"hello.go").write <<~EOS
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
EOS
# Run go fmt check for no errors then run the program.
# This is a a bare minimum of go working as it uses fmt, build, and run.
system bin/"go", "fmt", "hello.go"
assert_equal "Hello World\n", shell_output("#{bin}/go run hello.go")
with_env(GOOS: "freebsd", GOARCH: "amd64") do
system bin/"go", "build", "hello.go"
end
(testpath/"hello_cgo.go").write <<~EOS
package main
/*
#include <stdlib.h>
#include <stdio.h>
void hello() { printf("%s\\n", "Hello from cgo!"); fflush(stdout); }
*/
import "C"
func main() {
C.hello()
}
EOS
# Try running a sample using cgo without CC or CXX set to ensure that the
# toolchain's default choice of compilers work
with_env(CC: nil, CXX: nil) do
assert_equal "Hello from cgo!\n", shell_output("#{bin}/go run hello_cgo.go")
end
end
end