Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 1 | inherit goarch |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 3 | GO_PARALLEL_BUILD ?= "${@oe.utils.parallel_make_argument(d, '-p %d')}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 4 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 5 | export GODEBUG = "gocachehash=1" |
| 6 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 7 | GOROOT:class-native = "${STAGING_LIBDIR_NATIVE}/go" |
| 8 | GOROOT:class-nativesdk = "${STAGING_DIR_TARGET}${libdir}/go" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 9 | GOROOT = "${STAGING_LIBDIR}/go" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 10 | export GOROOT |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 11 | export GOROOT_FINAL = "${libdir}/go" |
Brad Bishop | c8f4712 | 2019-06-24 09:36:18 -0400 | [diff] [blame] | 12 | export GOCACHE = "${B}/.cache" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 13 | |
Brad Bishop | d89cb5f | 2019-04-10 09:02:41 -0400 | [diff] [blame] | 14 | export GOARCH = "${TARGET_GOARCH}" |
| 15 | export GOOS = "${TARGET_GOOS}" |
| 16 | export GOHOSTARCH="${BUILD_GOARCH}" |
| 17 | export GOHOSTOS="${BUILD_GOOS}" |
| 18 | |
| 19 | GOARM[export] = "0" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 20 | GOARM:arm:class-target = "${TARGET_GOARM}" |
| 21 | GOARM:arm:class-target[export] = "1" |
Brad Bishop | d89cb5f | 2019-04-10 09:02:41 -0400 | [diff] [blame] | 22 | |
| 23 | GO386[export] = "0" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 24 | GO386:x86:class-target = "${TARGET_GO386}" |
| 25 | GO386:x86:class-target[export] = "1" |
Brad Bishop | d89cb5f | 2019-04-10 09:02:41 -0400 | [diff] [blame] | 26 | |
| 27 | GOMIPS[export] = "0" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 28 | GOMIPS:mips:class-target = "${TARGET_GOMIPS}" |
| 29 | GOMIPS:mips:class-target[export] = "1" |
Brad Bishop | d89cb5f | 2019-04-10 09:02:41 -0400 | [diff] [blame] | 30 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 31 | DEPENDS_GOLANG:class-target = "virtual/${TUNE_PKGARCH}-go virtual/${TARGET_PREFIX}go-runtime" |
| 32 | DEPENDS_GOLANG:class-native = "go-native" |
| 33 | DEPENDS_GOLANG:class-nativesdk = "virtual/${TARGET_PREFIX}go-crosssdk virtual/${TARGET_PREFIX}go-runtime" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 34 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 35 | DEPENDS:append = " ${DEPENDS_GOLANG}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 36 | |
| 37 | GO_LINKSHARED ?= "${@'-linkshared' if d.getVar('GO_DYNLINK') else ''}" |
| 38 | GO_RPATH_LINK = "${@'-Wl,-rpath-link=${STAGING_DIR_TARGET}${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}" |
| 39 | GO_RPATH = "${@'-r ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 40 | GO_RPATH:class-native = "${@'-r ${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}" |
| 41 | GO_RPATH_LINK:class-native = "${@'-Wl,-rpath-link=${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 42 | GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS}" |
| 43 | GO_LINKMODE ?= "" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 44 | GO_LINKMODE:class-nativesdk = "--linkmode=external" |
| 45 | GO_LINKMODE:class-native = "--linkmode=external" |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 46 | GO_EXTRA_LDFLAGS ?= "" |
| 47 | GO_LDFLAGS ?= '-ldflags="${GO_RPATH} ${GO_LINKMODE} ${GO_EXTRA_LDFLAGS} -extldflags '${GO_EXTLDFLAGS}'"' |
Andrew Geissler | 1e34c2d | 2020-05-29 16:02:59 -0500 | [diff] [blame] | 48 | export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS} -trimpath" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 49 | export GOPATH_OMIT_IN_ACTIONID ?= "1" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 50 | export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 51 | export GOPTESTFLAGS ?= "" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 52 | GOBUILDFLAGS:prepend:task-compile = "${GO_PARALLEL_BUILD} " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 53 | |
| 54 | export GO = "${HOST_PREFIX}go" |
| 55 | GOTOOLDIR = "${STAGING_LIBDIR_NATIVE}/${TARGET_SYS}/go/pkg/tool/${BUILD_GOTUPLE}" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 56 | GOTOOLDIR:class-native = "${STAGING_LIBDIR_NATIVE}/go/pkg/tool/${BUILD_GOTUPLE}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 57 | export GOTOOLDIR |
| 58 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 59 | export CGO_ENABLED ?= "1" |
| 60 | export CGO_CFLAGS ?= "${CFLAGS}" |
| 61 | export CGO_CPPFLAGS ?= "${CPPFLAGS}" |
| 62 | export CGO_CXXFLAGS ?= "${CXXFLAGS}" |
| 63 | export CGO_LDFLAGS ?= "${LDFLAGS}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 64 | |
| 65 | GO_INSTALL ?= "${GO_IMPORT}/..." |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 66 | GO_INSTALL_FILTEROUT ?= "${GO_IMPORT}/vendor/" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 67 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 68 | B = "${WORKDIR}/build" |
| 69 | export GOPATH = "${B}" |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 70 | export GOTMPDIR ?= "${WORKDIR}/build-tmp" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 71 | GOTMPDIR[vardepvalue] = "" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 72 | |
| 73 | python go_do_unpack() { |
| 74 | src_uri = (d.getVar('SRC_URI') or "").split() |
| 75 | if len(src_uri) == 0: |
| 76 | return |
| 77 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 78 | fetcher = bb.fetch2.Fetch(src_uri, d) |
| 79 | for url in fetcher.urls: |
| 80 | if fetcher.ud[url].type == 'git': |
| 81 | if fetcher.ud[url].parm.get('destsuffix') is None: |
| 82 | s_dirname = os.path.basename(d.getVar('S')) |
| 83 | fetcher.ud[url].parm['destsuffix'] = os.path.join(s_dirname, 'src', d.getVar('GO_IMPORT')) + '/' |
| 84 | fetcher.unpack(d.getVar('WORKDIR')) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | go_list_packages() { |
| 88 | ${GO} list -f '{{.ImportPath}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \ |
| 89 | egrep -v '${GO_INSTALL_FILTEROUT}' |
| 90 | } |
| 91 | |
| 92 | go_list_package_tests() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 93 | ${GO} list -f '{{.ImportPath}} {{.TestGoFiles}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 94 | grep -v '\[\]$' | \ |
| 95 | egrep -v '${GO_INSTALL_FILTEROUT}' | \ |
| 96 | awk '{ print $1 }' |
| 97 | } |
| 98 | |
| 99 | go_do_configure() { |
| 100 | ln -snf ${S}/src ${B}/ |
| 101 | } |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 102 | do_configure[dirs] =+ "${GOTMPDIR}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 103 | |
| 104 | go_do_compile() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 105 | export TMPDIR="${GOTMPDIR}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 106 | if [ -n "${GO_INSTALL}" ]; then |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 107 | if [ -n "${GO_LINKSHARED}" ]; then |
| 108 | ${GO} install ${GOBUILDFLAGS} `go_list_packages` |
| 109 | rm -rf ${B}/bin |
| 110 | fi |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 111 | ${GO} install ${GO_LINKSHARED} ${GOBUILDFLAGS} `go_list_packages` |
| 112 | fi |
| 113 | } |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 114 | do_compile[dirs] =+ "${GOTMPDIR}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 115 | do_compile[cleandirs] = "${B}/bin ${B}/pkg" |
| 116 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 117 | go_do_install() { |
| 118 | install -d ${D}${libdir}/go/src/${GO_IMPORT} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 119 | tar -C ${S}/src/${GO_IMPORT} -cf - --exclude-vcs --exclude '*.test' --exclude 'testdata' . | \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 120 | tar -C ${D}${libdir}/go/src/${GO_IMPORT} --no-same-owner -xf - |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 121 | tar -C ${B} -cf - --exclude-vcs --exclude '*.test' --exclude 'testdata' pkg | \ |
| 122 | tar -C ${D}${libdir}/go --no-same-owner -xf - |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 123 | |
| 124 | if [ -n "`ls ${B}/${GO_BUILD_BINDIR}/`" ]; then |
| 125 | install -d ${D}${bindir} |
| 126 | install -m 0755 ${B}/${GO_BUILD_BINDIR}/* ${D}${bindir}/ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 127 | fi |
| 128 | } |
| 129 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 130 | go_stage_testdata() { |
| 131 | oldwd="$PWD" |
| 132 | cd ${S}/src |
| 133 | find ${GO_IMPORT} -depth -type d -name testdata | while read d; do |
| 134 | if echo "$d" | grep -q '/vendor/'; then |
| 135 | continue |
| 136 | fi |
| 137 | parent=`dirname $d` |
| 138 | install -d ${D}${PTEST_PATH}/$parent |
| 139 | cp --preserve=mode,timestamps -R $d ${D}${PTEST_PATH}/$parent/ |
| 140 | done |
| 141 | cd "$oldwd" |
| 142 | } |
| 143 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 144 | EXPORT_FUNCTIONS do_unpack do_configure do_compile do_install |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 145 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 146 | FILES:${PN}-dev = "${libdir}/go/src" |
| 147 | FILES:${PN}-staticdev = "${libdir}/go/pkg" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 148 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 149 | INSANE_SKIP:${PN} += "ldflags" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 150 | |
| 151 | # Add -buildmode=pie to GOBUILDFLAGS to satisfy "textrel" QA checking, but mips |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame] | 152 | # doesn't support -buildmode=pie, so skip the QA checking for mips/rv32 and its |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 153 | # variants. |
| 154 | python() { |
Andrew Geissler | 90fd73c | 2021-03-05 15:25:55 -0600 | [diff] [blame] | 155 | if 'mips' in d.getVar('TARGET_ARCH') or 'riscv32' in d.getVar('TARGET_ARCH'): |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 156 | d.appendVar('INSANE_SKIP:%s' % d.getVar('PN'), " textrel") |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 157 | else: |
| 158 | d.appendVar('GOBUILDFLAGS', ' -buildmode=pie') |
| 159 | } |