|
| 1 | +class GoAT125 < Formula |
| 2 | + desc "Open source programming language to build simple/reliable/efficient software" |
| 3 | + homepage "https://go.dev/" |
| 4 | + url "https://go.dev/dl/go1.25.7.src.tar.gz" |
| 5 | + mirror "https://fossies.org/linux/misc/go1.25.7.src.tar.gz" |
| 6 | + sha256 "178f2832820274b43e177d32f06a3ebb0129e427dd20a5e4c88df2c1763cf10a" |
| 7 | + license "BSD-3-Clause" |
| 8 | + revision 1 |
| 9 | + compatibility_version 1 |
| 10 | + |
| 11 | + livecheck do |
| 12 | + url "https://go.dev/dl/?mode=json" |
| 13 | + regex(/^go[._-]?v?(1\.25(?:\.\d+)*)[._-]src\.t.+$/i) |
| 14 | + strategy :json do |json, regex| |
| 15 | + json.map do |release| |
| 16 | + next if release["stable"] != true |
| 17 | + next if release["files"].none? { |file| file["filename"].match?(regex) } |
| 18 | + |
| 19 | + release["version"][/(\d+(?:\.\d+)+)/, 1] |
| 20 | + end |
| 21 | + end |
| 22 | + end |
| 23 | + |
| 24 | + bottle do |
| 25 | + sha256 cellar: :any_skip_relocation, arm64_tahoe: "1b7dbdf302ac420aa8f9f21b80753b42670160344ae8fcd222ed79f5dc4daa55" |
| 26 | + sha256 cellar: :any_skip_relocation, arm64_sequoia: "1b7dbdf302ac420aa8f9f21b80753b42670160344ae8fcd222ed79f5dc4daa55" |
| 27 | + sha256 cellar: :any_skip_relocation, arm64_sonoma: "1b7dbdf302ac420aa8f9f21b80753b42670160344ae8fcd222ed79f5dc4daa55" |
| 28 | + sha256 cellar: :any_skip_relocation, sonoma: "22393319dcfebad92b53a89259e924f66c7fec7bf56d73f8dd5be88c0e75cb4b" |
| 29 | + sha256 cellar: :any_skip_relocation, arm64_linux: "df5032811d797828f11621cdf085d5ab39fafa1127299c95d321773920257de8" |
| 30 | + sha256 cellar: :any_skip_relocation, x86_64_linux: "88ee33ff7f5018e16c12a93d4bad41ecfb5ed6b7112cd7a0206b6d69684552e0" |
| 31 | + end |
| 32 | + |
| 33 | + keg_only :versioned_formula |
| 34 | + |
| 35 | + depends_on "go" => :build |
| 36 | + |
| 37 | + # patch to fix pkg-config flag sanitization |
| 38 | + # Backport issue https://golang.org/issue/77438, should be included in 1.25.8+. |
| 39 | + patch do |
| 40 | + url "https://github.com/golang/go/commit/28fbdf7acb4146b5bc3d88128e407d1344691839.patch?full_index=1" |
| 41 | + sha256 "2e05f7e16f2320685547a7ebb240163a8b7f1c7bf9d2f6dc4872ff8b27707a35" |
| 42 | + end |
| 43 | + |
| 44 | + def install |
| 45 | + libexec.install Dir["*"] |
| 46 | + |
| 47 | + cd libexec/"src" do |
| 48 | + # Set portable defaults for CC/CXX to be used by cgo |
| 49 | + with_env(CC: "cc", CXX: "c++") { system "./make.bash" } |
| 50 | + end |
| 51 | + |
| 52 | + bin.install_symlink Dir[libexec/"bin/go*"] |
| 53 | + |
| 54 | + # Remove useless files. |
| 55 | + # Breaks patchelf because folder contains weird debug/test files |
| 56 | + rm_r(libexec/"src/debug/elf/testdata") |
| 57 | + # Binaries built for an incompatible architecture |
| 58 | + rm_r(libexec/"src/runtime/pprof/testdata") |
| 59 | + # Remove testdata with binaries for non-native architectures. |
| 60 | + rm_r(libexec/"src/debug/dwarf/testdata") |
| 61 | + end |
| 62 | + |
| 63 | + test do |
| 64 | + (testpath/"hello.go").write <<~GO |
| 65 | + package main |
| 66 | +
|
| 67 | + import "fmt" |
| 68 | +
|
| 69 | + func main() { |
| 70 | + fmt.Println("Hello World") |
| 71 | + } |
| 72 | + GO |
| 73 | + |
| 74 | + # Run go fmt check for no errors then run the program. |
| 75 | + # This is a a bare minimum of go working as it uses fmt, build, and run. |
| 76 | + system bin/"go", "fmt", "hello.go" |
| 77 | + assert_equal "Hello World\n", shell_output("#{bin}/go run hello.go") |
| 78 | + |
| 79 | + with_env(GOOS: "freebsd", GOARCH: "amd64") do |
| 80 | + system bin/"go", "build", "hello.go" |
| 81 | + end |
| 82 | + |
| 83 | + (testpath/"hello_cgo.go").write <<~GO |
| 84 | + package main |
| 85 | +
|
| 86 | + /* |
| 87 | + #include <stdlib.h> |
| 88 | + #include <stdio.h> |
| 89 | + void hello() { printf("%s\\n", "Hello from cgo!"); fflush(stdout); } |
| 90 | + */ |
| 91 | + import "C" |
| 92 | +
|
| 93 | + func main() { |
| 94 | + C.hello() |
| 95 | + } |
| 96 | + GO |
| 97 | + |
| 98 | + # Try running a sample using cgo without CC or CXX set to ensure that the |
| 99 | + # toolchain's default choice of compilers work |
| 100 | + with_env(CC: nil, CXX: nil, CGO_ENABLED: "1") do |
| 101 | + assert_equal "Hello from cgo!\n", shell_output("#{bin}/go run hello_cgo.go") |
| 102 | + end |
| 103 | + end |
| 104 | +end |
0 commit comments