diff options
| author | Khem Raj <raj.khem@gmail.com> | 2017-03-07 22:40:22 -0800 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-03-10 15:51:55 +0000 |
| commit | 760e81678cec80dcdaab12c2a0a0148e3e0ba275 (patch) | |
| tree | 6b587a2e9bd13c68788c1ff20df54db7e2f38c53 /meta/classes | |
| parent | 0efe58df2e5389f86dfbd53f90afc8f2970def7d (diff) | |
| download | poky-760e81678cec80dcdaab12c2a0a0148e3e0ba275.tar.gz | |
go: Add recipes for golang compilers and tools
* This is converging the recipes for go from
meta-virtualization and oe-meta-go
* Add recipes for go 1.7
* go.bbclass is added to ease out writing
recipes for go packages
* go-examples: Add an example, helloworld written in go
This should serve as temlate for writing go recipes
* Disable for musl, at least for now
* Disable for x32/ppc32 which is not supported
(From OE-Core rev: 78615e9260fb5d6569de4883521b049717fa4340)
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
| -rw-r--r-- | meta/classes/go.bbclass | 79 | ||||
| -rw-r--r-- | meta/classes/goarch.bbclass | 50 |
2 files changed, 129 insertions, 0 deletions
diff --git a/meta/classes/go.bbclass b/meta/classes/go.bbclass new file mode 100644 index 0000000000..f1984604b0 --- /dev/null +++ b/meta/classes/go.bbclass | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | inherit goarch | ||
| 2 | |||
| 3 | # Incompatible with musl, at least for now | ||
| 4 | COMPATIBLE_HOST_libc-musl_class-target = "null" | ||
| 5 | # x32 ABI is not supported on go compiler so far | ||
| 6 | COMPATIBLE_HOST_linux-gnux32 = "null" | ||
| 7 | # ppc32 is not supported in go compilers | ||
| 8 | COMPATIBLE_HOST_powerpc = "null" | ||
| 9 | |||
| 10 | GOROOT_class-native = "${STAGING_LIBDIR_NATIVE}/go" | ||
| 11 | GOROOT = "${STAGING_LIBDIR_NATIVE}/${TARGET_SYS}/go" | ||
| 12 | GOBIN_FINAL_class-native = "${GOROOT_FINAL}/bin" | ||
| 13 | GOBIN_FINAL = "${GOROOT_FINAL}/bin/${GOOS}_${GOARCH}" | ||
| 14 | |||
| 15 | export GOOS = "${TARGET_GOOS}" | ||
| 16 | export GOARCH = "${TARGET_GOARCH}" | ||
| 17 | export GOARM = "${TARGET_GOARM}" | ||
| 18 | export CGO_ENABLED = "1" | ||
| 19 | export GOROOT | ||
| 20 | export GOROOT_FINAL = "${libdir}/${TARGET_SYS}/go" | ||
| 21 | export GOBIN_FINAL | ||
| 22 | export GOPKG_FINAL = "${GOROOT_FINAL}/pkg/${GOOS}_${GOARCH}" | ||
| 23 | export GOSRC_FINAL = "${GOROOT_FINAL}/src" | ||
| 24 | export GO_GCFLAGS = "${TARGET_CFLAGS}" | ||
| 25 | export GO_LDFLAGS = "${TARGET_LDFLAGS}" | ||
| 26 | export CGO_CFLAGS = "${TARGET_CC_ARCH}${TOOLCHAIN_OPTIONS} ${TARGET_CFLAGS}" | ||
| 27 | export CGO_CPPFLAGS = "${TARGET_CPPFLAGS}" | ||
| 28 | export CGO_CXXFLAGS = "${TARGET_CC_ARCH}${TOOLCHAIN_OPTIONS} ${TARGET_CXXFLAGS}" | ||
| 29 | export CGO_LDFLAGS = "${TARGET_CC_ARCH}${TOOLCHAIN_OPTIONS} ${TARGET_LDFLAGS}" | ||
| 30 | |||
| 31 | DEPENDS += "go-cross-${TARGET_ARCH}" | ||
| 32 | DEPENDS_class-native += "go-native" | ||
| 33 | |||
| 34 | FILES_${PN}-staticdev += "${GOSRC_FINAL}/${GO_IMPORT}" | ||
| 35 | FILES_${PN}-staticdev += "${GOPKG_FINAL}/${GO_IMPORT}*" | ||
| 36 | |||
| 37 | GO_INSTALL ?= "${GO_IMPORT}/..." | ||
| 38 | |||
| 39 | do_go_compile() { | ||
| 40 | GOPATH=${S}:${STAGING_LIBDIR}/${TARGET_SYS}/go go env | ||
| 41 | if test -n "${GO_INSTALL}" ; then | ||
| 42 | GOPATH=${S}:${STAGING_LIBDIR}/${TARGET_SYS}/go go install -v ${GO_INSTALL} | ||
| 43 | fi | ||
| 44 | } | ||
| 45 | |||
| 46 | do_go_install() { | ||
| 47 | rm -rf ${WORKDIR}/staging | ||
| 48 | install -d ${WORKDIR}/staging${GOROOT_FINAL} ${D}${GOROOT_FINAL} | ||
| 49 | tar -C ${S} -cf - . | tar -C ${WORKDIR}/staging${GOROOT_FINAL} -xpvf - | ||
| 50 | |||
| 51 | find ${WORKDIR}/staging${GOROOT_FINAL} \( \ | ||
| 52 | -name \*.indirectionsymlink -o \ | ||
| 53 | -name .git\* -o \ | ||
| 54 | -name .hg -o \ | ||
| 55 | -name .svn -o \ | ||
| 56 | -name .pc\* -o \ | ||
| 57 | -name patches\* \ | ||
| 58 | \) -print0 | \ | ||
| 59 | xargs -r0 rm -rf | ||
| 60 | |||
| 61 | tar -C ${WORKDIR}/staging${GOROOT_FINAL} -cf - . | \ | ||
| 62 | tar -C ${D}${GOROOT_FINAL} -xpvf - | ||
| 63 | |||
| 64 | chown -R root:root "${D}${GOROOT_FINAL}" | ||
| 65 | |||
| 66 | if test -e "${D}${GOBIN_FINAL}" ; then | ||
| 67 | install -d -m 0755 "${D}${bindir}" | ||
| 68 | find "${D}${GOBIN_FINAL}" ! -type d -print0 | xargs -r0 mv --target-directory="${D}${bindir}" | ||
| 69 | rmdir -p "${D}${GOBIN_FINAL}" || true | ||
| 70 | fi | ||
| 71 | } | ||
| 72 | |||
| 73 | do_compile() { | ||
| 74 | do_go_compile | ||
| 75 | } | ||
| 76 | |||
| 77 | do_install() { | ||
| 78 | do_go_install | ||
| 79 | } | ||
diff --git a/meta/classes/goarch.bbclass b/meta/classes/goarch.bbclass new file mode 100644 index 0000000000..4a5b2ec787 --- /dev/null +++ b/meta/classes/goarch.bbclass | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | BUILD_GOOS = "${@go_map_os(d.getVar('BUILD_OS', True), d)}" | ||
| 2 | BUILD_GOARCH = "${@go_map_arch(d.getVar('BUILD_ARCH', True), d)}" | ||
| 3 | BUILD_GOTUPLE = "${BUILD_GOOS}_${BUILD_GOARCH}" | ||
| 4 | HOST_GOOS = "${@go_map_os(d.getVar('HOST_OS', True), d)}" | ||
| 5 | HOST_GOARCH = "${@go_map_arch(d.getVar('HOST_ARCH', True), d)}" | ||
| 6 | HOST_GOARM = "${@go_map_arm(d.getVar('HOST_ARCH', True), d.getVar('TUNE_FEATURES', True), d)}" | ||
| 7 | HOST_GOTUPLE = "${HOST_GOOS}_${HOST_GOARCH}" | ||
| 8 | TARGET_GOOS = "${@go_map_os(d.getVar('TARGET_OS', True), d)}" | ||
| 9 | TARGET_GOARCH = "${@go_map_arch(d.getVar('TARGET_ARCH', True), d)}" | ||
| 10 | TARGET_GOARM = "${@go_map_arm(d.getVar('TARGET_ARCH', True), d.getVar('TUNE_FEATURES', True), d)}" | ||
| 11 | TARGET_GOTUPLE = "${TARGET_GOOS}_${TARGET_GOARCH}" | ||
| 12 | GO_BUILD_BINDIR = "${@['bin/${HOST_GOTUPLE}','bin'][d.getVar('BUILD_GOTUPLE',True) == d.getVar('HOST_GOTUPLE',True)]}" | ||
| 13 | |||
| 14 | def go_map_arch(a, d): | ||
| 15 | import re | ||
| 16 | if re.match('i.86', a): | ||
| 17 | return '386' | ||
| 18 | elif a == 'x86_64': | ||
| 19 | return 'amd64' | ||
| 20 | elif re.match('arm.*', a): | ||
| 21 | return 'arm' | ||
| 22 | elif re.match('aarch64.*', a): | ||
| 23 | return 'arm64' | ||
| 24 | elif re.match('mips64el*', a): | ||
| 25 | return 'mips64le' | ||
| 26 | elif re.match('mips64*', a): | ||
| 27 | return 'mips64' | ||
| 28 | elif re.match('mipsel*', a): | ||
| 29 | return 'mipsle' | ||
| 30 | elif re.match('mips*', a): | ||
| 31 | return 'mips' | ||
| 32 | elif re.match('p(pc|owerpc)(64)', a): | ||
| 33 | return 'ppc64' | ||
| 34 | elif re.match('p(pc|owerpc)(64el)', a): | ||
| 35 | return 'ppc64le' | ||
| 36 | else: | ||
| 37 | raise bb.parse.SkipPackage("Unsupported CPU architecture: %s" % a) | ||
| 38 | |||
| 39 | def go_map_arm(a, f, d): | ||
| 40 | import re | ||
| 41 | if re.match('arm.*', a) and re.match('arm.*7.*', f): | ||
| 42 | return '7' | ||
| 43 | return '' | ||
| 44 | |||
| 45 | def go_map_os(o, d): | ||
| 46 | if o.startswith('linux'): | ||
| 47 | return 'linux' | ||
| 48 | return o | ||
| 49 | |||
| 50 | |||
