|
| 1 | +class GoAT123 < 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.23.6.src.tar.gz" |
| 5 | + mirror "https://fossies.org/linux/misc/go1.23.6.src.tar.gz" |
| 6 | + sha256 "039c5b04e65279daceee8a6f71e70bd05cf5b801782b6f77c6e19e2ed0511222" |
| 7 | + license "BSD-3-Clause" |
| 8 | + |
| 9 | + livecheck do |
| 10 | + url "https://go.dev/dl/?mode=json" |
| 11 | + regex(/^go[._-]?v?(1\.23(?:\.\d+)*)[._-]src\.t.+$/i) |
| 12 | + strategy :json do |json, regex| |
| 13 | + json.map do |release| |
| 14 | + next if release["stable"] != true |
| 15 | + next if release["files"].none? { |file| file["filename"].match?(regex) } |
| 16 | + |
| 17 | + release["version"][/(\d+(?:\.\d+)+)/, 1] |
| 18 | + end |
| 19 | + end |
| 20 | + end |
| 21 | + |
| 22 | + bottle do |
| 23 | + sha256 cellar: :any_skip_relocation, arm64_sequoia: "cf4db4579df6a906f27611a27613a8d6583292a50534470d101e276e5c4ee31b" |
| 24 | + sha256 cellar: :any_skip_relocation, arm64_sonoma: "cf4db4579df6a906f27611a27613a8d6583292a50534470d101e276e5c4ee31b" |
| 25 | + sha256 cellar: :any_skip_relocation, arm64_ventura: "cf4db4579df6a906f27611a27613a8d6583292a50534470d101e276e5c4ee31b" |
| 26 | + sha256 cellar: :any_skip_relocation, sonoma: "4654e00aa7967d9c8cf325253d1f82896f2a6ea40de389879cdfffa235e374af" |
| 27 | + sha256 cellar: :any_skip_relocation, ventura: "4654e00aa7967d9c8cf325253d1f82896f2a6ea40de389879cdfffa235e374af" |
| 28 | + sha256 cellar: :any_skip_relocation, x86_64_linux: "00ba9579754a0e0a4e6a6840dff51ad36c78cd8e4a3e820631083f09d32cc12b" |
| 29 | + end |
| 30 | + |
| 31 | + keg_only :versioned_formula |
| 32 | + |
| 33 | + depends_on "go" => :build |
| 34 | + |
| 35 | + def install |
| 36 | + cd "src" do |
| 37 | + ENV["GOROOT_FINAL"] = libexec |
| 38 | + # Set portable defaults for CC/CXX to be used by cgo |
| 39 | + with_env(CC: "cc", CXX: "c++") { system "./make.bash" } |
| 40 | + end |
| 41 | + |
| 42 | + libexec.install Dir["*"] |
| 43 | + bin.install_symlink Dir[libexec/"bin/go*"] |
| 44 | + |
| 45 | + system bin/"go", "install", "std", "cmd" |
| 46 | + |
| 47 | + # Remove useless files. |
| 48 | + # Breaks patchelf because folder contains weird debug/test files |
| 49 | + rm_r(libexec/"src/debug/elf/testdata") |
| 50 | + # Binaries built for an incompatible architecture |
| 51 | + rm_r(libexec/"src/runtime/pprof/testdata") |
| 52 | + end |
| 53 | + |
| 54 | + test do |
| 55 | + (testpath/"hello.go").write <<~GO |
| 56 | + package main |
| 57 | +
|
| 58 | + import "fmt" |
| 59 | +
|
| 60 | + func main() { |
| 61 | + fmt.Println("Hello World") |
| 62 | + } |
| 63 | + GO |
| 64 | + |
| 65 | + # Run go fmt check for no errors then run the program. |
| 66 | + # This is a a bare minimum of go working as it uses fmt, build, and run. |
| 67 | + system bin/"go", "fmt", "hello.go" |
| 68 | + assert_equal "Hello World\n", shell_output("#{bin}/go run hello.go") |
| 69 | + |
| 70 | + with_env(GOOS: "freebsd", GOARCH: "amd64") do |
| 71 | + system bin/"go", "build", "hello.go" |
| 72 | + end |
| 73 | + |
| 74 | + (testpath/"hello_cgo.go").write <<~GO |
| 75 | + package main |
| 76 | +
|
| 77 | + /* |
| 78 | + #include <stdlib.h> |
| 79 | + #include <stdio.h> |
| 80 | + void hello() { printf("%s\\n", "Hello from cgo!"); fflush(stdout); } |
| 81 | + */ |
| 82 | + import "C" |
| 83 | +
|
| 84 | + func main() { |
| 85 | + C.hello() |
| 86 | + } |
| 87 | + GO |
| 88 | + |
| 89 | + # Try running a sample using cgo without CC or CXX set to ensure that the |
| 90 | + # toolchain's default choice of compilers work |
| 91 | + with_env(CC: nil, CXX: nil) do |
| 92 | + assert_equal "Hello from cgo!\n", shell_output("#{bin}/go run hello_cgo.go") |
| 93 | + end |
| 94 | + end |
| 95 | +end |
0 commit comments