はじめに
Yocto Project 4.1(Langdale)からSDK_TOOLCHAIN_LANGSが追加され、
標準SDKにRustやGoのツールチェーンを含むことができるようになった。
執筆時点ではGoについては少し?問題があるので紹介する。
標準SDKへのGoの追加
作成手順
local.confに以下の内容を追加する。
SDK_TOOLCHAIN_LANGS = "go"
標準SDKをビルドする。
$ bitbake core-image-minimal -c populate_sdk
問題点
go-cross-canadianのエラー
MACHINEがqemuarm64などの場合に以下以下のようなビルドエラーが発生する。
ERROR: go-cross-canadian-aarch64-1.22.8-r0 do_install: ExecutionError('/home/mickey/yocto/scarthgap/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.22.8/temp/run.do_install.1151458', 1, None, None)
ERROR: Logfile of failure stored in: /home/mickey/yocto/scarthgap/build/tmp/work/x86_64-nativesdk-pokysdk-linux/go-cross-canadian-aarch64/1.22.8/temp/log.do_install.1151458
... (snip) ...
ERROR: Task (/home/mickey/yocto/scarthgap/poky/meta/recipes-devtools/go/go-cross-canadian_1.22.8.bb:do_install) failed with exit code '1'
go-cross-canadianのdo_installタスクでエラーになっている。
原因
GO_BUILD_BINDIRが期待しているディレクトリ構成と、実際のディレクトリ構成が食い違うため発生する問題らしい。
do_install() { install -d ${D}${libdir}/go/pkg/tool cp --preserve=mode,timestamps -R ${B}/pkg/tool/${HOST_GOTUPLE} ${D}${libdir}/go/pkg/tool/ install -d ${D}${bindir} ${D}${libdir}/go/bin for f in ${B}/${GO_BUILD_BINDIR}/* do base=`basename $f` install -m755 $f ${D}${libdir}/go/bin make_wrapper $base ${TARGET_PREFIX}$base done }
この問題はYocto Project 5.2(Walnascar)まで修正されていない。
修正コミット
下記のコミットで修正されている。
commit a669cd2e0c760da9d7e872daea9590fc9e86d766
Author: Osama Abdelkader <osama.abdelkader@gmail.com>
Date: Tue Aug 12 22:50:50 2025 +0200
go-cross-canadian: fix binaries install and GOARCH
set GOARCH to HOST_GOARCH which is set from SDKMACHINE,
since GOARCH defaults to TARGET_GOARCH, which is set from MACHINE (wrong arch).
Also fix do_install to correctly install all binaries from
${GO_BUILD_BINDIR} by using 'find -type f' to avoid issues when the
directory contains subdirectories (e.g. "linux_arm").
(From OE-Core rev: 31e3bd61c7986bc044e547aa5cb9caba7b32bf22)
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
修正内容は以下のようになっている。
diff --git a/meta/recipes-devtools/go/go-cross-canadian.inc b/meta/recipes-devtools/go/go-cross-canadian.inc index 39330fc98b..4a6f2f4c36 100644 --- a/meta/recipes-devtools/go/go-cross-canadian.inc +++ b/meta/recipes-devtools/go/go-cross-canadian.inc @@ -5,6 +5,8 @@ DEPENDS = "go-native virtual/${HOST_PREFIX}go virtual/nativesdk-${HOST_PREFIX}go virtual/nativesdk-compilerlibs" PN = "go-cross-canadian-${TRANSLATED_TARGET_ARCH}" +GOARCH = "${HOST_GOARCH}" + # it uses gcc on build machine during go-cross-canadian bootstrap, but # the gcc version may be old and not support option '-fmacro-prefix-map' # which is one of default values of DEBUG_PREFIX_MAP @@ -51,7 +53,7 @@ do_install() { install -d ${D}${libdir}/go/pkg/tool cp --preserve=mode,timestamps -R ${B}/pkg/tool/${HOST_GOTUPLE} ${D}${libdir}/go/pkg/tool/ install -d ${D}${bindir} ${D}${libdir}/go/bin - for f in ${B}/${GO_BUILD_BINDIR}/* + for f in $(find ${B}/${GO_BUILD_BINDIR} -type f) do base=`basename $f` install -m755 $f ${D}${libdir}/go/bin
この修正によりビルドエラーは回避できるようになった。
動作確認
ビルドされた標準SDKをインストールしたあと下記を実行してみると、ホストPCのコマンドが見つかる。
$ source /opt/poky/5.2.99+snapshot/environment-setup-cortexa57-poky-linux $ which go /snap/bin/go
SDK内でgoコマンドを検索してみると見つかりはする。どうやらパスに含まれていない場所に配置されているようだ。
$ find $OECORE_NATIVE_SYSROOT -name go /opt/poky/5.2.99+snapshot/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/go /opt/poky/5.2.99+snapshot/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/go/bin/go
フルパス指定で実行してみる。
$ /opt/poky/5.2.99+snapshot/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/go/bin/go -h | head
Go is a tool for managing Go source code.
Usage:
go <command> [arguments]
... (snip) ...
コマンドは実行可能なようなので試しにサンプルをビルドしてみる。以下の内容でhello.goを作成する。
package main import "fmt" func main() { fmt.Println("hello world") }
ビルドする。
$ export PATH=$OECORE_NATIVE_SYSROOT/usr/lib/aarch64-poky-linux/go/bin/go:$PATH $ go build hello.go hello.go:3:8: package fmt is not in std (/opt/poky/5.2.99+snapshot/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/go/src/fmt) package command-line-arguments: cannot find package
GOROOTに標準的なライブラリが見つからないらしい。
$ go env GOROOT /opt/poky/5.2.99+snapshot/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/go $ ls /opt/poky/5.2.99+snapshot/sysroots/x86_64-pokysdk-linux/usr/lib/aarch64-poky-linux/go bin pkg
ほぼ何もない。
まとめ
執筆時点(2025/10/29)でリリース済みのYocto Projectではx86系以外のプラットフォームの標準SDKでGoのツールチェーンを含めようとするとビルドエラーになる。 masterブランチには修正がすでに取り込まれているので次回リリース予定の5.3(Whinlatter)では反映されている可能性が高い。
ただし、標準SDKのsysrootにはgoのバイナリしか入らず、実行に必要な以下の処理が実施されないため実質何もできない。
- goコマンドのPATHへの追加
- GOOSやGOARCHなどのクロスコンパイルに必要な設定
- GOROOTへのsrcなど必要なファイルのインストール