Unrolled build for #149964
Rollup merge of #149964 - Mark-Simulacrum:ci-channel, r=Kobzol

Write file with channel to S3

This will let rustup-toolchain-install-master gain support for installing stable artifacts, which is currently only possible when explicitly overriding the channel. That in turn will unblock letting Crater kick off a beta run as soon as both a new beta and a new stable artifact are ready, rather than waiting until the actual release.
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs
index adae9a1..c935859 100644
--- a/src/bootstrap/src/lib.rs
+++ b/src/bootstrap/src/lib.rs
@@ -1624,26 +1624,20 @@ fn rust_release(&self) -> String {
         self.release(&self.version)
     }
 
-    /// Returns the "package version" for a component given the `num` release
-    /// number.
+    /// Returns the "package version" for a component.
     ///
     /// The package version is typically what shows up in the names of tarballs.
-    /// For channels like beta/nightly it's just the channel name, otherwise
-    /// it's the `num` provided.
-    fn package_vers(&self, num: &str) -> String {
+    /// For channels like beta/nightly it's just the channel name, otherwise it's the release
+    /// version.
+    fn rust_package_vers(&self) -> String {
         match &self.config.channel[..] {
-            "stable" => num.to_string(),
+            "stable" => self.version.to_string(),
             "beta" => "beta".to_string(),
             "nightly" => "nightly".to_string(),
-            _ => format!("{num}-dev"),
+            _ => format!("{}-dev", self.version),
         }
     }
 
-    /// Returns the value of `package_vers` above for Rust itself.
-    fn rust_package_vers(&self) -> String {
-        self.package_vers(&self.version)
-    }
-
     /// Returns the `version` string associated with this compiler for Rust
     /// itself.
     ///
diff --git a/src/ci/scripts/upload-artifacts.sh b/src/ci/scripts/upload-artifacts.sh
index 975b4c5..6c916eb 100755
--- a/src/ci/scripts/upload-artifacts.sh
+++ b/src/ci/scripts/upload-artifacts.sh
@@ -6,6 +6,7 @@
 set -euo pipefail
 IFS=$'\n\t'
 
+ci_dir=`cd $(dirname $0)/.. && pwd`
 source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
 
 upload_dir="$(mktemp -d)"
@@ -22,6 +23,22 @@
     mv "${dist_dir}"/* "${upload_dir}"
 fi
 
+# We write the release channel into the output so that
+# `rustup-toolchain-install-master` or other, similar, tools can automatically
+# detect the appropriate name to use for downloading artifacts.
+#
+# For nightly and beta this isn't strictly necessary as just trying both is
+# enough, but stable builds produce artifacts with a version (e.g.,
+# rust-src-1.92.0.tar.xz) which can't be easily guessed otherwise.
+channel=$(releaseChannel)
+if [[ "$channel" = "stable" ]]; then
+    # On stable, artifacts use the version number. See rust_package_vers in
+    # src/bootstrap/src/lib.rs.
+    cat "$ci_dir/../version" > "${upload_dir}/package-version"
+else
+    echo "$channel" > "${upload_dir}/package-version"
+fi
+
 # CPU usage statistics.
 cp build/cpu-usage.csv "${upload_dir}/cpu-${CI_JOB_NAME}.csv"