Skip to content

Commit 9fd619e

Browse files
committed
Support rustup
[GitHub #87]
1 parent c2273b8 commit 9fd619e

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

src/recipe/lang/Rust/rustup.c

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ pl_rust_rustup_sources[] = {
1515
{&Upstream, NULL},
1616
{&Tuna, "https://mirrors.tuna.tsinghua.edu.cn/rustup"},
1717
{&Ustc, "https://mirrors.ustc.edu.cn/rust-static"},
18-
{&Sjtug, "https://mirror.sjtu.edu.cn/rust-static"},
18+
{&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/rust-static"},
1919
{&Zju, "https://mirrors.zju.edu.cn/rustup"},
20-
{&Iscas, "https://mirror.iscas.ac.cn/rustup"}
20+
{&Iscas, "https://mirror.iscas.ac.cn/rustup"},
21+
{&RsProxyCN, "https://rsproxy.cn"}
2122
};
2223
def_sources_n(pl_rust_rustup);
2324

@@ -28,6 +29,10 @@ def_sources_n(pl_rust_rustup);
2829
void
2930
pl_rust_rustup_getsrc (char *option)
3031
{
32+
char *cmd = "echo RUSTUP_UPDATE_ROOT;"
33+
"echo RUSTUP_DIST_SERVER;";
34+
35+
system (cmd);
3136
}
3237

3338

@@ -39,9 +44,43 @@ pl_rust_rustup_getsrc (char *option)
3944
void
4045
pl_rust_rustup_setsrc (char *option)
4146
{
47+
char *setsrc_type = xy_streql (option, SetsrcType_Reset) ? SetsrcType_Reset : SetsrcType_Auto;
48+
4249
chsrc_yield_source_and_confirm (pl_rust_rustup);
4350

51+
char *dist_server = xy_strjoin (3, "export RUSTUP_DIST_SERVER=\"", source.url, "\"");
52+
char *update_root = xy_strjoin (3, "export RUSTUP_UPDATE_ROOT=\"", source.url, "/rustup\"");
53+
54+
char *bashrc = "~/.bashrc";
55+
if (xy_file_exist (bashrc))
56+
{
57+
chsrc_backup (bashrc);
58+
chsrc_append_to_file (dist_server, bashrc);
59+
chsrc_append_to_file (update_root, bashrc);
60+
}
61+
62+
char *zshrc = "~/.zshrc";
63+
if (xy_file_exist (zshrc))
64+
{
65+
chsrc_backup (zshrc);
66+
chsrc_append_to_file (dist_server, zshrc);
67+
chsrc_append_to_file (update_root, zshrc);
68+
}
69+
70+
char *fishrc = "~/.config/fish/config.fish";
71+
if (xy_file_exist (fishrc))
72+
{
73+
char *dist_server = xy_2strjoin ("set -x RUSTUP_DIST_SERVER ", source.url);
74+
char *update_root = xy_2strjoin ("set -x RUSTUP_UPDATE_ROOT ", xy_2strjoin (source.url, "/rustup"));
75+
76+
chsrc_backup (fishrc);
77+
chsrc_append_to_file (dist_server, fishrc);
78+
chsrc_append_to_file (update_root, fishrc);
79+
}
80+
81+
4482
chsrc_conclude (&source, setsrc_type);
83+
chsrc_note2 ("请您重启终端使rustup环境变量生效");
4584
}
4685

4786

@@ -51,7 +90,7 @@ pl_rust_rustup_setsrc (char *option)
5190
void
5291
pl_rust_rustup_resetsrc (char *option)
5392
{
54-
// pl_rust_rustup_setsrc (SetsrcType_Reset);
93+
pl_rust_rustup_setsrc (SetsrcType_Reset);
5594
}
5695

5796

@@ -66,12 +105,12 @@ pl_rust_rustup_feat (char *option)
66105
fi.can_get = true;
67106
fi.can_reset = false;
68107

69-
fi.stcan_locally = CanSemi;
70-
fi.locally = "具体说明是否支持项目级换源...";
108+
fi.stcan_locally = CanNot;
109+
fi.locally = "";
71110
fi.can_english = false;
72-
fi.can_user_define = false;
111+
fi.can_user_define = true;
73112

74-
fi.note = "备注说明...";
113+
fi.note = NULL;
75114
return fi;
76115
}
77116

0 commit comments

Comments
 (0)