1 //! rustbuild, the Rust build system
3 //! This is the entry point for the build system used to compile the `rustc`
4 //! compiler. Lots of documentation can be found in the `README.md` file in the
5 //! parent directory, and otherwise documentation can be found throughout the `build`
6 //! directory in each respective module.
10 use bootstrap::{Build, Config, Subcommand, VERSION};
13 let args = env::args().skip(1).collect::<Vec<_>>();
14 let config = Config::parse(&args);
16 // check_version warnings are not printed during setup
17 let changelog_suggestion =
18 if matches!(config.cmd, Subcommand::Setup { .. }) { None } else { check_version(&config) };
20 // NOTE: Since `./configure` generates a `config.toml`, distro maintainers will see the
21 // changelog warning, not the `x.py setup` message.
22 let suggest_setup = !config.config.exists() && !matches!(config.cmd, Subcommand::Setup { .. });
24 println!("warning: you have not made a `config.toml`");
26 "help: consider running `./x.py setup` or copying `config.toml.example` by running \
27 `cp config.toml.example config.toml`"
29 } else if let Some(suggestion) = &changelog_suggestion {
30 println!("{}", suggestion);
33 let pre_commit = config.src.join(".git").join("hooks").join("pre-commit");
34 Build::new(config).build();
37 println!("warning: you have not made a `config.toml`");
39 "help: consider running `./x.py setup` or copying `config.toml.example` by running \
40 `cp config.toml.example config.toml`"
42 } else if let Some(suggestion) = &changelog_suggestion {
43 println!("{}", suggestion);
46 // Give a warning if the pre-commit script is in pre-commit and not pre-push.
47 // HACK: Since the commit script uses hard links, we can't actually tell if it was installed by x.py setup or not.
48 // We could see if it's identical to src/etc/pre-push.sh, but pre-push may have been modified in the meantime.
49 // Instead, look for this comment, which is almost certainly not in any custom hook.
50 if std::fs::read_to_string(pre_commit).map_or(false, |contents| {
51 contents.contains("https://github.com/rust-lang/rust/issues/77620#issuecomment-705144570")
54 "warning: You have the pre-push script installed to .git/hooks/pre-commit. \
55 Consider moving it to .git/hooks/pre-push instead, which runs less often."
59 if suggest_setup || changelog_suggestion.is_some() {
60 println!("note: this message was printed twice to make it more likely to be seen");
64 fn check_version(config: &Config) -> Option<String> {
65 let mut msg = String::new();
67 let suggestion = if let Some(seen) = config.changelog_seen {
69 msg.push_str("warning: there have been changes to x.py since you last updated.\n");
70 format!("update `config.toml` to use `changelog-seen = {}` instead", VERSION)
75 msg.push_str("warning: x.py has made several changes recently you may want to look at\n");
76 format!("add `changelog-seen = {}` at the top of `config.toml`", VERSION)
79 msg.push_str("help: consider looking at the changes in `src/bootstrap/CHANGELOG.md`\n");
80 msg.push_str("note: to silence this warning, ");
81 msg.push_str(&suggestion);