How to package go project for homebrew
Asked Answered
D

5

17

We're developing runscripts and try to support something like brew install runscripts.

It's written in golang and have some dependencies which required to go get. Now I have no idea to write the Formula to setup GOPATH and run go get. Our project can be compiled into an binary but we need run --init to install it.

Can anyone helps to give an example about a homebrew Formula of go project?

Domiciliary answered 24/11, 2014 at 2:26 Comment(2)
Docker is in Go: github.com/Homebrew/homebrew/blob/master/Library/Formula/…Yean
Thanks @Matt. I have read docker.rb but it's a little complicated. We just need to go get the dependencies and run a command to install it.Domiciliary
W
5

Fork homebrew, look at the content of Library/Formula/consul.rb. You don't need to manually generate all the resources. Use homebrew-go-resources. A more complete intro could be found here.

War answered 10/8, 2015 at 20:39 Comment(0)
D
1

I have refer to termshare.rb and it seems we can simply go get and homebrew will handle anything about GOPATH for us.

That's great and I think my problem is solved.

Domiciliary answered 24/11, 2014 at 9:47 Comment(1)
The original link is archived (read-only) but it still has value, so I didn't want to edit it. However, this is the current link to the termshare.rb formula: github.com/Homebrew/homebrew-core/blob/master/Formula/…Conation
P
1

The best I could find is how docker-swarm is added to brew: https://github.com/Homebrew/homebrew/blob/4c6857b0e337b2d5afd49dcf7209b6b5091709f4/Library/Formula/docker-swarm.rb

It's relatively clean and simple to follow.

Pharmacognosy answered 5/8, 2015 at 14:4 Comment(0)
V
1

You can use goreleaser to generate the formula automatically: https://goreleaser.com/customization/homebrew/

Voight answered 10/8, 2021 at 4:10 Comment(0)
M
0

Here is a possible work around creating a build directory within the checkout as the GOPATH:

...
def install
    system "mkdir -p build/src"
    system "ln -s `pwd` build/src/repo"
    system "GOPATH=`pwd`/build go get repo/mytool"
    bin.install "build/bin/mytool"
    ...
end
...
Maletta answered 28/6, 2015 at 2:51 Comment(1)
Very curious why this was downvoted. It ended up working for me.Cusack

© 2022 - 2024 — McMap. All rights reserved.