前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >The Things Network LoRaWAN Stack V3 学习笔记 1.2 源码编译 - 190821

The Things Network LoRaWAN Stack V3 学习笔记 1.2 源码编译 - 190821

作者头像
twowinter
发布2020-04-17 11:31:18
1.1K0
发布2020-04-17 11:31:18
举报
文章被收录于专栏:twowinter

前言

源码编译是重头戏,这节笔记记录如何使用 make 命令编译相关部件。

此前已经分享了一篇相同笔记,但由于时间又过去了半年,部分命令已做了调整,遂更新一篇。

小能手这段时间在学习 The Things Network LoRaWAN Stack V3,从使用和代码等角度对该 Stack 进行了分析,详细可点此查看

1 依赖包替换

TTN Stack V3 采用了 go moudles 来进行包依赖管理。我们可以看到工程目录下,存在着一个 go.mod,记录了整个工程的依赖包。

我们使用 go mod download 命令,来下载依赖包。

代码语言:javascript
复制
ubuntu@VM-0-6-ubuntu:~/lorawan-stack$ go mod download
go: finding github.com/kamilsk/retry/v4 v4.0.0
go: cloud.google.com/go@v0.36.0: unrecognized import path "cloud.google.com/go" (https fetch: Get https://cloud.google.com/go?go-get=1: dial tcp 172.217.163.238:443: i/o timeout)
go: cloud.google.com/go@v0.34.0: unrecognized import path "cloud.google.com/go" (https fetch: Get https://cloud.google.com/go?go-get=1: dial tcp 172.217.163.238:443: i/o timeout)
go: golang.org/x/sys@v0.0.0-20190209173611-3b5209105503: unrecognized import path "golang.org/x/sys" (https fetch: Get https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/sys@v0.0.0-20180909124046-d0be0721c37e: unrecognized import path "golang.org/x/sys" (https fetch: Get https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/sys@v0.0.0-20181011152604-fa43e7bc11ba: unrecognized import path "golang.org/x/sys" (https fetch: Get https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: google.golang.org/genproto@v0.0.0-20190201180003-4b09977fb922: unrecognized import path "google.golang.org/genproto" (https fetch: Get https://google.golang.org/genproto?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: google.golang.org/genproto@v0.0.0-20181016170114-94acd270e44e: unrecognized import path "google.golang.org/genproto" (https fetch: Get https://google.golang.org/genproto?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/sync@v0.0.0-20180314180146-1d60e4601c6f: unrecognized import path "golang.org/x/sync" (https fetch: Get https://golang.org/x/sync?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/sys@v0.0.0-20181030150119-7e31e0c00fa0: unrecognized import path "golang.org/x/sys" (https fetch: Get https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/net@v0.0.0-20181023162649-9b4f9f5ad519: unrecognized import path "golang.org/x/net" (https fetch: Get https://golang.org/x/net?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/net@v0.0.0-20190206173232-65e2d4e15006: unrecognized import path "golang.org/x/net" (https fetch: Get https://golang.org/x/net?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/tools@v0.0.0-20190211224914-44bee7e801e4: unrecognized import path "golang.org/x/tools" (https fetch: Get https://golang.org/x/tools?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: finding gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
go: golang.org/x/text@v0.3.0: unrecognized import path "golang.org/x/text" (https fetch: Get https://golang.org/x/text?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/sync@v0.0.0-20181108010431-42b317875d0f: unrecognized import path "golang.org/x/sync" (https fetch: Get https://golang.org/x/sync?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/sys@v0.0.0-20180905080454-ebe1bf3edb33: unrecognized import path "golang.org/x/sys" (https fetch: Get https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: google.golang.org/appengine@v1.2.0: unrecognized import path "google.golang.org/appengine" (https fetch: Get https://google.golang.org/appengine?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/oauth2@v0.0.0-20190211225200-5f6b76b7c9dd: unrecognized import path "golang.org/x/oauth2" (https fetch: Get https://golang.org/x/oauth2?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/oauth2@v0.0.0-20181017192945-9dcd33a902f4: unrecognized import path "golang.org/x/oauth2" (https fetch: Get https://golang.org/x/oauth2?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: finding github.com/konsorten/go-windows-terminal-sequences v0.0.0-20180402223658-b729f2633dfe
go: golang.org/x/image@v0.0.0-20190209060608-ef4a1470e0dc: unrecognized import path "golang.org/x/image" (https fetch: Get https://golang.org/x/image?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/net@v0.0.0-20180906233101-161cd47e91fd: unrecognized import path "golang.org/x/net" (https fetch: Get https://golang.org/x/net?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/net@v0.0.0-20181017193950-04a2e542c03f: unrecognized import path "golang.org/x/net" (https fetch: Get https://golang.org/x/net?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/crypto@v0.0.0-20180904163835-0709b304e793: unrecognized import path "golang.org/x/crypto" (https fetch: Get https://golang.org/x/crypto?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/crypto@v0.0.0-20190211182817-74369b46fc67: unrecognized import path "golang.org/x/crypto" (https fetch: Get https://golang.org/x/crypto?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/crypto@v0.0.0-20181015023909-0c41d7ab0a0e: unrecognized import path "golang.org/x/crypto" (https fetch: Get https://golang.org/x/crypto?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: google.golang.org/grpc@v1.15.0: unrecognized import path "google.golang.org/grpc" (https fetch: Get https://google.golang.org/grpc?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: google.golang.org/grpc@v1.18.0: unrecognized import path "google.golang.org/grpc" (https fetch: Get https://google.golang.org/grpc?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: golang.org/x/time@v0.0.0-20180412165947-fbb02b2291d2: unrecognized import path "golang.org/x/time" (https fetch: Get https://golang.org/x/time?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: google.golang.org/api@v0.0.0-20181017004218-3f6e8463aa1d: unrecognized import path "google.golang.org/api" (https fetch: Get https://google.golang.org/api?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
go: error loading module requirements
代码语言:javascript
复制
# Enable the go modules feature
export GO111MODULE=on
# Set the GOPROXY environment variable
export GOPROXY=https://goproxy.io

设置了 go 代理之后,所有包就很顺畅地下载下来了。

2 编译准备

代码语言:javascript
复制
ubuntu@VM-0-6-ubuntu:~/lorawan-stack$ make init
make[1]: Entering directory '/home/ubuntu/lorawan-stack'
GO111MODULE=on go run github.com/magefile/mage -compile .mage/run
lorawan-stack  Installing git hook: pre-commit
lorawan-stack  Installing git hook: pre-push
lorawan-stack  Installing git hook: commit-msg
lorawan-stack  Initializing go
make[2]: Entering directory '/home/ubuntu/lorawan-stack'
lorawan-stack  Installing go dependencies
make[2]: Leaving directory '/home/ubuntu/lorawan-stack'
lorawan-stack  Initializing js
make[2]: Entering directory '/home/ubuntu/lorawan-stack'
lorawan-stack  Installing js dev dependencies
+ yarn@1.12.3
added 1 package and audited 1 package in 3.241s
found 0 vulnerabilities

make[2]: Leaving directory '/home/ubuntu/lorawan-stack'
make[2]: Entering directory '/home/ubuntu/lorawan-stack'
lorawan-stack  Installing js dev dependencies
lorawan-stack  Fetching JS SDK dependencies
yarn install v1.12.3
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.4: The platform "linux" is incompatible with this module.
info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
warning Your current version of Yarn is out of date. The latest version is "1.13.0", while you're on "1.12.3".
info To upgrade, run the following command:
$ curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
Done in 24.55s.
make[2]: Leaving directory '/home/ubuntu/lorawan-stack'
make[2]: Entering directory '/home/ubuntu/lorawan-stack'
lorawan-stack  Building JS SDK files
yarn run v1.12.3
$ babel src -d dist --no-emoji --no-progress --quiet
Done in 2.68s.
make[2]: Leaving directory '/home/ubuntu/lorawan-stack'
make[2]: Entering directory '/home/ubuntu/lorawan-stack'
lorawan-stack  Installing js dev dependencies
lorawan-stack  Installing js dependencies
yarn install v1.12.3
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.4: The platform "linux" is incompatible with this module.
info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 77.69s.
make[2]: Leaving directory '/home/ubuntu/lorawan-stack'
lorawan-stack  Generating certificates
2019/03/11 16:47:50 wrote cert.pem
2019/03/11 16:47:50 wrote key.pem
make[1]: Leaving directory '/home/ubuntu/lorawan-stack'

3 编译

For development/testing purposes we suggest either running required binaries via go run (e.g. go run ./cmd/ttn-lw-cli from repository root for CLI), or using go build directly. Note, that the frontend (if used) needs to be built via ./mage js:build before go build or go run commands are run.

这块命令现在官方做了比较大的精简,目前已经不用再去运行一些依赖命令,直接可以 build。

3.1 cli 编译

这个命令行工具是和 Stack 的各组件进行交互的必要工具。

代码语言:javascript
复制
go build ./cmd/ttn-lw-cli/

3.2 stack 编译

代码语言:javascript
复制
go build ./cmd/ttn-lw-stack/

小能手使用一个弱爆了虚机进行编译,竟然出错,因此下一篇还额外分享了一个交叉编译的方式,即在 MAC 上为 Linux 编译程序。就当是体验 GO 的一大特色。

3.3 前端编译

代码语言:javascript
复制
./mage js:build

详细的可以见 2.7 编译运行 Web 前端

END

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • 1 依赖包替换
  • 2 编译准备
  • 3 编译
    • 3.1 cli 编译
      • 3.2 stack 编译
        • 3.3 前端编译
        • END
        相关产品与服务
        命令行工具
        腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档