homebrew-core/Formula/go.rb

95 lines
3.2 KiB
Ruby

class Go < Formula
desc "Open source programming language to build simple/reliable/efficient software"
homepage "https://go.dev/"
url "https://go.dev/dl/go1.19.4.src.tar.gz"
mirror "https://fossies.org/linux/misc/go1.19.4.src.tar.gz"
sha256 "eda74db4ac494800a3e66ee784e495bfbb9b8e535df924a8b01b1a8028b7f368"
license "BSD-3-Clause"
head "https://go.googlesource.com/go.git", branch: "master"
livecheck do
url "https://go.dev/dl/"
regex(/href=.*?go[._-]?v?(\d+(?:\.\d+)+)[._-]src\.t/i)
end
bottle do
sha256 arm64_ventura: "1bcac5ddef2548a68b34360c06fdc9c7e1eddf74609c297d2ee11559002de09b"
sha256 arm64_monterey: "98186e4f8856e6b9bf6b066f6f4e732679892038a4b52679a9489bb06ea96716"
sha256 arm64_big_sur: "90c6e39856c80b18ec9bcfc138abfa0405a59d9757e388084bda5c364b850b56"
sha256 ventura: "52d7bf0a6f7ea153aff7ee3f66370b39ad457cccde1a6df4ddce32c2105a09d9"
sha256 monterey: "499e4853df920d45b9c1c06a01d143005c283297b155ff07c5a08e90962499f8"
sha256 big_sur: "74f1680f7a335b8dd5fa86d6b5cf0279bce1925023770aaf301e7ff23f8c7313"
sha256 x86_64_linux: "126d902967e54ed738ac28a1e03c1a27e20504d4bbdd2a68d8c3a70ba9a2b288"
end
# Don't update this unless this version cannot bootstrap the new version.
resource "gobootstrap" do
checksums = {
"darwin-arm64" => "4dac57c00168d30bbd02d95131d5de9ca88e04f2c5a29a404576f30ae9b54810",
"darwin-amd64" => "6000a9522975d116bf76044967d7e69e04e982e9625330d9a539a8b45395f9a8",
"linux-arm64" => "3770f7eb22d05e25fbee8fb53c2a4e897da043eb83c69b9a14f8d98562cd8098",
"linux-amd64" => "013a489ebb3e24ef3d915abe5b94c3286c070dfe0818d5bca8108f1d6e8440d2",
}
arch = "arm64"
platform = "darwin"
on_intel do
arch = "amd64"
end
on_linux do
platform = "linux"
end
boot_version = "1.16"
url "https://storage.googleapis.com/golang/go#{boot_version}.#{platform}-#{arch}.tar.gz"
version boot_version
sha256 checksums["#{platform}-#{arch}"]
end
def install
(buildpath/"gobootstrap").install resource("gobootstrap")
ENV["GOROOT_BOOTSTRAP"] = buildpath/"gobootstrap"
cd "src" do
ENV["GOROOT_FINAL"] = libexec
system "./make.bash", "--no-clean"
end
(buildpath/"pkg/obj").rmtree
rm_rf "gobootstrap" # Bootstrap not required beyond compile.
libexec.install Dir["*"]
bin.install_symlink Dir[libexec/"bin/go*"]
system bin/"go", "install", "-race", "std"
# Remove useless files.
# Breaks patchelf because folder contains weird debug/test files
(libexec/"src/debug/elf/testdata").rmtree
# Binaries built for an incompatible architecture
(libexec/"src/runtime/pprof/testdata").rmtree
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")
ENV["GOOS"] = "freebsd"
ENV["GOARCH"] = "amd64"
system bin/"go", "build", "hello.go"
end
end