Revamp the Go support
v10 cover Revamp the Go support
This improves the Go support on OE-Core.
We are trying to port as much as possible work done by Matt on meta-golang back to OE-Core and also to avoid carrying old releases as there is no need to support more versions of Go toolchain.
This fixes issues in existing support as well as add support for SDK generation which supports Go.
Changes in v10:
- new patch
- new patch
- new patch
- new patch
- new patch
Matt Madison (4):
go-crosssdk: fix host/target references and cleanup
go: fix linking issues for nativesdk builds
go: fixes for cross-canadian builds go.bbclass: set TMPDIR during compilation
Otavio Salvador (1):
Add Go toolchain support
meta/classes/go.bbclass | 10 +++++- meta/recipes-core/meta/meta-go-toolchain.bb | 12 +++++++ .../packagegroup-go-cross-canadian.bb | 12 +++++++ .../packagegroups/packagegroup-go-sdk-target.bb | 8 +++++ meta/recipes-devtools/go/go-1.9.inc | 1 + ...dd-GOHOSTxx-indirection-for-cross-canadia.patch | 33 ++++++++++++++++++ meta/recipes-devtools/go/go-cross-canadian.inc | 40 ++++++++++------------ meta/recipes-devtools/go/go-crosssdk.inc | 11 +++--- meta/recipes-devtools/go/go-runtime.inc | 5 +++ meta/recipes-devtools/go/go-target.inc | 3 ++ 10 files changed, 106 insertions(+), 29 deletions(-) create mode 100644 meta/recipes-core/meta/meta-go-toolchain.bb create mode 100644 meta/recipes-core/packagegroups/packagegroup-go-cross-canadian.bb create mode 100644 meta/recipes-core/packagegroups/packagegroup-go-sdk-target.bb create mode 100644 meta/recipes-devtools/go/go-1.9/0008-make.bash-add-GOHOSTxx-indirection-for-cross-canadia.patch
Signature · 1 line
2.14.1
PATCH v10 1/5 go-crosssdk: fix host/target references and cleanup
From: Matt Madison <[email protected]>
* The _FOR_TARGET variables need to include SDKNATIVEPATH
* Install tools (cmd) only, and for the build host
* Remove unnecessary FILES setting
Corrects some errors when the build host architecture is different from the SDKMACHINE's.
---
Changes in v10:
- new patch
meta/recipes-devtools/go/go-crosssdk.inc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
meta/recipes-devtools/go/go-crosssdk.inc +5 -6
@@ -11,8 +11,9 @@ export GOARCH = "${TARGET_GOARCH}" export GOROOT_BOOTSTRAP = "${STAGING_LIBDIR_NATIVE}/go" export GOROOT_FINAL = "${libdir}/go" export CGO_ENABLED = "1" -export CC_FOR_TARGET="${TARGET_PREFIX}gcc ${TARGET_CC_ARCH} --sysroot=${STAGING_DIR_TARGET}" -export CXX_FOR_TARGET="${TARGET_PREFIX}g++ ${TARGET_CC_ARCH} --sysroot=${STAGING_DIR_TARGET}" +export CC_FOR_TARGET="${TARGET_PREFIX}gcc ${TARGET_CC_ARCH} --sysroot=${STAGING_DIR_TARGET}${SDKPATHNATIVE}" +export CXX_FOR_TARGET="${TARGET_PREFIX}g++ ${TARGET_CC_ARCH} --sysroot=${STAGING_DIR_TARGET}${SDKPATHNATIVE}" +export GO_INSTALL = "cmd" CC = "${@d.getVar('BUILD_CC', True).strip()}" do_configure[noexec] = "1"
@@ -43,13 +44,11 @@ do_install() { install -d ${D}${libdir}/go/bin install -d ${D}${libdir}/go/pkg/tool install -d ${D}${bindir} - cp --preserve=mode,timestamps -R ${S}/pkg/tool/${TARGET_GOTUPLE} ${D}${libdir}/go/pkg/tool/ - for f in ${B}/${GO_BUILD_BINDIR}/* + cp --preserve=mode,timestamps -R ${S}/pkg/tool/${BUILD_GOTUPLE} ${D}${libdir}/go/pkg/tool/ + for f in ${B}/bin/* do base=`basename $f` install -m755 $f ${D}${libdir}/go/bin make_wrapper $base ${TARGET_PREFIX}$base done } - -FILES_${PN}-staticdev = "${libdir}/go/pkg"
Signature · 1 line
2.14.1
PATCH v10 2/5 go: fix linking issues for nativesdk builds
In reply to Otavio SalvadorFrom: Matt Madison <[email protected]>
Switch to using an external linker for nativesdk go, go-runtime, and go package builds, which works more reliably when building 32-bit SDKs.
---
Changes in v10:
- new patch
meta/classes/go.bbclass | 4 +++- meta/recipes-devtools/go/go-runtime.inc | 5 +++++ meta/recipes-devtools/go/go-target.inc | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-)
meta/classes/go.bbclass +3 -1
@@ -37,7 +37,9 @@ GO_RPATH = "${@'-r ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_D GO_RPATH_class-native = "${@'-r ${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}" GO_RPATH_LINK_class-native = "${@'-Wl,-rpath-link=${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}" GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS}" -GO_LDFLAGS ?= '-ldflags="${GO_RPATH} -extldflags '${GO_EXTLDFLAGS}'"' +GO_LINKMODE ?= "" +GO_LINKMODE_class-nativesdk = "--linkmode=external" +GO_LDFLAGS ?= '-ldflags="${GO_RPATH} ${GO_LINKMODE} -extldflags '${GO_EXTLDFLAGS}'"' export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS}" export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c" export GOPTESTFLAGS ?= "-test.v"
meta/recipes-devtools/go/go-runtime.inc +5 -0
@@ -45,6 +45,11 @@ do_install() { done } +# Remove test binaries that cannot be relocated +do_install_append_class-nativesdk() { + rm -rf ${D}${libdir}/go/src/runtime/pprof/testdata +} + # These testdata directories aren't needed for builds and contain binaries # that can cause errors in sysroot_strip(), so just remove them. sysroot_stage_all_append() {
meta/recipes-devtools/go/go-target.inc +3 -0
@@ -14,6 +14,9 @@ export CC_FOR_TARGET = "${CC}" export CXX_FOR_TARGET = "${CXX}" export GO_TARGET_INSTALL = "cmd" export GO_FLAGS = "-a" +GO_LDFLAGS = "" +GO_LDFLAGS_class-nativesdk = "-linkmode external" +export GO_LDFLAGS do_configure[noexec] = "1"
Signature · 1 line
2.14.1
PATCH v10 3/5 go: fixes for cross-canadian builds
In reply to Otavio SalvadorFrom: Matt Madison <[email protected]>
* Add patch for go's make script to allow for
build system != host system
* Add dependencies on the appropriate crosssdk recipes, and use the crosssdk C compiler and linker
* Remove bashism in the wrapper script
* Restrict installation to only the tool binaries
to address some packaging errors
---
Changes in v10:
- new patch
meta/recipes-devtools/go/go-1.9.inc | 1 + ...dd-GOHOSTxx-indirection-for-cross-canadia.patch | 33 ++++++++++++++++++ meta/recipes-devtools/go/go-cross-canadian.inc | 40 ++++++++++------------ 3 files changed, 52 insertions(+), 22 deletions(-) create mode 100644 meta/recipes-devtools/go/go-1.9/0008-make.bash-add-GOHOSTxx-indirection-for-cross-canadia.patch
meta/recipes-devtools/go/go-1.9.inc +1 -0
@@ -13,6 +13,7 @@ SRC_URI += "\ file://0005-cmd-go-make-GOROOT-precious-by-default.patch \ file://0006-make.bash-add-GOTOOLDIR_BOOTSTRAP-environment-variab.patch \ file://0007-ld-add-soname-to-shareable-objects.patch \ + file://0008-make.bash-add-GOHOSTxx-indirection-for-cross-canadia.patch \ " SRC_URI[main.md5sum] = "da2d44ea384076efec43ee1f8b7d45d2" SRC_URI[main.sha256sum] = "a4ab229028ed167ba1986825751463605264e44868362ca8e7accc8be057e993"
meta/recipes-devtools/go/go-1.9/0008-make.bash-add-GOHOSTxx-indirection-for-cross-canadia.patch new file +33 -0
@@ -0,0 +1,33 @@ +From 03e6c339d4fb712fbb8c4ca6ef2fc7100dcdb3d7 Mon Sep 17 00:00:00 2001 +From: Matt Madison <[email protected]> +Date: Thu, 14 Sep 2017 05:38:10 -0700 +Subject: [PATCH 8/8] make.bash: add GOHOSTxx indirection for cross-canadian + builds + +Add environment variables for specifying the host OS/arch +that we are building the compiler for, so it can differ from +the build host OS/arch. + +Upstream-Status: Pending + +Signed-off-by: Matt Madison <[email protected]> +--- + src/make.bash | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/src/make.bash b/src/make.bash +index 2e6fb05..0bdadc6 100755 +--- a/src/make.bash ++++ b/src/make.bash +@@ -173,6 +173,8 @@ if [ "$do_host_build" = "yes" ]; then + echo + + GOTOOLDIR_BOOTSTRAP="${GOTOOLDIR_BOOTSTRAP:-$GOTOOLDIR}" ++ GOHOSTOS="${GOHOSTOS_CROSS:-$GOHOSTOS}" ++ GOHOSTARCH="${GOHOSTARCH_CROSS:-$GOHOSTARCH}" + echo "##### Building packages and commands for host, $GOHOSTOS/$GOHOSTARCH." + # CC_FOR_TARGET is recorded as the default compiler for the go tool. When building for the host, however, + # use the host compiler, CC, from `cmd/dist/dist env` instead. +-- +2.7.4 +
meta/recipes-devtools/go/go-cross-canadian.inc +18 -22
@@ -1,21 +1,24 @@ inherit cross-canadian -DEPENDS = "go-native virtual/${HOST_PREFIX}gcc-crosssdk virtual/nativesdk-${HOST_PREFIX}libc-for-gcc virtual/nativesdk-${HOST_PREFIX}compilerlibs" +DEPENDS = "go-native virtual/${HOST_PREFIX}go-crosssdk virtual/nativesdk-${HOST_PREFIX}go-runtime \ + virtual/${HOST_PREFIX}gcc-crosssdk virtual/nativesdk-${HOST_PREFIX}libc-for-gcc \ + virtual/nativesdk-${HOST_PREFIX}compilerlibs" PN = "go-cross-canadian-${TRANSLATED_TARGET_ARCH}" export GOHOSTOS = "${BUILD_GOOS}" export GOHOSTARCH = "${BUILD_GOARCH}" -export GOOS = "${HOST_GOOS}" -export GOARCH = "${HOST_GOARCH}" -export GOARM = "${HOST_GOARM}" +export GOHOSTOS_CROSS = "${HOST_GOOS}" +export GOHOSTARCH_CROSS = "${HOST_GOARCH}" export GOROOT_BOOTSTRAP = "${STAGING_LIBDIR_NATIVE}/go" -export GOTOOLDIR_BOOTSTRAP = "${GOROOT_BOOTSTRAP}/pkg/tool/${BUILD_GOTUPLE}" +export GOTOOLDIR_BOOTSTRAP = "${STAGING_LIBDIR_NATIVE}/${HOST_SYS}/go/pkg/tool/${BUILD_GOTUPLE}" export GOROOT_FINAL = "${libdir}/go" export CGO_ENABLED = "1" -export CC_FOR_TARGET = "${HOST_CC}" -export CXX_FOR_TARGET = "${HOST_CXX}" -CC = "${@d.getVar('BUILD_CC', True).strip()}" -export GO_LDFLAGS = '-linkmode external -extld ${HOST_PREFIX}gcc -extldflags "${TOOLCHAIN_OPTIONS} ${LDFLAGS}"' +export CC_FOR_TARGET = "${TARGET_PREFIX}gcc" +export CXX_FOR_TARGET = "${TARGET_PREFIX}g++" +CC = "${HOST_PREFIX}gcc" +export CGO_CFLAGS = "--sysroot=${STAGING_DIR_TARGET} ${HOST_CC_ARCH} ${CFLAGS}" +export CGO_LDFLAGS = "--sysroot=${STAGING_DIR_TARGET} ${HOST_CC_ARCH} ${LDFLAGS}" +export GO_LDFLAGS = '-linkmode external -extld ${HOST_PREFIX}gcc -extldflags "--sysroot=${STAGING_DIR_TARGET} ${HOST_CC_ARCH} ${LDFLAGS}"' do_configure[noexec] = "1"
@@ -32,34 +35,27 @@ do_compile() { make_wrapper() { rm -f ${D}${bindir}/$2 cat <<END >${D}${bindir}/$2 -#!/bin/bash +#!/bin/sh here=\`dirname \$0\` native_goroot=\`readlink -f \$here/../../lib/${TARGET_SYS}/go\` export GOARCH="${TARGET_GOARCH}" export GOOS="${TARGET_GOOS}" -export GOARM="\${GOARM:-${TARGET_GOARM}}" +test -n "\$GOARM" || export GOARM="${TARGET_GOARM}" export GOTOOLDIR="\$native_goroot/pkg/tool/${HOST_GOTUPLE}" -export GOROOT="\${GOROOT:-\$OECORE_TARGET_SYSROOT/${target_libdir}/go}" +test -n "\$GOROOT" || export GOROOT="\$OECORE_TARGET_SYSROOT/${target_libdir}/go" \$here/../../lib/${TARGET_SYS}/go/bin/$1 "\$@" END chmod +x ${D}${bindir}/$2 } do_install() { - install -d ${D}${libdir}/go - cp --preserve=mode,timestamps -R ${B}/pkg ${D}${libdir}/go/ - install -d ${D}${libdir}/go/src - (cd ${S}/src; for d in *; do \ - [ -d $d ] && cp --preserve=mode,timestamps -R ${S}/src/$d ${D}${libdir}/go/src/; \ - done) - rm -rf ${D}${libdir}/go/src/runtime/pprof/testdata + install -d ${D}${libdir}/go/pkg/tool + cp --preserve=mode,timestamps -R ${B}/pkg/tool/${HOST_GOTUPLE} ${D}${libdir}/go/pkg/tool/ install -d ${D}${bindir} ${D}${libdir}/go/bin - for f in ${B}/bin/* + for f in ${B}/${GO_BUILD_BINDIR}/* do base=`basename $f` install -m755 $f ${D}${libdir}/go/bin make_wrapper $base ${TARGET_PREFIX}$base done } - -FILES_${PN}-staticdev = "${libdir}/go/pkg"
Signature · 1 line
2.14.1
PATCH v10 4/5 go.bbclass: set TMPDIR during compilation
In reply to Otavio SalvadorFrom: Matt Madison <[email protected]>
The go build tool creates working directories under $TMPDIR for all of its processing. Create a directory under ${WORKDIR} for this and point TMPDIR at it during compilation, so that systems that have a relatively small /tmp filesystems can still compile larger Go packages.
---
Changes in v10:
- new patch
meta/classes/go.bbclass | 6 ++++++ 1 file changed, 6 insertions(+)
meta/classes/go.bbclass +6 -0
@@ -61,6 +61,8 @@ GO_INSTALL_FILTEROUT ?= "${GO_IMPORT}/vendor/" B = "${WORKDIR}/build" export GOPATH = "${B}" +GO_TMPDIR ?= "${WORKDIR}/go-tmp" +GO_TMPDIR[vardepvalue] = "" python go_do_unpack() { src_uri = (d.getVar('SRC_URI') or "").split()
@@ -97,14 +99,17 @@ go_do_configure() { } go_do_compile() { + export TMPDIR="${GO_TMPDIR}" ${GO} env if [ -n "${GO_INSTALL}" ]; then ${GO} install ${GO_LINKSHARED} ${GOBUILDFLAGS} `go_list_packages` fi } +do_compile[dirs] =+ "${GO_TMPDIR}" do_compile[cleandirs] = "${B}/bin ${B}/pkg" do_compile_ptest() { + export TMPDIR="${GO_TMPDIR}" rm -f ${B}/.go_compiled_tests.list go_list_package_tests | while read pkg; do cd ${B}/src/$pkg
@@ -113,6 +118,7 @@ do_compile_ptest() { sed -e's,/\./,/,'>> ${B}/.go_compiled_tests.list done } +do_compile_ptest_base[dirs] =+ "${GO_TMPDIR}" go_do_install() { install -d ${D}${libdir}/go/src/${GO_IMPORT}
Signature · 1 line
2.14.1
PATCH v10 5/5 Add Go toolchain support
In reply to Otavio SalvadorThis adds the meta-go-toolchain. It enables the generation of a Go toolchain allowing for cross compiling for target architecture.
---
Changes in v10:
- new patch
meta/recipes-core/meta/meta-go-toolchain.bb | 12 ++++++++++++ .../packagegroups/packagegroup-go-cross-canadian.bb | 12 ++++++++++++ .../recipes-core/packagegroups/packagegroup-go-sdk-target.bb | 8 ++++++++ 3 files changed, 32 insertions(+) create mode 100644 meta/recipes-core/meta/meta-go-toolchain.bb create mode 100644 meta/recipes-core/packagegroups/packagegroup-go-cross-canadian.bb create mode 100644 meta/recipes-core/packagegroups/packagegroup-go-sdk-target.bb
meta/recipes-core/meta/meta-go-toolchain.bb new file +12 -0
@@ -0,0 +1,12 @@ +SUMMARY = "Meta package for building a installable Go toolchain" +LICENSE = "MIT" + +inherit populate_sdk + +TOOLCHAIN_HOST_TASK_append = " \ + packagegroup-go-cross-canadian-${MACHINE} \ +" + +TOOLCHAIN_TARGET_TASK_append = " \ + ${@multilib_pkg_extend(d, 'packagegroup-go-sdk-target')} \ +"
meta/recipes-core/packagegroups/packagegroup-go-cross-canadian.bb new file +12 -0
@@ -0,0 +1,12 @@ +SUMMARY = "Host SDK package for Go cross canadian toolchain" +PN = "packagegroup-go-cross-canadian-${MACHINE}" + +inherit cross-canadian packagegroup + +PACKAGEGROUP_DISABLE_COMPLEMENTARY = "1" + +GO = "go-cross-canadian-${TRANSLATED_TARGET_ARCH}" + +RDEPENDS_${PN} = " \ + ${@all_multilib_tune_values(d, 'GO')} \ +"
meta/recipes-core/packagegroups/packagegroup-go-sdk-target.bb new file +8 -0
@@ -0,0 +1,8 @@ +SUMMARY = "Target packages for the Go SDK" + +inherit packagegroup + +RDEPENDS_${PN} = " \ + go-runtime \ + go-runtime-dev \ +"
Signature · 1 line
2.14.1
✗ patchtest: failure for Revamp the Go support (rev10)
In reply to Otavio Salvador== Series Details ==
Series: Revamp the Go support (rev10)
Revision: 10
URL : https://patchwork.openembedded.org/series/8697/
State : failure
== Summary ==
Thank you for submitting this patch series to OpenEmbedded Core. This is an automated response. Several tests have been executed on the proposed series by patchtest resulting in the following failures:
* Patch [v10,5/5] Add Go toolchain support Issue Shortlog does not follow expected format [test_shortlog_format] Suggested fix Commit shortlog (first line of commit message) should follow the format "<target>: <summary>"
If you believe any of these test results are incorrect, please reply to the mailing list ([email protected]) raising your concerns. Otherwise we would appreciate you correcting the issues and submitting a new version of the patchset if applicable. Please ensure you add/increment the version number when sending the new version (i.e. [PATCH] -> [PATCH v2] -> [PATCH v3] -> ...).
---
Test framework: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest Test suite: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest-oe