Merge pull request #1965 from rdbtCVS/t3/optimize-launcher-resource-prepare

🤖 Agent: Thanks rdbt, preparation needs only a Java runtime now and runs 5 JVMs instead of 18! Verified on the Mac mini:
This commit is contained in:
Ludovic Marie
2026-10-26 03:21:56 +01:00
committed by GitHub
21 changed files with 833 additions and 78 deletions
+21 -9
View File
@@ -1194,17 +1194,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();
@@ -1216,7 +1222,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,
};
@@ -1227,7 +1233,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> {
@@ -1242,13 +1248,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")];
@@ -1351,7 +1357,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"))
@@ -1365,7 +1371,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,
+4
View File
@@ -247,9 +247,12 @@ fn links_stay_inside_the_runtime() {
#[test]
fn java_runtime_lays_out_mojangs_runtime_with_its_executables_and_links() {
const JAVAC: &[u8] = b"#!/bin/sh\necho javac 25.0.1\n";
const JAVA: &[u8] = b"#!/bin/sh\necho java 25.0.1\n";
const LICENSE: &[u8] = b"a fake license";
let manifest = serde_json::json!({"files": {
"bin": {"type": "directory"},
"bin/java": {"type": "file", "executable": true, "downloads": {"raw":
{"sha1": sha1_hex(JAVA), "size": JAVA.len(), "url": "https://piston-data.mojang.com/java"}}},
"bin/javac": {"type": "file", "executable": true, "downloads": {"raw":
{"sha1": sha1_hex(JAVAC), "size": JAVAC.len(), "url": "https://piston-data.mojang.com/javac"}}},
"legal/java.base/LICENSE": {"type": "file", "executable": false, "downloads": {"raw":
@@ -269,6 +272,7 @@ fn java_runtime_lays_out_mojangs_runtime_with_its_executables_and_links() {
"https://piston-meta.mojang.com/m.json".into(),
manifest.into_bytes(),
),
("https://piston-data.mojang.com/java".into(), JAVA.to_vec()),
(
"https://piston-data.mojang.com/javac".into(),
JAVAC.to_vec(),