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