Rollforward of https://github.com/bazelbuild/bazel/commit/37eb1d79ecb019220073b62321f9eb88aebaa4e4: Attach Java runtime to Java toolchains

Defining a new rule "java_runtime_version_alias", which uses a custom configuration flag transition to select a specific version of...

NEW: ...

Automated rollback of commit ddfc932380c8147c70bb3faf1bc999f0cc3652f2.

*** Reason for rollback ***

Rollforward

*** Original change description ***

Automated rollback of commit 37eb1d79ecb019220073b62321f9eb88aebaa4e4.

*** Reason for rollback ***

Breaks multiple downstream projects, see https://buildkite.com/bazel/bazel-auto-sheriff-face-with-cowboy-hat/builds/364#c671c11c-f885-4527-829f-057b0e29d29c

PiperOrigin-RevId: 347364659
diff --git a/scripts/bootstrap/BUILD.bootstrap b/scripts/bootstrap/BUILD.bootstrap
new file mode 100644
index 0000000..b5991f6
--- /dev/null
+++ b/scripts/bootstrap/BUILD.bootstrap
@@ -0,0 +1,23 @@
+load("@bazel_tools//tools/jdk:default_java_toolchain.bzl", "default_java_toolchain")
+
+# This toolchain is used to bootstrap Bazel.
+default_java_toolchain(
+    name = "bootstrap_toolchain",
+    bootclasspath = ["@bazel_tools//tools/jdk:platformclasspath.jar"],
+    genclass = ["//src/java_tools/buildjar:bootstrap_genclass_deploy.jar"],
+    ijar = ["//third_party/ijar"],
+    java_runtime = "@local_jdk//:jdk",
+    javabuilder = ["//src/java_tools/buildjar:bootstrap_VanillaJavaBuilder_deploy.jar"],
+    jvm_opts = [
+        # Prevent "Could not reserve enough space for object heap" errors on Windows.
+        "-Xmx512m",
+        # Using tiered compilation improves performance of Javac when not using the worker mode.
+        "-XX:+TieredCompilation",
+        "-XX:TieredStopAtLevel=1",
+    ],
+    singlejar = ["//src/java_tools/singlejar:bootstrap_deploy.jar"],
+    source_version = "8",
+    tags = ["manual"],
+    target_version = "8",
+    visibility = ["//visibility:public"],
+)
diff --git a/scripts/bootstrap/bootstrap.sh b/scripts/bootstrap/bootstrap.sh
index a42c861..597379b 100755
--- a/scripts/bootstrap/bootstrap.sh
+++ b/scripts/bootstrap/bootstrap.sh
@@ -36,12 +36,15 @@
       --strategy=Javac=worker --worker_quit_after_build --ignore_unsupported_sandboxing \
       --compilation_mode=opt \
       --distdir=derived/distdir \
-      --java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \
-      --host_java_toolchain=//src/java_tools/buildjar:bootstrap_toolchain \
-      --extra_toolchains=//src/java_tools/buildjar:bootstrap_toolchain_definition \
+      --java_toolchain=//scripts/bootstrap:bootstrap_toolchain \
+      --host_java_toolchain=//scripts/bootstrap:bootstrap_toolchain \
+      --incompatible_use_toolchain_resolution_for_java_rules \
+      --extra_toolchains=//scripts/bootstrap:bootstrap_toolchain_definition \
       ${DIST_BOOTSTRAP_ARGS:-} \
       ${EXTRA_BAZEL_ARGS:-}"
 
+cp scripts/bootstrap/BUILD.bootstrap scripts/bootstrap/BUILD
+
 if [ -z "${BAZEL-}" ]; then
   function _run_bootstrapping_bazel() {
     local command=$1