Support rustup

[GitHub #87]
This commit is contained in:
Aoran Zeng 2024-10-02 20:11:04 +08:00
parent c2273b8c42
commit 9fd619e7ca
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98

View File

@ -15,9 +15,10 @@ pl_rust_rustup_sources[] = {
{&Upstream, NULL},
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/rustup"},
{&Ustc, "https://mirrors.ustc.edu.cn/rust-static"},
{&Sjtug, "https://mirror.sjtu.edu.cn/rust-static"},
{&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/rust-static"},
{&Zju, "https://mirrors.zju.edu.cn/rustup"},
{&Iscas, "https://mirror.iscas.ac.cn/rustup"}
{&Iscas, "https://mirror.iscas.ac.cn/rustup"},
{&RsProxyCN, "https://rsproxy.cn"}
};
def_sources_n(pl_rust_rustup);
@ -28,6 +29,10 @@ def_sources_n(pl_rust_rustup);
void
pl_rust_rustup_getsrc (char *option)
{
char *cmd = "echo RUSTUP_UPDATE_ROOT;"
"echo RUSTUP_DIST_SERVER;";
system (cmd);
}
@ -39,9 +44,43 @@ pl_rust_rustup_getsrc (char *option)
void
pl_rust_rustup_setsrc (char *option)
{
char *setsrc_type = xy_streql (option, SetsrcType_Reset) ? SetsrcType_Reset : SetsrcType_Auto;
chsrc_yield_source_and_confirm (pl_rust_rustup);
char *dist_server = xy_strjoin (3, "export RUSTUP_DIST_SERVER=\"", source.url, "\"");
char *update_root = xy_strjoin (3, "export RUSTUP_UPDATE_ROOT=\"", source.url, "/rustup\"");
char *bashrc = "~/.bashrc";
if (xy_file_exist (bashrc))
{
chsrc_backup (bashrc);
chsrc_append_to_file (dist_server, bashrc);
chsrc_append_to_file (update_root, bashrc);
}
char *zshrc = "~/.zshrc";
if (xy_file_exist (zshrc))
{
chsrc_backup (zshrc);
chsrc_append_to_file (dist_server, zshrc);
chsrc_append_to_file (update_root, zshrc);
}
char *fishrc = "~/.config/fish/config.fish";
if (xy_file_exist (fishrc))
{
char *dist_server = xy_2strjoin ("set -x RUSTUP_DIST_SERVER ", source.url);
char *update_root = xy_2strjoin ("set -x RUSTUP_UPDATE_ROOT ", xy_2strjoin (source.url, "/rustup"));
chsrc_backup (fishrc);
chsrc_append_to_file (dist_server, fishrc);
chsrc_append_to_file (update_root, fishrc);
}
chsrc_conclude (&source, setsrc_type);
chsrc_note2 ("请您重启终端使rustup环境变量生效");
}
@ -51,7 +90,7 @@ pl_rust_rustup_setsrc (char *option)
void
pl_rust_rustup_resetsrc (char *option)
{
// pl_rust_rustup_setsrc (SetsrcType_Reset);
pl_rust_rustup_setsrc (SetsrcType_Reset);
}
@ -66,12 +105,12 @@ pl_rust_rustup_feat (char *option)
fi.can_get = true;
fi.can_reset = false;
fi.stcan_locally = CanSemi;
fi.locally = "具体说明是否支持项目级换源...";
fi.stcan_locally = CanNot;
fi.locally = "";
fi.can_english = false;
fi.can_user_define = false;
fi.can_user_define = true;
fi.note = "备注说明...";
fi.note = NULL;
return fi;
}