openEuler欧拉系统编译InfluxDB2.0.6(Go、rust编译)

环境准备

go安装

前往官网下载1.19版本的安装包,运行命令:

tar -C /usr/local -zxf go1.19.tar.gz
export PATH=$PATH:/usr/local/go/bin
go开启代理
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn

rust安装

通过查看flux@0.113.0源码的Dockerfile_build文件,可知使用的是1.51.0的Rust。一般来说,Rust编译器会有向后兼容性,但涉及到一些重大语法或规则更新时会出现编译不通过的情况。此处如果使用了最新版的Rust,会出现后文中Q7的问题。

执行命令:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh  -s -- --default-toolchain "1.51.0" -y
export PATH="$HOME/.cargo/bin:${PATH}"
rustc --version
cargo开启代理

通过命令vi ~/.cargo/config.toml写入以下内容:

[source.crates-io]
replace-with = 'tuna'

[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"

[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

[source.rustcc]
registry = "git://crates.rustcc.cn/crates.io-index"

[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"

安装编译工具

GCC安装

执行命令:

yum -y install gcc gcc-c++
influxdata pkg-config安装

安装influxdata的pkg-config:

go install github.com/influxdata/pkg-config@latest
# 查看安装结果
ll ~/go/bin

编译源码

github下载v2.0.6版本的influxdb源码:influxdb-2.0.6.tar.gz
cd进项目根目录influxdb-2.0.6,运行:

PKG_CONFIG=~/go/bin/pkg-config CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -o test -v cmd/influxd/main.go

编译完成后,运行测试:

./test --help

Q&A

Q1. 编译报错提示undefined: libflux.ASTPkg

github.com/influxdata/flux/parser
# github.com/influxdata/flux/parser
/home/ecx/go/pkg/mod/github.com/influxdata/flux@v0.113.0/parser/parser.go:88:30: undefined: libflux.ASTPkg
/home/ecx/go/pkg/mod/github.com/influxdata/flux@v0.113.0/parser/parser.go:92:42: undefined: libflux.ASTPkg
/home/ecx/go/pkg/mod/github.com/influxdata/flux@v0.113.0/parser/parser.go:93:17: undefined: libflux.ParseString
/home/ecx/go/pkg/mod/github.com/influxdata/flux@v0.113.0/parser/libflux_parser.go:10:21: undefined: libflux.Parse

A1. 打开CGO_ENABLED开关:

CGO_ENABLED=1

Q2. 编译报错提示No package 'flux' found

github.com/influxdata/flux/libflux/go/libflux
# pkg-config --cflags  -- flux
Package flux was not found in the pkg-config search path.
Perhaps you should add the directory containing `flux.pc'
to the PKG_CONFIG_PATH environment variable
No package 'flux' found
pkg-config: exit status 1

A2. 查看flux文档GO论坛,安装influxdata的pkg-config:

go install github.com/influxdata/pkg-config@latest
ll ~/go/bin

Q3. 提示"gcc": executable file not found in $PATH

cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH

A3. 安装gcc:

yum -y install gcc gcc-c++

Q4. 提示gcc: error: unrecognized command line option '-m64'

runtime/cgo
# runtime/cgo
gcc: error: unrecognized command line option '-m64'
Error installing library        {"name": "flux", "error": "exec: \"cargo\": executable file not found in $PATH"}

A4. 使用arm64架构:

GOARCH=arm64

Q5. 提示\"cargo\": executable file not found in $PATH"

Error installing library        {"name": "flux", "error": "exec: \"cargo\": executable file not found in $PATH"}

A5. 安装rust:

# 1.51.0版,推荐
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain "1.51.0" -y
# 最新版,会遇到问题Q7
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Q6. 提示Failed to connect to static.crates.io

Caused by:
  [7] Couldn't connect to server (Failed to connect to static.crates.io port 443 after 0 ms: Couldn't connect to server)
Error installing library        {"name": "flux", "error": "exit status 101"}

A6. 更改cargo镜像地址,参考上文cargo开启代理部分内容


Q7. 编译flux-core报错:

error: variable does not need to be mutable
  --> flux-core/src/ast/flatbuffers/mod.rs:79:13
   |
79 |         let mut v = &mut *self.inner.borrow_mut();
   |             ----^
   |             |
   |             help: remove this `mut`
   |
note: the lint level is defined here
  --> flux-core/src/lib.rs:1:38
   |
1  | #![cfg_attr(feature = "strict", deny(warnings, missing_docs))]
   |                                      ^^^^^^^^
   = note: `#[deny(unused_mut)]` implied by `#[deny(warnings)]`

error: field `message` is never read
  --> flux-core/src/parser/mod.rs:35:9
   |
34 | struct TokenError {
   |        ---------- field in this struct
35 |     pub message: String,
   |         ^^^^^^^
   |
   = note: `#[deny(dead_code)]` implied by `#[deny(warnings)]`

error: could not compile `flux-core` (lib) due to 2 previous errors

A7. 原因是rust新版无法编译flux@0.113.0,新编译器语法检查不兼容旧代码。rust切换到1.51.0版本:

# 若已安装其他版本的rust,执行以下三步:
rustup install 1.51.0
rustup toolchain list
rustup default 1.51.0-x86_64-unknown-linux-gnu
# 若以上三步提示网络错误或未安装rust则执行:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh  -s -- --default-toolchain "1.51.0" -y
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值