Skip to content

[gn] Ubuntu 22.04 / GCC 11 环境编译失败:std::ranges::unique 导致 rust_project_writer.cc 报错 #1971

Description

@sKyissKy

问题描述

在 Ubuntu 22.04 LTS 环境下编译 helloworld feed 时,gn host package 编译失败。

问题出现在:

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)

Activity

  1. zxlhhyccc commented on May 22, 2026

    @zxlhhyccc
    Collaborator

    @sKyissKy 建议将补丁改为gcc>11和<=11的予以兼容,即:>11使用std::ranges::unique,否则使用std::unique,是否可行?如下格式:

    --- a/src/gn/rust_project_writer.cc
    +++ b/src/gn/rust_project_writer.cc
    @@ -218,8 +218,14 @@ 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());
    +
    +#if defined(__GNUC__) && (__GNUC__ > 11)
    +  include_dirs.erase(std::ranges::unique(include_dirs).begin(),
    +                     include_dirs.end());
    +#else
    +  include_dirs.erase(std::unique(include_dirs.begin(), include_dirs.end()),
    +                     include_dirs.end());
    +#endif
    
       Crate crate = Crate(crate_root, include_dirs, crate_id, crate_label,
                           edition.value_or("2015"));
    
  2. sKyissKy commented on May 22, 2026

    @sKyissKy
    ContributorAuthor

    010-gn-fix-gcc11-ranges-unique.patch 我修改了一下 这样能判断 并且也能过编译

  3. zxlhhyccc commented on May 22, 2026

    @zxlhhyccc
    Collaborator

    @sKyissKy 我发的不行吗?

  4. sKyissKy commented on May 27, 2026

    @sKyissKy
    ContributorAuthor

    @sKyissKy 我发的不行吗?

    没试....只能说我发的补丁我能过编译

  5. sKyissKy commented on Jun 2, 2026

    @sKyissKy
    ContributorAuthor

    @sKyissKy 我发的不行吗?

    刚试了一下 宿主机 gcc 12 也照样编译过不了

  6. zxlhhyccc commented on Jun 2, 2026

    @zxlhhyccc
    Collaborator

    @sKyissKy 改成小于13试试。

  7. sKyissKy commented on Jun 11, 2026

    @sKyissKy
    ContributorAuthor

    另外就是节点模式选择 不管是订阅节点 还是服务端选择 都是有 shadowsocks 命名重复的问题,要考虑修复,既然编译时是二选一,相应的luci代码要跟上啊,不然每次都要去改配置文件.....

  8. sKyissKy commented on Jun 11, 2026

    @sKyissKy
    ContributorAuthor

    还有就是这个clash mihomo订阅的问题,经常出现修改以后 MD5编码一致不更新节点的问题,也不知道怎么清空这个保留的md5编码,节点规则都已经删除重建了

  9. zxlhhyccc commented on Jun 13, 2026

    @zxlhhyccc
    Collaborator

    @sKyissKy 我暂时不知道怎么用clash mihomo订阅,一直显示没有启用主节点导致面板打不开,能教我使用吗?等我会玩我再修改。

  10. sKyissKy commented on Jun 29, 2026

    @sKyissKy
    ContributorAuthor

    @sKyissKy 我发的不行吗?

    灯神,gn更新太勤快了,又要打补丁了,不然又搞不定ubuntu 22.04 LTS 编译。

    有两个方案 一个是打两个补丁 :

    010-gn-fix-old-libstdcxx-ranges-unique.patch
    020-clang-host-compat.patch

    另外就是改makefile 和更新补丁

    010-gn-fix-old-libstdcxx-ranges-unique.patch

    Makefile.txt

  11. sKyissKy commented on Jul 29, 2026

    @sKyissKy
    ContributorAuthor

    @sKyissKy 我暂时不知道怎么用clash mihomo订阅,一直显示没有启用主节点导致面板打不开,能教我使用吗?等我会玩我再修改。

    要彻底清除ss-rust了吗?最新版已经没法正常使用了,只能用 mihomo,但是mihomo稳定性实在太差了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions