From b19a21acf1c4227e411316f2560b2e9b3b7f0160 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Thu, 25 Aug 2016 12:27:19 -0700 Subject: [PATCH] coreos-go-utils: new eclass for Go related utilities This eclass adopts parts of coreos-go.eclass and the dev-lang/go ebuilds, providing functionality useful to both types of builds. --- .../containerd/containerd-0.2.3.ebuild | 2 +- .../runc/runc-1.0.0_rc1_p20160615-r1.ebuild | 2 +- .../eclass/coreos-go-utils.eclass | 116 ++++++++++++++++++ .../coreos-overlay/eclass/coreos-go.eclass | 36 +----- 4 files changed, 124 insertions(+), 32 deletions(-) create mode 100644 sdk_container/src/third_party/coreos-overlay/eclass/coreos-go-utils.eclass diff --git a/sdk_container/src/third_party/coreos-overlay/app-emulation/containerd/containerd-0.2.3.ebuild b/sdk_container/src/third_party/coreos-overlay/app-emulation/containerd/containerd-0.2.3.ebuild index 9e685da1b4..462a6c2109 100644 --- a/sdk_container/src/third_party/coreos-overlay/app-emulation/containerd/containerd-0.2.3.ebuild +++ b/sdk_container/src/third_party/coreos-overlay/app-emulation/containerd/containerd-0.2.3.ebuild @@ -32,7 +32,7 @@ RDEPEND="app-emulation/runc S=${WORKDIR}/${P}/src/${EGO_PN} src_compile() { - export GOARCH=$(go_get_arch) + export GOARCH=$(go_arch) export CGO_ENABLED=1 export CC=$(tc-getCC) export CXX=$(tc-getCXX) diff --git a/sdk_container/src/third_party/coreos-overlay/app-emulation/runc/runc-1.0.0_rc1_p20160615-r1.ebuild b/sdk_container/src/third_party/coreos-overlay/app-emulation/runc/runc-1.0.0_rc1_p20160615-r1.ebuild index d87ae79698..cffab21a0b 100644 --- a/sdk_container/src/third_party/coreos-overlay/app-emulation/runc/runc-1.0.0_rc1_p20160615-r1.ebuild +++ b/sdk_container/src/third_party/coreos-overlay/app-emulation/runc/runc-1.0.0_rc1_p20160615-r1.ebuild @@ -34,7 +34,7 @@ src_prepare() { src_compile() { # fix up cross-compiling variables - export GOARCH=$(go_get_arch) + export GOARCH=$(go_arch) export CGO_ENABLED=1 export CC=$(tc-getCC) export CXX=$(tc-getCXX) diff --git a/sdk_container/src/third_party/coreos-overlay/eclass/coreos-go-utils.eclass b/sdk_container/src/third_party/coreos-overlay/eclass/coreos-go-utils.eclass new file mode 100644 index 0000000000..5131e5d716 --- /dev/null +++ b/sdk_container/src/third_party/coreos-overlay/eclass/coreos-go-utils.eclass @@ -0,0 +1,116 @@ +# Copyright 2016 CoreOS, Inc. +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ + +# @ECLASS: coreos-go-utils.eclass +# @BLURB: Utility functions for Go +# @DESCRIPTION: +# A utility eclass for functions needed when building both Go itself +# and packages that depend on it. It does not set any metadata. + +case "${EAPI:-0}" in + 5|6) ;; + *) die "Unsupported EAPI=${EAPI} for ${ECLASS}" +esac + +inherit flag-o-matic toolchain-funcs + +# @FUNCTION: go_arch +# @USAGE: [chost] +# @DESCRIPTION: +# export GOARCH=$(go_arch $CHOST) +go_arch() { + # By chance most portage arch names match Go + local portage_arch=$(tc-arch "${1:-${CHOST}}") + local endian=$(tc-endian "${1:-${CHOST}}") + case "${portage_arch}" in + x86) echo 386;; + x64-*) echo amd64;; + ppc64) + [[ "${endian}" = big ]] && echo ppc64 || echo ppc64le ;; + *) echo "${portage_arch}";; + esac +} + +# @FUNCTION: go_arm +# @USAGE: [chost] +# @DESCRIPTION: +# export GOARM=$(go_arm $CHOST) +go_arm() { + case "${1:-${CHOST}}" in + armv5*) echo 5;; + armv6*) echo 6;; + armv7*) echo 7;; + *) + die "unknown GOARM for ${1:-${CHOST}}" + ;; + esac +} + +# @FUNCTION: go_os +# @USAGE: [chost] +# @DESCRIPTION: +# export GOOS=$(go_os $CHOST) +go_os() { + case "${1:-${CHOST}}" in + *-linux*) echo linux;; + *-darwin*) echo darwin;; + *-freebsd*) echo freebsd;; + *-netbsd*) echo netbsd;; + *-openbsd*) echo openbsd;; + *-solaris*) echo solaris;; + *-cygwin*|*-interix*|*-winnt*) + echo windows + ;; + *) + die "unknown GOOS for ${1:-${CHOST}}" + ;; + esac +} + +# @FUNCTION: go_export +# @USAGE: [chost] +# @DESCRIPTION: +# Export GOARCH, GOOS, GOARM, CC, CXX, and CGO_* environment variables. +go_export() { + export GOARCH=$(go_arch "$@") + export GOOS=$(go_os "$@") + if [[ "${GOARCH}" == "arm" ]]; then + export GOARM=$(go_arm "$@") + fi + + # Go's 6l linker does not support PIE, disable so cgo binaries + # which use 6l+gcc for linking can be built correctly. + if gcc-specs-pie; then + append-ldflags -nopie + fi + + export CC=$(tc-getCC) + export CXX=$(tc-getCXX) + export CGO_ENABLED=${CGO_ENABLED:-1} + export CGO_CFLAGS="${CFLAGS}" + export CGO_CPPFLAGS="${CPPFLAGS}" + export CGO_CXXFLAGS="${CXXFLAGS}" + export CGO_LDFLAGS="${LDFLAGS}" +} + +# @FUNCTION: go_tuple +# @USAGE: [chost] +# @DESCRIPTION: +# The uniqe string defining a Go target, as used in directory names. +# e.g. linux_amd64 for x86_64-pc-linux-gnu +go_tuple() +{ + echo "$(go_os $@)_$(go_arch $@)" +} + +# @FUNCTION: go_cross_compile +# @USAGE: [chost] +# @DESCRIPTION: +# Check if Go consideres compiling for $CHOST as cross-compilation. +# Since Go's target tuples are smaller than GCC's Go may not consider +# itself as a cross-compiler even if the GCC it is using for cgo is. +go_cross_compile() +{ + [[ $(go_tuple ${CBUILD:-${CHOST}}) != $(go_tuple $@) ]] +} diff --git a/sdk_container/src/third_party/coreos-overlay/eclass/coreos-go.eclass b/sdk_container/src/third_party/coreos-overlay/eclass/coreos-go.eclass index 12f0428d71..aa22af7077 100644 --- a/sdk_container/src/third_party/coreos-overlay/eclass/coreos-go.eclass +++ b/sdk_container/src/third_party/coreos-overlay/eclass/coreos-go.eclass @@ -9,26 +9,15 @@ # @DESCRIPTION: # Name of the Go package unpacked to ${S}, this is required. -[[ ${EAPI} != "5" ]] && die "${ECLASS}: Only EAPI=5 is supported" +case "${EAPI:-0}" in + 5|6) ;; + *) die "Unsupported EAPI=${EAPI} for ${ECLASS}" +esac -inherit flag-o-matic multiprocessing toolchain-funcs +inherit coreos-go-utils multiprocessing DEPEND="dev-lang/go:=" -# @FUNCTION: go_get_arch -# @USAGE: export GOARCH=$(go_get_arch) -go_get_arch() { - # By chance most portage arch names match Go - local portage_arch=$(tc-arch ${CHOST}) - case "${portage_arch}" in - x86) echo 386;; - x64-*) echo amd64;; - ppc64) - [[ "$(tc-endian)" = big ]] && echo ppc64 || echo ppc64le ;; - *) echo "${portage_arch}";; - esac -} - # @FUNCTION: go_build # @USAGE: [] go_build() { @@ -55,7 +44,7 @@ go_build() { coreos-go_src_prepare() { debug-print-function ${FUNCNAME} "$@" - export GOARCH=$(go_get_arch) + go_export export GOPATH="${WORKDIR}/gopath" export GOBIN="${GOPATH}/bin" @@ -68,19 +57,6 @@ coreos-go_src_prepare() { local package_path="${GOPATH}/src/${COREOS_GO_PACKAGE}" mkdir -p "${package_path%/*}" || die "${ECLASS}: bad path: ${package_path%/*}" ln -sT "${S}" "${package_path}" || die "${ECLASS}: bad path: ${S}" - - # Go's 6l linker does not support PIE, disable so cgo binaries - # which use 6l+gcc for linking can be built correctly. - if gcc-specs-pie; then - append-ldflags -nopie - fi - - export CC=$(tc-getCC) - export CGO_ENABLED=${CGO_ENABLED:-1} - export CGO_CFLAGS="${CFLAGS}" - export CGO_CPPFLAGS="${CPPFLAGS}" - export CGO_CXXFLAGS="${CXXFLAGS}" - export CGO_LDFLAGS="${LDFLAGS}" } coreos-go_src_compile() {