From e1fff77a484a57e4d34947215768660a1f2dcb7b Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 24 Oct 2026 00:38:13 +0200 Subject: [PATCH] Prepare: Netty's native transports are optional, as in the game Prism Launcher never downloads io.netty:netty-transport-native-kqueue (or the epoll one on Linux), so preparing from a Prism install stopped on a jar the game runs without: vanilla's EventLoopGroupHolder.remote takes KQueue/Epoll only when isAvailable(), else Netty NIO. Preparing now imports a native transport when the launcher has it (checked against the version JSON's sha1, as before) and goes on without it otherwise; every other library stays required. Fixes #1487. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-prepare/src/artifacts.rs | 163 +++++++++++++++++++++++- 1 file changed, 159 insertions(+), 4 deletions(-) diff --git a/crates/horizon-prepare/src/artifacts.rs b/crates/horizon-prepare/src/artifacts.rs index b29bffb28..805dd80d4 100644 --- a/crates/horizon-prepare/src/artifacts.rs +++ b/crates/horizon-prepare/src/artifacts.rs @@ -372,6 +372,19 @@ fn client_library_artifacts(manifest: &Value) -> Result, Str Ok(artifacts) } +/// Netty's native transports (`io.netty:netty-transport-native-kqueue:4.2.16.Final:osx-aarch_64`, +/// the epoll ones on Linux): the game uses one when it loads and Netty NIO otherwise +/// (`EventLoopGroupHolder.remote` asks `KQueue.isAvailable()`, then `Epoll.isAvailable()`), and +/// Prism Launcher never downloads them (#1487). Preparing imports one when the launcher has it. +fn runs_without(name: &str) -> bool { + let mut parts = name.split(':'); + parts.next() == Some("io.netty") + && parts + .next() + .is_some_and(|artifact| artifact.starts_with("netty-transport-native-")) + && parts.nth(1).is_some() +} + /// A relative path with only normal components and forward slashes, from a manifest or bundle. pub(crate) fn safe_relative(path: &str) -> Option { if path.contains('\\') || path.starts_with('/') { @@ -547,9 +560,18 @@ pub fn import( for (name, artifact) in client_library_artifacts(&manifest)? { let (path, sha1) = artifact_fields(artifact)?; let relative = safe_relative(path).ok_or("Unsafe library path")?; + let source = launcher_library(&minecraft, name, &relative); + let destination = lock.directory.join("libraries/client").join(&relative); + if runs_without(name) && !source.is_file() && !destination.exists() { + log(&format!( + "No {name} in {}: the game runs without it", + minecraft.display() + )); + continue; + } client_libraries.push(import_copy( - &launcher_library(&minecraft, name, &relative), - &lock.directory.join("libraries/client").join(&relative), + &source, + &destination, sha1, "sha1", &hint(LAUNCHER_HINT, version), @@ -783,13 +805,17 @@ pub fn verify(lock: &Lock) -> Result { } /// The client libraries, checked against the version JSON (tools/test_model_baking_parity.py's -/// `client_libraries`); the client-side exporters compile against them. +/// `client_libraries`); the client-side exporters compile against them. A native transport the +/// player's launcher did not have is left out. pub fn client_libraries(lock: &Lock, manifest: &Value) -> Result, String> { let mut libraries = Vec::new(); - for (_, artifact) in client_library_artifacts(manifest)? { + for (name, artifact) in client_library_artifacts(manifest)? { let (path, sha1) = artifact_fields(artifact)?; let relative = safe_relative(path).ok_or("Unsafe client library path")?; let library = lock.directory.join("libraries/client").join(&relative); + if runs_without(name) && !library.exists() { + continue; + } if !library.exists() || digest(&library, "sha1")? != sha1 { return Err(format!("Client dependency checksum changed: {path}")); } @@ -1071,6 +1097,135 @@ mod tests { } } + /// scanfee's Prism Launcher 26.3 install on a Mac (#1487): Prism keeps natives under its own + /// names and never downloads Netty's native transport, which the game runs without. Preparing + /// still checks every other library, and the transport whenever the launcher has it. + #[test] + fn a_prism_install_without_netty_natives_prepares() { + let fixture = Imports::new(); + let old = fixture.imported(&fixture.source); + let prism = fixture.directory.join("PrismLauncher"); + let put = |path: &str, data: &[u8]| { + let path = prism.join(path); + fs::create_dir_all(path.parent().unwrap()).unwrap(); + fs::write(path, data).unwrap(); + }; + put( + "versions/9.9/9.9.jar", + &fs::read(old.join("jars/client.jar")).unwrap(), + ); + put("libraries/org/lib/lib/1/lib-1.jar", b"lib"); + put( + "libraries/com/mojang/jtracy-natives-test/1/jtracy-natives-test-1.jar", + b"jtracy natives", + ); + let sha1 = |data: &[u8]| { + let file = fixture.directory.join("sha1"); + fs::write(&file, data).unwrap(); + digest(&file, "sha1").unwrap() + }; + let library = |name: &str, path: &str, sha1: &str, rules: &str| { + format!( + r#"{{"name":"{name}","downloads":{{"artifact":{{"path":"{path}","sha1":"{sha1}"}}}}{rules}}}"# + ) + }; + let netty = |arch: &str| { + library( + &format!("io.netty:netty-transport-native-kqueue:1:osx-{arch}"), + &format!("io/netty/netty-transport-native-kqueue/1/netty-transport-native-kqueue-1-osx-{arch}.jar"), + &sha1(b"kqueue"), + &format!(r#","rules":[{{"action":"allow","os":{{"name":"{}"}}}}]"#, rule_system()), + ) + }; + let client_sha1 = digest(&old.join("jars/client.jar"), "sha1").unwrap(); + let server_sha1 = digest(&old.join("jars/server.jar"), "sha1").unwrap(); + let libraries = [ + library( + "org.lib:lib:1", + "org/lib/lib/1/lib-1.jar", + &sha1(b"lib"), + "", + ), + library( + "com.mojang:jtracy:1:natives-test", + "com/mojang/jtracy/1/jtracy-1-natives-test.jar", + &sha1(b"jtracy natives"), + "", + ), + netty("aarch_64"), + netty("x86_64"), + ]; + put( + "versions/9.9/9.9.json", + format!( + r#"{{"id":"9.9","javaVersion":{{"majorVersion":25}},"downloads":{{"client":{{"sha1":"{client_sha1}"}},"server":{{"sha1":"{server_sha1}"}}}},"libraries":[{}]}}"#, + libraries.join(",") + ) + .as_bytes(), + ); + let manifest_sha1 = digest(&prism.join("versions/9.9/9.9.json"), "sha1").unwrap(); + fs::write( + fixture.target.join("research-lock.json"), + format!( + r#"{{"minecraft":{{"version":"9.9","java_major":25,"manifest_sha1":"{manifest_sha1}","client_sha1":"{client_sha1}","server_sha1":"{server_sha1}"}}}}"# + ), + ) + .unwrap(); + let lock = Lock::read(&fixture.target).unwrap(); + let server = old.join("jars/server.jar"); + let prepare = || import(&fixture.target, &lock, Some(&prism), Some(&server), &|_| {}); + let imported = || { + let manifest = verify(&lock).unwrap().manifest; + client_libraries(&lock, &manifest).unwrap().len() + }; + + prepare().unwrap(); + assert_eq!(imported(), 2); + let prepared = read_json(&lock.directory.join("prepared.json")).unwrap(); + let listed = prepared.get("libraries").and_then(|l| l.get("client")); + assert_eq!( + listed.and_then(Value::as_array).map(<[Value]>::len), + Some(2) + ); + assert!(reuse_imported(&fixture.target, &|_| {}).unwrap()); + + // The launcher's copy is used, and checked, when it has one. + let manifest = read_json(&prism.join("versions/9.9/9.9.json")).unwrap(); + let (_, transport) = client_library_artifacts(&manifest) + .unwrap() + .into_iter() + .find(|(name, _)| runs_without(name)) + .unwrap(); + let path = transport.get("path").and_then(Value::as_str).unwrap(); + put(&format!("libraries/{path}"), b"not kqueue"); + assert!(prepare().unwrap_err().contains("is not the pinned file")); + put(&format!("libraries/{path}"), b"kqueue"); + prepare().unwrap(); + assert_eq!(imported(), 3); + // Other libraries stay required. + fs::remove_dir_all(lock.directory.join("libraries/client/org")).unwrap(); + fs::remove_file(prism.join("libraries/org/lib/lib/1/lib-1.jar")).unwrap(); + assert!(prepare().unwrap_err().starts_with("Missing ")); + } + + #[test] + fn runs_without_only_netty_native_transports() { + assert!(runs_without( + "io.netty:netty-transport-native-kqueue:4.2.16.Final:osx-aarch_64" + )); + assert!(runs_without( + "io.netty:netty-transport-native-epoll:4.2.16.Final:linux-x86_64" + )); + for required in [ + "io.netty:netty-transport-native-unix-common:4.2.16.Final", + "io.netty:netty-transport-classes-kqueue:4.2.16.Final", + "org.lwjgl:lwjgl:3.3.3:natives-macos-arm64", + "com.mojang:jtracy:1.14.38:natives-windows", + ] { + assert!(!runs_without(required), "{required}"); + } + } + #[test] fn natives_follow_the_architecture() { let names = ["a:b:1:natives-macos", "a:b:1:natives-macos-arm64"];