-
-
Notifications
You must be signed in to change notification settings - Fork 12.7k
/
Copy pathgo.rb
128 lines (109 loc) · 4.51 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
121
122
123
124
125
126
127
128
class Go < Formula
desc "Open source programming language to build simple/reliable/efficient software"
homepage "https://go.dev/"
url "https://go.dev/dl/go1.24.2.src.tar.gz"
mirror "https://fossies.org/linux/misc/go1.24.2.src.tar.gz"
sha256 "9dc77ffadc16d837a1bf32d99c624cb4df0647cee7b119edd9e7b1bcc05f2e00"
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
bottle do
sha256 arm64_sequoia: "af3b7e49c04ba9c7c5da1f18ad09ca9282388507ac0455d6a7d67ad3a634b403"
sha256 arm64_sonoma: "af3b7e49c04ba9c7c5da1f18ad09ca9282388507ac0455d6a7d67ad3a634b403"
sha256 arm64_ventura: "af3b7e49c04ba9c7c5da1f18ad09ca9282388507ac0455d6a7d67ad3a634b403"
sha256 sonoma: "f34bd91a7f803e9bd4a15c66fec9e08a7c5d47cde9afd9ca1f10d35ac31a0cef"
sha256 ventura: "f34bd91a7f803e9bd4a15c66fec9e08a7c5d47cde9afd9ca1f10d35ac31a0cef"
sha256 cellar: :any_skip_relocation, arm64_linux: "0eae1c913860d8682a7e7594cf53f28862de3e64b13b5b66b443c518560f0668"
sha256 x86_64_linux: "33ab89c5b736bc433a2118050bfcc09a238f72f821ea8e5add409928579806a2"
end
# Don't update this unless this version cannot bootstrap the new version.
resource "gobootstrap" do
checksums = {
"darwin-arm64" => "416c35218edb9d20990b5d8fc87be655d8b39926f15524ea35c66ee70273050d",
"darwin-amd64" => "e7bbe07e96f0bd3df04225090fe1e7852ed33af37c43a23e16edbbb3b90a5b7c",
"linux-arm64" => "fd017e647ec28525e86ae8203236e0653242722a7436929b1f775744e26278e7",
"linux-amd64" => "4fa4f869b0f7fc6bb1eb2660e74657fbf04cdd290b5aef905585c86051b34d43",
}
version "1.22.12"
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
libexec.install Dir["*"]
(buildpath/"gobootstrap").install resource("gobootstrap")
ENV["GOROOT_BOOTSTRAP"] = buildpath/"gobootstrap"
cd libexec/"src" do
# Set portable defaults for CC/CXX to be used by cgo
with_env(CC: "cc", CXX: "c++") { system "./make.bash" }
end
bin.install_symlink Dir[libexec/"bin/go*"]
# 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")
# Remove testdata with binaries for non-native architectures.
rm_r(libexec/"src/debug/dwarf/testdata")
end
test do
(testpath/"hello.go").write <<~GO
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
GO
# 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 <<~GO
package main
/*
#include <stdlib.h>
#include <stdio.h>
void hello() { printf("%s\\n", "Hello from cgo!"); fflush(stdout); }
*/
import "C"
func main() {
C.hello()
}
GO
# 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