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



我想用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"
}

我相信只有两种类型的依赖项
1. 主机依赖(在 YOCTO 中应用编译时的依赖关系(
在约克托食谱(.bb文件(中保持DEPENDS = "some lib"

  1. 目标依赖项(应用在板上运行时的依赖项(
    您的瑜伽食谱RDEPENDS = "some lib"

hello.bb

DESCRIPTION =  
LIC =  
SRC_URI =  
DEPENDS ="sqlite3"   
inherit autools
您可以使用

SRC_URI添加外部 go 依赖项:

SRC_URI = "
           <git_url>/${GO_IMPORT}.git;branch=${SRCBRANCH};tag=${PV} 
           git://github.com/golang/protobuf/ptypes;protocol=https;name=ptype;destsuffix=${PN}-${PV}/src/github.com/golang/protobuf/ptypes 
"
SRCREV_ptype = "v0.1.0" <-- whatever revision you need (branch, tag, sha)

最新更新