4

I intend to create a Gentoo ebuild for a project written in Go, and I'm wondering whether this has been done before.

As building and installing a Go project from source seems sufficiently different compared to projects in other programming languages, it would be useful for me to compare to an existing ebuild for figuring out best practices.

However, in the current portage tree I can't find any package that would depend on "dev-lang/go". Is there such an ebuild, perhaps in an overlay?

Nicolas Kaiser
  • 1,628
  • 2
  • 14
  • 26

4 Answers4

1

How about go-overlay to look for example ebuilds? They wrote a special ebuild class for building Go apllications and libraries in a few lines. Let me use their dev-util/flint-0.0.4 ebuild as an illustration (all comments are mine):

EAPI=6

GOLANG_PKG_IMPORTPATH="github.com/pengwynn"
GOLANG_PKG_VERSION="c3a5d8d9a2e04296fba560d9a22f763cff68eb75"

# Many Go projects don't pin versions of their dependencies,
# so it may has to be done here. You might not need this step if
# the upstream already uses 'godep' or simular tool.
GOLANG_PKG_DEPENDENCIES=(
    "github.com/codegangsta/cli:142e6cd241"
    "github.com/fatih/color:1b35f289c4"
    "github.com/octokit/go-octokit:4408b5393e"
    "github.com/fhs/go-netrc:4422b68c9c"
    "github.com/jingweno/go-sawyer:1999ae5763"
    "github.com/shiena/ansicolor:264b056680"
    "github.com/jtacoma/uritemplates:0a85813eca"
)

# Since many projects don't require custom build steps,
# this single line may be enough.
inherit golang-single

# Nothing special about these variables.    
DESCRIPTION="Check your project for common sources of contributor friction"
HOMEPAGE="https://${GOLANG_PKG_IMPORTPATH}/${PN}"    
LICENSE="MIT"
KEYWORDS="amd64 x86 arm"

# Prevent simulateneous installing with 'dev-go/flint'.
# Honestly, I was unable to this package on the Internet.
SLOT="0"
DEPEND="!dev-go/${PN}"
firegurafiku
  • 3,017
  • 1
  • 28
  • 37
0

Here is a working example of an ebuild which installs a go project:

https://github.com/timboudreau/gentoo/blob/master/net-misc/syncthing/syncthing-0.11.7.ebuild

Tim Boudreau
  • 1,741
  • 11
  • 13
0

It is possible. I just made one in my overlay. It was a little bit painful, but it works.

There are a few important things, that have to be done.

  1. Create golang eclasses in your repository, if you don't have go-overlay added in your system.
  2. GOLANG_PKG_IMPORTPATH variable specifies a GitHub profile, from which will be downloaded source code.
  3. GOLANG_PKG_DEPENDENCIES variable specifies GitHub repositories and particular commits of all dependencies.
  4. inherit golang-single imports mentioned eclass and at the same time adds dev-lang/go into dependencies.
BlueManCZ
  • 417
  • 6
  • 12
-1

It looks like there's an existing, working ebuild.

From: https://gist.github.com/matsuu/233858 (and also found at http://git.overlays.gentoo.org/gitweb/?p=proj/glentoo-overlay.git;a=blob_plain;f=dev-lang/golang-platform/golang-platform-9999.ebuild;hb=HEAD)

# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI="2"
inherit elisp-common eutils mercurial toolchain-funcs

DESCRIPTION="The Go Programming Language"
HOMEPAGE="http://golang.org/"
SRC_URI=""
EHG_REPO_URI="https://go.googlecode.com/hg/"
EHG_REVISION="release"

LICENSE="BSD"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="emacs vim-syntax"

RESTRICT="test"

RDEPEND="sys-devel/gcc"
DEPEND="${RDEPEND}
    emacs? ( virtual/emacs )
    sys-devel/bison
    sys-apps/ed"

S="${WORKDIR}/hg"

ENVFILE="${WORKDIR}/50${PN}"

src_prepare() {
    GOBIN="${WORKDIR}/bin"
    mkdir -p "${GOBIN}" || die

    sed -i \
        -e "/^GOBIN=/s:=.*:=${GOBIN}:" \
        -e "/MAKEFLAGS=/s:=.*:=${MAKEOPTS}:" \
        src/make.bash || die

    sed -i \
        -e "/^CFLAGS=/s:-O2:${CFLAGS}:" \
        src/Make.conf || die

    case ${ARCH} in
    x86)
        GOARCH="386"
        ;;
    *)
        GOARCH="${ARCH}"
        ;;
    esac

    case ${CHOST} in
    *-darwin*)
        GOOS="darwin"
        ;;
    *)
        GOOS="linux"
        ;;
    esac
#   *-nacl*)
#       GOOS="nacl"
#       ;;

    cat > "${ENVFILE}" <<EOF
GOROOT="/usr/$(get_libdir)/${PN}"
GOARCH="${GOARCH}"
GOOS="${GOOS}"
EOF
    . "${ENVFILE}"

    export GOBIN GOROOT GOARCH GOOS
}

src_compile() {
    cd src
    PATH="${GOBIN}:${PATH}" GOROOT="${S}" CC="$(tc-getCC)" ./make.bash || die
    if use emacs ; then
        elisp-compile "${S}"/misc/emacs/*.el || die
    fi
}

src_test() {
    cd src
    PATH="${GOBIN}:${PATH}" GOROOT="${S}" CC="$(tc-getCC)" ./run.bash || die
}

src_install() {
    dobin "${GOBIN}"/* || die

    insinto "${GOROOT}"
    doins -r pkg || die

    if use emacs ; then
        elisp-install ${PN} "${S}"/misc/emacs/*.el* || die "elisp-install failed"
    fi

    if use vim-syntax ; then
        insinto /usr/share/vim/vimfiles/plugin
        doins "${S}"/misc/vim/go.vim || die
    fi

    doenvd "${ENVFILE}" || die

    dodoc AUTHORS CONTRIBUTORS README || die
    dohtml -r doc/* || die
}

pkg_postinst() {
    elog "please don't forget to source /etc/profile"
}

Sorry, I haven't tested it as I don't have a running Gentoo instance right now. Hope it works.

Intermernet
  • 18,604
  • 4
  • 49
  • 61
  • I think the OP isn't looking for an ebuild to build the Go package, but an ebuild to [easily] build a project written in the Go language. – cd1 Dec 20 '14 at 21:04
  • That is an ebuild for building the go language itself. The question is asking how to do an ebuild for a project *written in* go. – Tim Boudreau May 31 '15 at 12:17
  • @TimBoudreau Go *is* a project written (the majority, at the time of the question, more than 2 years ago. Recently almost entirely) in Go. The structure of the ebuild should be simpler for a regular Go project, especially as there is a standard Go package for Gentoo now, which can be set as a depency (https://devmanual.gentoo.org/general-concepts/dependencies/) – Intermernet May 31 '15 at 12:51