blob: e40e55689ddb11a2cbd656e449f10ae2da710774 [file] [log] [blame]
Brad Bishop96ff1982019-08-19 13:50:42 -04001inherit goarch
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002
Brad Bishop316dfdd2018-06-25 12:45:53 -04003GO_PARALLEL_BUILD ?= "${@oe.utils.parallel_make_argument(d, '-p %d')}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -05004
5GOROOT_class-native = "${STAGING_LIBDIR_NATIVE}/go"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006GOROOT_class-nativesdk = "${STAGING_DIR_TARGET}${libdir}/go"
7GOROOT = "${STAGING_LIBDIR}/go"
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008export GOROOT
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009export GOROOT_FINAL = "${libdir}/go"
Brad Bishopc8f47122019-06-24 09:36:18 -040010export GOCACHE = "${B}/.cache"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011
Brad Bishopd89cb5f2019-04-10 09:02:41 -040012export GOARCH = "${TARGET_GOARCH}"
13export GOOS = "${TARGET_GOOS}"
14export GOHOSTARCH="${BUILD_GOARCH}"
15export GOHOSTOS="${BUILD_GOOS}"
16
17GOARM[export] = "0"
18GOARM_arm_class-target = "${TARGET_GOARM}"
19GOARM_arm_class-target[export] = "1"
20
21GO386[export] = "0"
22GO386_x86_class-target = "${TARGET_GO386}"
23GO386_x86_class-target[export] = "1"
Brad Bishopd89cb5f2019-04-10 09:02:41 -040024
25GOMIPS[export] = "0"
26GOMIPS_mips_class-target = "${TARGET_GOMIPS}"
27GOMIPS_mips_class-target[export] = "1"
28
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080029DEPENDS_GOLANG_class-target = "virtual/${TUNE_PKGARCH}-go virtual/${TARGET_PREFIX}go-runtime"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050030DEPENDS_GOLANG_class-native = "go-native"
31DEPENDS_GOLANG_class-nativesdk = "virtual/${TARGET_PREFIX}go-crosssdk virtual/${TARGET_PREFIX}go-runtime"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032
Brad Bishopd7bf8c12018-02-25 22:55:05 -050033DEPENDS_append = " ${DEPENDS_GOLANG}"
34
35GO_LINKSHARED ?= "${@'-linkshared' if d.getVar('GO_DYNLINK') else ''}"
36GO_RPATH_LINK = "${@'-Wl,-rpath-link=${STAGING_DIR_TARGET}${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}"
37GO_RPATH = "${@'-r ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}"
38GO_RPATH_class-native = "${@'-r ${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}"
39GO_RPATH_LINK_class-native = "${@'-Wl,-rpath-link=${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}"
40GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS}"
41GO_LINKMODE ?= ""
42GO_LINKMODE_class-nativesdk = "--linkmode=external"
43GO_LDFLAGS ?= '-ldflags="${GO_RPATH} ${GO_LINKMODE} -extldflags '${GO_EXTLDFLAGS}'"'
44export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040045export GOPATH_OMIT_IN_ACTIONID ?= "1"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050046export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c"
Brad Bishop316dfdd2018-06-25 12:45:53 -040047export GOPTESTFLAGS ?= ""
Brad Bishopd7bf8c12018-02-25 22:55:05 -050048GOBUILDFLAGS_prepend_task-compile = "${GO_PARALLEL_BUILD} "
49
50export GO = "${HOST_PREFIX}go"
51GOTOOLDIR = "${STAGING_LIBDIR_NATIVE}/${TARGET_SYS}/go/pkg/tool/${BUILD_GOTUPLE}"
52GOTOOLDIR_class-native = "${STAGING_LIBDIR_NATIVE}/go/pkg/tool/${BUILD_GOTUPLE}"
53export GOTOOLDIR
54
Brad Bishopd7bf8c12018-02-25 22:55:05 -050055export CGO_ENABLED ?= "1"
56export CGO_CFLAGS ?= "${CFLAGS}"
57export CGO_CPPFLAGS ?= "${CPPFLAGS}"
58export CGO_CXXFLAGS ?= "${CXXFLAGS}"
59export CGO_LDFLAGS ?= "${LDFLAGS}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050060
61GO_INSTALL ?= "${GO_IMPORT}/..."
Brad Bishopd7bf8c12018-02-25 22:55:05 -050062GO_INSTALL_FILTEROUT ?= "${GO_IMPORT}/vendor/"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050063
Brad Bishopd7bf8c12018-02-25 22:55:05 -050064B = "${WORKDIR}/build"
65export GOPATH = "${B}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040066export GOTMPDIR ?= "${WORKDIR}/go-tmp"
67GOTMPDIR[vardepvalue] = ""
Brad Bishopd7bf8c12018-02-25 22:55:05 -050068
69python go_do_unpack() {
70 src_uri = (d.getVar('SRC_URI') or "").split()
71 if len(src_uri) == 0:
72 return
73
Brad Bishop08902b02019-08-20 09:16:51 -040074 fetcher = bb.fetch2.Fetch(src_uri, d)
75 for url in fetcher.urls:
76 if fetcher.ud[url].type == 'git':
77 if fetcher.ud[url].parm.get('destsuffix') is None:
78 s_dirname = os.path.basename(d.getVar('S'))
79 fetcher.ud[url].parm['destsuffix'] = os.path.join(s_dirname, 'src', d.getVar('GO_IMPORT')) + '/'
80 fetcher.unpack(d.getVar('WORKDIR'))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050081}
82
83go_list_packages() {
84 ${GO} list -f '{{.ImportPath}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \
85 egrep -v '${GO_INSTALL_FILTEROUT}'
86}
87
88go_list_package_tests() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040089 ${GO} list -f '{{.ImportPath}} {{.TestGoFiles}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050090 grep -v '\[\]$' | \
91 egrep -v '${GO_INSTALL_FILTEROUT}' | \
92 awk '{ print $1 }'
93}
94
95go_do_configure() {
96 ln -snf ${S}/src ${B}/
97}
Brad Bishop316dfdd2018-06-25 12:45:53 -040098do_configure[dirs] =+ "${GOTMPDIR}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050099
100go_do_compile() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400101 export TMPDIR="${GOTMPDIR}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500102 if [ -n "${GO_INSTALL}" ]; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400103 if [ -n "${GO_LINKSHARED}" ]; then
104 ${GO} install ${GOBUILDFLAGS} `go_list_packages`
105 rm -rf ${B}/bin
106 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500107 ${GO} install ${GO_LINKSHARED} ${GOBUILDFLAGS} `go_list_packages`
108 fi
109}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400110do_compile[dirs] =+ "${GOTMPDIR}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500111do_compile[cleandirs] = "${B}/bin ${B}/pkg"
112
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500113go_do_install() {
114 install -d ${D}${libdir}/go/src/${GO_IMPORT}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400115 tar -C ${S}/src/${GO_IMPORT} -cf - --exclude-vcs --exclude '*.test' --exclude 'testdata' . | \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500116 tar -C ${D}${libdir}/go/src/${GO_IMPORT} --no-same-owner -xf -
Brad Bishopc342db32019-05-15 21:57:59 -0400117 tar -C ${B} -cf - --exclude-vcs pkg | tar -C ${D}${libdir}/go --no-same-owner -xf -
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500118
119 if [ -n "`ls ${B}/${GO_BUILD_BINDIR}/`" ]; then
120 install -d ${D}${bindir}
121 install -m 0755 ${B}/${GO_BUILD_BINDIR}/* ${D}${bindir}/
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500122 fi
123}
124
Brad Bishop316dfdd2018-06-25 12:45:53 -0400125go_stage_testdata() {
126 oldwd="$PWD"
127 cd ${S}/src
128 find ${GO_IMPORT} -depth -type d -name testdata | while read d; do
129 if echo "$d" | grep -q '/vendor/'; then
130 continue
131 fi
132 parent=`dirname $d`
133 install -d ${D}${PTEST_PATH}/$parent
134 cp --preserve=mode,timestamps -R $d ${D}${PTEST_PATH}/$parent/
135 done
136 cd "$oldwd"
137}
138
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500139EXPORT_FUNCTIONS do_unpack do_configure do_compile do_install
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500140
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500141FILES_${PN}-dev = "${libdir}/go/src"
142FILES_${PN}-staticdev = "${libdir}/go/pkg"
143
144INSANE_SKIP_${PN} += "ldflags"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800145
146# Add -buildmode=pie to GOBUILDFLAGS to satisfy "textrel" QA checking, but mips
147# doesn't support -buildmode=pie, so skip the QA checking for mips and its
148# variants.
149python() {
150 if 'mips' in d.getVar('TARGET_ARCH'):
151 d.appendVar('INSANE_SKIP_%s' % d.getVar('PN'), " textrel")
152 else:
153 d.appendVar('GOBUILDFLAGS', ' -buildmode=pie')
154}