src/gn/rust_project_writer.cc
其中使用了:
include_dirs.erase(std::ranges::unique(include_dirs).begin(),
include_dirs.end());
Ubuntu 22.04 默认使用 GCC 11 / libstdc++ 11,该环境下编译此处会触发 std::ranges::unique / std::ranges::subrange 相关模板约束错误,最终导致:
ERROR: package/feeds/helloworld/gn [host] failed to build.
编译环境
系统:Ubuntu 22.04 LTS
编译对象:package/feeds/helloworld/gn [host]
工具链相关:GCC 11 / libstdc++ 11
关键报错
FAILED: src/gn/rust_project_writer.o
../src/gn/rust_project_writer.cc:221:41: note: in instantiation of function template specialization
'std::ranges::__unique_fn::operator()<std::vector &, std::identity, std::ranges::equal_to>' requested here
include_dirs.erase(std::ranges::unique(include_dirs).begin(),
^
error: constraints not satisfied for alias template 'sentinel_t'
修复方式
将 std::ranges::unique 修改为传统的 std::unique 写法后,可以兼容 Ubuntu 22.04 / GCC 11 环境:
--- a/src/gn/rust_project_writer.cc
+++ b/src/gn/rust_project_writer.cc
@@ -218,8 +218,8 @@ RustProjectWriter::Crate RustProjectWrit
std::ranges::sort(include_dirs, [](const auto& lhs, const auto& rhs) {
return lhs.value() < rhs.value();
});
- include_dirs.erase(std::ranges::unique(include_dirs).begin(),
- include_dirs.end());
+ include_dirs.erase(std::unique(include_dirs.begin(), include_dirs.end()),
+ include_dirs.end());
Crate crate = Crate(crate_root, include_dirs, crate_id, crate_label,
edition.value_or("2015"));
建议
建议在 gn package 中加入该兼容性补丁,以支持 Ubuntu 22.04 LTS 默认 GCC 11 / libstdc++ 11 的构建环境。
补丁文件可命名为:
010-gn-fix-gcc11-ranges-unique.patch
我可以提交该 patch 供合并,如需完整编译日志也可以继续补充。
[010-gn-fix-gcc11-ranges-unique.patch](https://github.com/user-attachments/files/28126301/010-gn-fix-gcc11-ranges-unique.patch)
问题描述
在 Ubuntu 22.04 LTS 环境下编译 helloworld feed 时,
gnhost package 编译失败。问题出现在: