gpt4 book ai didi

go - 如何在 yocto 配方中管理 golang 项目的外部依赖

转载 作者:数据小太阳 更新时间:2023-10-29 03:23:13 26 4
gpt4 key购买 nike

我想用 Yocto 2.4.1 为交叉编译的 golang 应用程序编写一个 yocto 配方,但我无法让外部依赖项工作。谁能帮帮我?

current RECIPE_FILE: hello-world_%.bb
LICENSE = "CLOSED"
LIC_FILES_CHKSUM = ""
DESCRIPTION = "Hello world test with golang."

inherit go

COMPATIBLE_MACHINE = "(<machine>)"
DEPENDS = "go-cross-${TARGET_ARCH}"
GO_IMPORT = "hello-world"
SRC_URI = "<git_url>/${GO_IMPORT}.git;branch=${SRCBRANCH};tag=${PV}"
SRCBRANCH = "master"
PV = "0.01"
S = "${WORKDIR}/git"

do_compile() {
export GOPATH="${WORKDIR}/build"
export GOARCH="<machine_arch>"
export GOOS="linux"
export CGO_ENABLED="0"
go build src/${GO_IMPORT}/hello-world.go
}

do_install() {
install -d "${D}/${bindir}"
install -m 0755 "${WORKDIR}/build/hello-world" "${D}/${bindir}/hello-world"
}

RDEPENDS_${PN}-dev += "bash"

此配方仅适用于内部依赖项。但是我如何集成外部依赖项,如“github.com/golang/protobuf/ptypes”?

PROJECT_FILE:hello-world.go

package main

import (
"fmt"
"github.com/golang/protobuf/ptypes"
)

func main() {
timestamp := ptypes.TimestampNow()
fmt.Println(timestamp)
}

有人知道这个用例的解决方案吗?

或者有人知道“go-dep”如何处理这个问题吗?

最好的问候

最佳答案

我使用 go dep 作为 deps,这是一个例子。最麻烦的是代理,这在配方中也已解决:

inherit go

LICENSE = "CLOSED"
LIC_FILES_CHKSUM = ""
DESCRIPTION = "Hello world test with golang."

COMPATIBLE_MACHINE = "(<machine>)"
DEPENDS += "go-dep-native"
GO_LINKSHARED = ""

GO_IMPORT = "<git_url>/hello-world.git"
SRC_URI = "<git_url>/${GO_IMPORT}.git;branch=${SRCBRANCH};tag=${PV}"
SRCBRANCH = "master"

do_compile() {
export SSH_AUTH_SOCK="${SSH_AUTH_SOCK}"
export HTTP_PROXY="${HTTP_PROXY}"
( cd ${WORKDIR}/build/src/${GO_IMPORT} && dep ensure -v )
}

do_compile[vardepsexclude] += "SSH_AUTH_SOCK HTTP_PROXY"

do_install() {
install -d "${D}/${bindir}"
install -m 0755 "${WORKDIR}/bin/<arch>/hello-world" "${D}/${bindir}/hello-world"
}

关于go - 如何在 yocto 配方中管理 golang 项目的外部依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49455065/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com