使用sudo构建Ubuntu镜像时遇scoped_threads编译错误求助
可行构建方案
方案1:让sudo继承rustup的环境变量
sudo默认不会加载用户的shell配置,因此无法识别rustup安装的nightly版本。可以通过两种方式解决:
- 临时指定PATH执行构建:
sudo env PATH=$PATH make image PROFILE=kstr-sama5d27 - 永久配置sudo保留PATH:用
visudo命令安全编辑/etc/sudoers,找到Defaults env_reset行,修改为:
保存后重新登录,sudo即可识别rustup的nightly环境,之后直接运行原构建命令即可。Defaults env_reset, env_keep += "PATH HOME"
方案2:降级cargo-deb适配稳定版Rust
cargo-deb 1.41.3依赖的scoped_threads是Rust 1.63才稳定的特性,而你系统apt安装的rustc是1.61.0,可通过降级cargo-deb版本解决:
- 进入gpt-manipulator子模块目录:
cd ubuntu-build/gpt-manipulator - 编辑
Cargo.toml,将cargo-deb的版本从1.41.3改为1.39.0(该版本不依赖scoped_threads,兼容1.61.0):cargo-deb = "1.39.0" - 返回主目录重新执行构建:
cd .. sudo make image PROFILE=kstr-sama5d27
方案3:预编译子模块再执行整体构建
既然单独编译gpt-manipulator无问题,可以先手动编译子模块,再让make跳过该模块的编译步骤:
- 单独编译gpt-manipulator:
cd ubuntu-build/gpt-manipulator cargo build --release - 将编译好的二进制文件复制到make预期的路径(可查看makefile中指定的gpt-manipulator输出位置,一般为
target/release/gpt-manipulator):cp target/release/gpt-manipulator ../path/to/expected/location - 执行make命令并跳过gpt-manipulator编译(若makefile支持跳过参数,比如
SKIP_GPT_BUILD,或直接修改makefile注释掉该模块的编译逻辑):cd .. sudo make image PROFILE=kstr-sama5d27 SKIP_GPT_BUILD=1
内容的提问来源于stack exchange,提问作者davegravy
相关产品推荐
相关产品推荐

