Skip to content

Commit

Permalink
[email protected] 1.21.7 (new formula)
Browse files Browse the repository at this point in the history
Follow-up to
* Homebrew#157782

Signed-off-by: Rui Chen <[email protected]>
  • Loading branch information
stefanb authored and chenrui333 committed Feb 15, 2024
1 parent 98b060a commit def9d1d
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions Formula/g/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
class GoAT121 < Formula
desc "Open source programming language to build simple/reliable/efficient software"
homepage "https://go.dev/"
url "https://go.dev/dl/go1.21.7.src.tar.gz"
mirror "https://fossies.org/linux/misc/go1.21.7.src.tar.gz"
sha256 "00197ab20f33813832bff62fd93cca1c42a08cc689a32a6672ca49591959bff6"
license "BSD-3-Clause"

livecheck do
url "https://go.dev/dl/?mode=json"
regex(/^go[._-]?v?(1\.21(?:\.\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

keg_only :versioned_formula

depends_on "go" => :build

def install
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

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
(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")

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

0 comments on commit def9d1d

Please sign in to comment.