summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe/go.bbclass
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2025-11-07 13:31:53 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-11-07 13:31:53 +0000
commit8c22ff0d8b70d9b12f0487ef696a7e915b9e3173 (patch)
treeefdc32587159d0050a69009bdf2330a531727d95 /meta/classes-recipe/go.bbclass
parentd412d2747595c1cc4a5e3ca975e3adc31b2f7891 (diff)
downloadpoky-8c22ff0d8b70d9b12f0487ef696a7e915b9e3173.tar.gz
The poky repository master branch is no longer being updated.
You can either: a) switch to individual clones of bitbake, openembedded-core, meta-yocto and yocto-docs b) use the new bitbake-setup You can find information about either approach in our documentation: https://docs.yoctoproject.org/ Note that "poky" the distro setting is still available in meta-yocto as before and we continue to use and maintain that. Long live Poky! Some further information on the background of this change can be found in: https://lists.openembedded.org/g/openembedded-architecture/message/2179 Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-recipe/go.bbclass')
-rw-r--r--meta/classes-recipe/go.bbclass159
1 files changed, 0 insertions, 159 deletions
diff --git a/meta/classes-recipe/go.bbclass b/meta/classes-recipe/go.bbclass
deleted file mode 100644
index e0f667373e..0000000000
--- a/meta/classes-recipe/go.bbclass
+++ /dev/null
@@ -1,159 +0,0 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7inherit goarch
8inherit linuxloader
9
10# if the GO_IMPORT is not set in recipe generate an error
11GO_IMPORT ??= "${@bb.fatal("The recipe needs to set GO_IMPORT for go.bbclass to work")}"
12
13GO_PARALLEL_BUILD ?= "${@oe.utils.parallel_make_argument(d, '-p %d')}"
14
15export GODEBUG = "gocachehash=1"
16
17GOROOT:class-native = "${STAGING_LIBDIR_NATIVE}/go"
18GOROOT:class-nativesdk = "${STAGING_DIR_TARGET}${libdir}/go"
19GOROOT = "${STAGING_LIBDIR}/go"
20export GOROOT
21export GOCACHE = "${B}/.cache"
22
23export GOARCH = "${TARGET_GOARCH}"
24export GOOS = "${TARGET_GOOS}"
25export GOHOSTARCH = "${BUILD_GOARCH}"
26export GOHOSTOS = "${BUILD_GOOS}"
27
28GOARM[export] = "0"
29GOARM:arm:class-target = "${TARGET_GOARM}"
30GOARM:arm:class-target[export] = "1"
31
32GO386[export] = "0"
33GO386:x86:class-target = "${TARGET_GO386}"
34GO386:x86:class-target[export] = "1"
35
36GOMIPS[export] = "0"
37GOMIPS:mips:class-target = "${TARGET_GOMIPS}"
38GOMIPS:mips:class-target[export] = "1"
39
40DEPENDS_GOLANG:class-target = "virtual/${TUNE_PKGARCH}-go virtual/${TARGET_PREFIX}go-runtime"
41DEPENDS_GOLANG:class-native = "go-native"
42DEPENDS_GOLANG:class-nativesdk = "virtual/${TARGET_PREFIX}go virtual/${TARGET_PREFIX}go-runtime"
43
44DEPENDS:append = " ${DEPENDS_GOLANG}"
45
46GO_LINKSHARED ?= "${@'-linkshared' if d.getVar('GO_DYNLINK') else ''}"
47GO_RPATH_LINK = "${@'-Wl,-rpath-link=${STAGING_DIR_TARGET}${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}"
48GO_RPATH = "${@'-r ${libdir}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}"
49GO_RPATH:class-native = "${@'-r ${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}"
50GO_RPATH_LINK:class-native = "${@'-Wl,-rpath-link=${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}"
51GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS}"
52GO_LINKMODE ?= ""
53GO_EXTRA_LDFLAGS ?= ""
54GO_LINUXLOADER ?= "-I ${@get_linuxloader(d)}"
55# Use system loader. If uninative is used, the uninative loader will be patched automatically
56GO_LINUXLOADER:class-native = ""
57GO_LDFLAGS ?= '-ldflags="${GO_RPATH} ${GO_LINKMODE} ${GO_LINUXLOADER} ${GO_EXTRA_LDFLAGS} -extldflags '${GO_EXTLDFLAGS}'"'
58export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS} -trimpath"
59export GOPATH_OMIT_IN_ACTIONID ?= "1"
60export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c"
61export GOPTESTFLAGS ?= ""
62GOBUILDFLAGS:prepend:task-compile = "${GO_PARALLEL_BUILD} "
63
64export GO = "${HOST_PREFIX}go"
65GOTOOLDIR = "${STAGING_LIBDIR_NATIVE}/${TARGET_SYS}/go/pkg/tool/${BUILD_GOTUPLE}"
66GOTOOLDIR:class-native = "${STAGING_LIBDIR_NATIVE}/go/pkg/tool/${BUILD_GOTUPLE}"
67export GOTOOLDIR
68
69export CGO_ENABLED ?= "1"
70export CGO_CFLAGS ?= "${CFLAGS}"
71export CGO_CPPFLAGS ?= "${CPPFLAGS}"
72export CGO_CXXFLAGS ?= "${CXXFLAGS}"
73export CGO_LDFLAGS ?= "${LDFLAGS}"
74
75GO_INSTALL ?= "${GO_IMPORT}/..."
76GO_INSTALL_FILTEROUT ?= "${GO_IMPORT}/vendor/"
77
78B = "${WORKDIR}/build"
79export GOPATH = "${B}"
80export GOENV = "off"
81export GOPROXY ??= "https://proxy.golang.org,direct"
82export GOTMPDIR ?= "${WORKDIR}/build-tmp"
83GOTMPDIR[vardepvalue] = ""
84
85GO_SRCURI_DESTSUFFIX = "${@os.path.join(os.path.basename(d.getVar('S')), 'src', d.getVar('GO_IMPORT')) + '/'}"
86
87go_list_packages() {
88 ${GO} list -f '{{.ImportPath}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \
89 egrep -v '${GO_INSTALL_FILTEROUT}'
90}
91
92go_list_package_tests() {
93 ${GO} list -f '{{.ImportPath}} {{.TestGoFiles}}' ${GOBUILDFLAGS} ${GO_INSTALL} | \
94 grep -v '\[\]$' | \
95 egrep -v '${GO_INSTALL_FILTEROUT}' | \
96 awk '{ print $1 }'
97}
98
99go_do_configure() {
100 ln -snf ${S}/src ${B}/
101}
102do_configure[dirs] =+ "${GOTMPDIR}"
103
104go_do_compile() {
105 export TMPDIR="${GOTMPDIR}"
106 if [ -n "${GO_INSTALL}" ]; then
107 if [ -n "${GO_LINKSHARED}" ]; then
108 ${GO} install ${GOBUILDFLAGS} `go_list_packages`
109 rm -rf ${B}/bin
110 fi
111 ${GO} install ${GO_LINKSHARED} ${GOBUILDFLAGS} `go_list_packages`
112 fi
113}
114do_compile[dirs] =+ "${GOTMPDIR}"
115do_compile[cleandirs] = "${B}/bin ${B}/pkg"
116
117go_do_install() {
118 install -d ${D}${libdir}/go/src/${GO_IMPORT}
119 tar -C ${S}/src/${GO_IMPORT} -cf - --exclude-vcs --exclude '*.test' --exclude 'testdata' . | \
120 tar -C ${D}${libdir}/go/src/${GO_IMPORT} --no-same-owner -xf -
121 tar -C ${B} -cf - --exclude-vcs --exclude '*.test' --exclude 'testdata' pkg | \
122 tar -C ${D}${libdir}/go --no-same-owner -xf -
123
124 if ls ${B}/${GO_BUILD_BINDIR}/* >/dev/null 2>/dev/null ; then
125 install -d ${D}${bindir}
126 install -m 0755 ${B}/${GO_BUILD_BINDIR}/* ${D}${bindir}/
127 fi
128}
129
130go_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
144EXPORT_FUNCTIONS do_configure do_compile do_install
145
146FILES:${PN}-dev = "${libdir}/go/src"
147FILES:${PN}-staticdev = "${libdir}/go/pkg"
148
149INSANE_SKIP:${PN} += "ldflags"
150
151# Add -buildmode=pie to GOBUILDFLAGS to satisfy "textrel" QA checking, but mips
152# doesn't support -buildmode=pie, so skip the QA checking for mips/rv32 and its
153# variants.
154python() {
155 if 'mips' in d.getVar('TARGET_ARCH') or 'riscv32' in d.getVar('TARGET_ARCH'):
156 d.appendVar('INSANE_SKIP:%s' % d.getVar('PN'), " textrel")
157 else:
158 d.appendVar('GOBUILDFLAGS', ' -buildmode=pie')
159}