Skip to content

修复 cargo 换源的一些问题#288

Merged
ccmywish merged 3 commits into
RubyMetric:devfrom
happy-game:main
Sep 19, 2025
Merged

修复 cargo 换源的一些问题#288
ccmywish merged 3 commits into
RubyMetric:devfrom
happy-game:main

Conversation

@happy-game

Copy link
Copy Markdown
Collaborator

问题描述

  1. cargo现在无法自动换源 rust 换源提示有误 #281
  2. cargo getsrc 只是显示配置文件完整内容,不太合适,应该要考虑一些边界情况 pip在wsl上查看当前源失败 #272 增强目前 recipe 的getsrc #287

方案与实现

由于 uv 和 cargo 的 mirror 都是存在 toml 配置文件当中且有相似的结构,因此参考 uv 换源实现 Cargo 换源,具体如下:

  1. 在没有该配置文件或者配置文件当中没有配置mirror时 append 到最后
  2. 在存在 mirror时进行替换

对于 getsrc, 做了如下考虑:

  1. 如果存在配置文件,则过滤出 mirror
  2. 如果不存在配置文件或配置文件未定义 source.mirror 则显示默认源

@github-actions

Copy link
Copy Markdown

Hi @happy-game,

❤️ 感谢你的贡献!你的 PR 当前基于 main 分支,请修改使用 dev 分支

@happy-game happy-game changed the base branch from main to dev September 13, 2025 03:10

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个文件没有看到对应的 rawstr4c.md 变化,是不是漏 git add 进来了?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, 我漏了没有更新这一部分, 今天晚点我更新后再上传一次

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分更新了,同时我注意到这次提交里我又犯了之前 pip 的错误,也一并更正了

happy-game and others added 2 commits September 13, 2025 21:24
参考 uv 换源实现

Co-Authored-By: Claude <noreply@anthropic.com>
1. 如果存在配置文件,则过滤出 mirror
2. 如果不存在配置文件或配置文件未定义 source.mirror 则显示默认源
Comment thread src/recipe/lang/Rust/Cargo.c Outdated

if (0 == status)
{
#if defined(XY_Build_On_macOS) || defined(XY_Build_On_BSD)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里还是用动态的变量 xy.on_macos 等检测吧,

考虑到可能会有跨平台编译(比如,现在安卓的chsrc是在Windows上编译的),所以专门把这几个宏从原来的 XY_On_macOS 改成了 XY_Build_On_macOS,强调是在编译时判断。

Comment thread src/recipe/lang/Rust/Cargo.c Outdated
// 尝试提取 [source.mirror] 下的 registry URL
char *grep_cmd = xy_str_gsub ("grep -A1 '\\[source\\.mirror\\]' '@f@' | grep 'registry' | cut -d'\"' -f2", "@f@", cargo_config_file);
chsrc_ensure_program ("grep");
chsrc_ensure_program ("cut");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows 上似乎没有 cut,能不能换一个方法?

虽然 Windows 默认也没有 grep,但是比起 grep,用户可能更没有 cut.

Comment thread src/recipe/lang/Rust/Cargo.c Outdated
chef_set_chef (this, NULL);
chef_set_cooks (this, 1, "@ccmywish");
chef_set_sauciers (this, 1, "@Mikachu2333");
chef_set_sauciers (this, 2, "@Mikachu2333", "@happy-game");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • cooks 就是看这个文件主要是谁写的,谁改动的。
  • sauciers 是小变化,小改动。

这个文件你的改动很大,你直接写在我前面吧。

@ccmywish ccmywish added the pl_target pl target label Sep 19, 2025
@ccmywish ccmywish added this to the v0.2.3 milestone Sep 19, 2025
@ccmywish ccmywish merged commit d424ed2 into RubyMetric:dev Sep 19, 2025
This was referenced Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pl_target pl target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants