blob: e18339cddb0c5602a826922676e25dca2e8ace7b [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001DEPENDS = "virtual/${TUNE_PKGARCH}-go go-native"
Patrick Williams213cb262021-08-07 19:21:33 -05002DEPENDS:class-nativesdk = "virtual/${TARGET_PREFIX}go-crosssdk"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05003PROVIDES = "virtual/${TARGET_PREFIX}go-runtime"
4
Andrew Geissler595f6302022-01-24 19:11:47 +00005DEBUG_PREFIX_MAP = "\
6 -fdebug-prefix-map=${STAGING_DIR_HOST}= \
7 -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \
8"
9
Brad Bishop316dfdd2018-06-25 12:45:53 -040010export CGO_CFLAGS = "${CFLAGS}"
11export CGO_CPPFLAGS = "${CPPFLAGS}"
12export CGO_CXXFLAGS = "${CXXFLAGS}"
Andrew Geissler595f6302022-01-24 19:11:47 +000013# Filter out -fdebug-prefix-map options as they clash with the GO's build system
14export CGO_LDFLAGS = "${@ ' '.join(filter(lambda f: not f.startswith('-fdebug-prefix-map'), d.getVar('LDFLAGS').split())) }"
Brad Bishopc8f47122019-06-24 09:36:18 -040015export GOCACHE = "${B}/.cache"
Brad Bishop316dfdd2018-06-25 12:45:53 -040016
17GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${LDFLAGS}"
18GO_SHLIB_LDFLAGS ?= '-ldflags="--linkmode=external -extldflags '${GO_EXTLDFLAGS}'"'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050019
20do_configure() {
21 :
22}
23
Patrick Williams213cb262021-08-07 19:21:33 -050024do_configure:libc-musl() {
Brad Bishopd7bf8c12018-02-25 22:55:05 -050025 rm -f ${S}/src/runtime/race/*.syso
26}
27
28do_compile() {
Andrew Geissler82c905d2020-04-13 13:39:40 -050029 export CC_FOR_${TARGET_GOTUPLE}="${CC}"
30 export CXX_FOR_${TARGET_GOTUPLE}="${CXX}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040031
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032 cd src
Brad Bishop316dfdd2018-06-25 12:45:53 -040033 ./make.bash --target-only --no-banner std
Brad Bishopd7bf8c12018-02-25 22:55:05 -050034 if [ -n "${GO_DYNLINK}" ]; then
Brad Bishop316dfdd2018-06-25 12:45:53 -040035 export GOTOOLDIR="${B}/pkg/tool/native_native"
Andrew Geissler82c905d2020-04-13 13:39:40 -050036 CC="$CC_FOR_${TARGET_GOTUPLE}" GOARCH="${TARGET_GOARCH}" GOOS="${TARGET_GOOS}" GOROOT=${B} \
Brad Bishop316dfdd2018-06-25 12:45:53 -040037 $GOTOOLDIR/go_bootstrap install -linkshared -buildmode=shared ${GO_SHLIB_LDFLAGS} std
Brad Bishopd7bf8c12018-02-25 22:55:05 -050038 fi
39 cd ${B}
40}
Brad Bishop316dfdd2018-06-25 12:45:53 -040041do_compile[cleandirs] += "${GOTMPDIR} ${B}/bin ${B}/pkg"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050042
43do_install() {
44 install -d ${D}${libdir}/go/src
45 cp --preserve=mode,timestamps -R ${B}/pkg ${D}${libdir}/go/
46 if [ "${BUILD_GOTUPLE}" != "${TARGET_GOTUPLE}" ]; then
47 rm -rf ${D}${libdir}/go/pkg/${BUILD_GOTUPLE}
48 rm -rf ${D}${libdir}/go/pkg/obj/${BUILD_GOTUPLE}
49 fi
50 rm -rf ${D}${libdir}/go/pkg/tool
51 rm -rf ${D}${libdir}/go/pkg/obj
52 rm -rf ${D}${libdir}/go/pkg/bootstrap
53 find src -mindepth 1 -maxdepth 1 -type d | while read srcdir; do
54 cp --preserve=mode,timestamps -R $srcdir ${D}${libdir}/go/src/
55 done
Brad Bishop316dfdd2018-06-25 12:45:53 -040056 find ${D}${libdir}/go/src -depth -type d -name testdata -exec rm -rf {} \;
Brad Bishopd7bf8c12018-02-25 22:55:05 -050057 rm -f ${D}${libdir}/go/src/cmd/dist/dist
Brad Bishop08902b02019-08-20 09:16:51 -040058 rm -f ${D}${libdir}/go/src/cmd/cgo/zdefaultcc.go
59 rm -f ${D}${libdir}/go/src/cmd/go/internal/cfg/zdefaultcc.go
60
Brad Bishopd7bf8c12018-02-25 22:55:05 -050061}
62
Patrick Williams213cb262021-08-07 19:21:33 -050063ALLOW_EMPTY:${PN} = "1"
64FILES:${PN} = "${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*${SOLIBSDEV}"
65FILES:${PN}-dev = "${libdir}/go/src ${libdir}/go/pkg/include \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050066 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*.shlibname \
67 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*.shlibname \
68 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*.shlibname \
69 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*.shlibname \
70 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*/*.shlibname \
71 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*/*/*.shlibname \
72 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*/*/*/*.shlibname \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050073 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*.a \
74 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*.a \
75 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*.a \
76 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*.a \
77 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*/*.a \
78 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*/*/*.a \
79 ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink/*/*/*/*/*/*/*.a \
80"
Patrick Williams213cb262021-08-07 19:21:33 -050081FILES:${PN}-staticdev = "${libdir}/go/pkg/${TARGET_GOTUPLE}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040082
83# Go sources include some scripts and pre-built binaries for
84# multiple architectures. The static .a files for dynamically-linked
85# runtime are also required in -dev.
Patrick Williams213cb262021-08-07 19:21:33 -050086INSANE_SKIP:${PN}-dev = "staticdev file-rdeps arch"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050087
88INHIBIT_PACKAGE_STRIP = "1"
89INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
Brad Bishop316dfdd2018-06-25 12:45:53 -040090INHIBIT_SYSROOT_STRIP = "1"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050091
92BBCLASSEXTEND = "nativesdk"