Optimize launcher preparation with precompiled, batched exporters

Compile and validate original exporter bundles during release builds, cache development compilation, and reuse initialized JVMs and collision data during preparation. Keep legacy preparers compatible while current releases need only a Java runtime.

Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
rdbtCVS
2026-10-25 23:11:23 +00:00
parent d58d26c793
commit f45e3f1237
20 changed files with 810 additions and 78 deletions
+21 -9
View File
@@ -1096,17 +1096,23 @@ fn download_for_owner(
}
}
/// The home of a JDK whose compiler and runtime support `major`. Forward even an installed
/// JDK to external preparers: older versions may otherwise rediscover incompatible PATH tools.
/// The Java home for this version: a runtime for precompiled exporters, a JDK for older
/// preparers or changed sources. Forward the selection to external preparers too.
/// Else try the official launcher's Java in `games`, then download the runtime named by
/// `manifest` into Horizon's game folder (Mojang's runtimes are whole JDKs).
fn java(
major: i64,
compiler: bool,
games: &[PathBuf],
manifest: &Path,
log: &dyn Fn(String),
) -> Result<PathBuf, String> {
if let Ok(jdk) = horizon_prepare::java::find(major, &[]) {
let find = if compiler {
horizon_prepare::java::find
} else {
horizon_prepare::java::find_runtime
};
if let Ok(jdk) = find(major, &[]) {
return Ok(jdk.home());
}
let mut runtimes: Vec<PathBuf> = Vec::new();
@@ -1118,7 +1124,7 @@ fn java(
runtimes.push(home);
}
}
let missing = match horizon_prepare::java::find(major, &runtimes) {
let missing = match find(major, &runtimes) {
Ok(jdk) => return Ok(jdk.home()),
Err(e) => e,
};
@@ -1129,7 +1135,7 @@ fn java(
// musl distributions) it cannot start, so don't download it.
if cfg!(all(target_os = "linux", target_arch = "x86_64")) && !Path::new(GLIBC_LOADER).exists() {
return Err(format!(
"{missing}\n • Minecraft's own Java from Mojang needs glibc ({GLIBC_LOADER} is missing; on NixOS, enable programs.nix-ld), so install a JDK instead."
"{missing}\n • Minecraft's own Java from Mojang needs glibc ({GLIBC_LOADER} is missing; on NixOS, enable programs.nix-ld), so install compatible Java instead."
));
}
let fetch = |url: &str| -> Result<Vec<u8>, String> {
@@ -1144,13 +1150,13 @@ fn java(
let home = mojang::java_runtime(&component, &runtime, 8, &fetch, log).map_err(|e| {
format!("{missing}\n • Horizon also tried to download Minecraft's own Java from Mojang, but: {e}")
})?;
horizon_prepare::java::find(major, &[home]).map(|jdk| jdk.home())
find(major, &[home]).map(|jdk| jdk.home())
}
/// The dynamic loader glibc programs on x86-64 Linux start through.
const GLIBC_LOADER: &str = "/lib64/ld-linux-x86-64.so.2";
/// Runs `cmd` with the JDK at `home`: JAVA_HOME names it and its `bin` leads the PATH, as the
/// Runs `cmd` with Java at `home`: JAVA_HOME names it and its `bin` leads the PATH, as the
/// versions' own preparers look for Java.
fn with_java(cmd: &mut Command, home: &Path) {
let mut path = vec![home.join("bin")];
@@ -1253,7 +1259,7 @@ pub fn preparer(
"This version prepares with Python: Python 3.10 or newer is needed. Install it, or pick a newer version.",
)?),
};
// The JDK the version pins, found as horizon-prepare finds it, so a missing one is
// The Java the version pins, found as horizon-prepare finds it, so a missing one is
// reported (or downloaded) before the server jar is downloaded. Versions from before
// java_major ran Java 25.
let major = read_json(&dir.join("research-lock.json"))
@@ -1267,7 +1273,13 @@ pub fn preparer(
.into_iter()
.map(|(_, dir)| dir),
);
let java_home = java(major, &games, &manifest, log)?;
let java_home = java(
major,
!horizon_prepare::exporters::available(&dir),
&games,
&manifest,
log,
)?;
let jar = data_dir()
.join("server-jars")
.join(format!("{version}.jar"));
+1 -1
View File
@@ -5,7 +5,7 @@ fn selected_jdk_reaches_external_preparers() {
const CHILD: &str = "HORIZON_LAUNCHER_JAVA_TEST";
if let Some(root) = std::env::var_os(CHILD) {
let root = PathBuf::from(root);
let home = java(25, &[], &root.join("missing.json"), &|_| {}).unwrap();
let home = java(25, true, &[], &root.join("missing.json"), &|_| {}).unwrap();
assert_eq!(
fs::canonicalize(&home).unwrap(),
fs::canonicalize(root.join("jdk25")).unwrap()
+2 -2
View File
@@ -103,8 +103,8 @@ fn java_platform() -> Option<&'static str> {
/// Downloads Mojang's Java runtime `component` (the version JSON's `javaVersion.component`, e.g.
/// `java-runtime-epsilon`) into the game directory's `runtime` folder, as the official launcher
/// lays it out: `<component>/<platform>/<component>/`. Each file is checked against its sha1;
/// files already there and whole are kept. Mojang's runtimes are whole JDKs, javac included,
/// which is what the exporters need.
/// files already there and whole are kept. These also include javac for older release preparers;
/// current releases can use an already installed runtime without it.
pub fn java_runtime(
component: &str,
runtime: &Path,