forked from BynBang/OpenPrestige
Add compatibility notes, resource-provider and hook checks, and payload bundling script. Remove generated engine mixin stubs, engine target lists and prebuilt binaries now produced by the build. Co-Authored-By: Claude Opus 5.5 <[email protected]>
34 lines
1.8 KiB
Rust
34 lines
1.8 KiB
Rust
//! Embed exact-version payloads and one copy of their common libraries.
|
|
use std::{env, fs, path::{Path, PathBuf}};
|
|
|
|
fn include(path: &Path) -> String {
|
|
let path = path.canonicalize().unwrap_or_else(|e| panic!("{}: {e}", path.display()));
|
|
println!("cargo:rerun-if-changed={}", path.display());
|
|
format!("include_bytes!({:?})", path.to_str().expect("UTF-8 payload path"))
|
|
}
|
|
|
|
fn main() {
|
|
println!("cargo:rerun-if-env-changed=PRESTIGE_PAYLOAD");
|
|
println!("cargo:rerun-if-env-changed=PRESTIGE_BUNDLE");
|
|
let generated = if let Ok(jar) = env::var("PRESTIGE_PAYLOAD") {
|
|
// Explicit single-target developer builds retain Java's exact-target guard.
|
|
format!("static COMMON: &[u8] = &[];\nstatic PAYLOADS: &[(&str, &[u8])] = &[(\"\", {})];", include(Path::new(&jar)))
|
|
} else {
|
|
let dir = env::var_os("PRESTIGE_BUNDLE").map(PathBuf::from).unwrap_or_else(||
|
|
PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("../../../build/bundle"));
|
|
let manifest = dir.join("versions.txt");
|
|
println!("cargo:rerun-if-changed={}", manifest.display());
|
|
let versions = fs::read_to_string(&manifest)
|
|
.expect("run gradlew bundlePayloads before building the native bundle");
|
|
let expected: Vec<_> = (1..=11).map(|n| format!("1.21.{n}")).collect();
|
|
assert_eq!(versions.lines().collect::<Vec<_>>(), expected, "incomplete payload matrix");
|
|
let mut code = format!("static COMMON: &[u8] = {};\nstatic PAYLOADS: &[(&str, &[u8])] = &[\n", include(&dir.join("common.jar")));
|
|
for version in versions.lines() {
|
|
code.push_str(&format!("({version:?}, {}),\n", include(&dir.join(format!("{version}.jar")))));
|
|
}
|
|
code.push_str("];\n");
|
|
code
|
|
};
|
|
fs::write(PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("payloads.rs"), generated).unwrap();
|
|
}
|