Skip to content

feat(cargo): Use the CARGO_HOME environment variable to locate the co…#348

Open
AnonTokio wants to merge 2 commits intoRubyMetric:devfrom
AnonTokio:dev
Open

feat(cargo): Use the CARGO_HOME environment variable to locate the co…#348
AnonTokio wants to merge 2 commits intoRubyMetric:devfrom
AnonTokio:dev

Conversation

@AnonTokio
Copy link

问题描述

  1. 当前 cargo 换源写入时,固定写入 ~/.cargo/config.toml,没有查看环境变量 CARGO_HOME。若用户修改了 CARGO_HOME,那么 cargo 的配置文件会在 $CARGO_HOME/config.toml
  2. N/A

方案与实现

先检查是否设置了 CARGO_HOME 环境变量,若存在,则使用 $CARGO_HOME/config.toml 作为配置文件地址,否则使用 ~/.cargo/config.toml


@Mikachu2333 @ccmywish

@github-actions
Copy link

Hi @AnonTokio

❤️ 感谢你的贡献!我们将在最少半小时,最多5天内阅读此 PR 并回复你

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Rust/Cargo recipe to respect the CARGO_HOME environment variable when locating Cargo’s config file, aligning behavior with Cargo’s documented config location precedence.

Changes:

  • Added a helper to compute the Cargo config file path using CARGO_HOME when set, otherwise falling back to ~/.cargo/config.toml.
  • Updated pl_rust_cargo_getsrc and pl_rust_cargo_setsrc to use the new helper and free the returned path.

Copy link
Collaborator

@Mikachu2333 Mikachu2333 left a comment

Choose a reason for hiding this comment

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

看起来挺好的,我没意见

@ccmywish
Copy link
Contributor

ccmywish commented Mar 21, 2026

@AnonTokio 👍👍👍

最后需要在:

  1. https://github.com/RubyMetric/chsrc/blob/main/src/chsrc-main.c#L80 记录你的信息
  2. 将信息再填入 Cargo.c 文件里的: chef_set_sauciers (this, 2, "@happy-game", "@你的信息");
  3. 更新一下 Cargo.c 文件的时间信息: chef_set_recipe_last_updated (this, "今天");

通过运行 chsrc ls cargo 验证上述修改

Copy link
Contributor

@ccmywish ccmywish left a comment

Choose a reason for hiding this comment

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

pl_rust_cargo_config_file() 这个函数可以提一个公用的函数出来给 xy.h:

xy_path_join(): 函数名 @flavor Ruby: Pathname#join

@AnonTokio
Copy link
Author

@ccmywish 好的,我修改一下,以及 xy_path_join 也放在这个 pr 里提还是单独再提一个 pr?因为功能和这个 pr 不太相关。

@ccmywish
Copy link
Contributor

xy_path_join 也放在这个 pr 里提还是单独再提一个 pr

我不介意作为同一个 PR,因为这两个已经确定都要被合并,并且另一个PR的修改将会触及这个PR。

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants