From 2760e7e466fcf581d67cc2574241a824fbe158ff Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 25 Jul 2026 22:33:35 +0900 Subject: refactor(json): embed Composer schemas instead of copying them to target build.rs guessed target/ from OUT_DIR to place res/*.json next to the executable (twice, since test binaries live in deps/), and JsonFile resolved them through current_exe(). That made the binary undistributable on its own. The schemas are now include_str!'d and referenced through a shirabe:///res/ URI that SchemaRetriever resolves, keeping the $ref indirection PHP uses for the phar case. The res/ path segment is required so composer-lock-schema.json's relative "./composer-schema.json" reference still resolves. --- crates/shirabe/build.rs | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 crates/shirabe/build.rs (limited to 'crates/shirabe/build.rs') diff --git a/crates/shirabe/build.rs b/crates/shirabe/build.rs deleted file mode 100644 index d98b07e7..00000000 --- a/crates/shirabe/build.rs +++ /dev/null @@ -1,37 +0,0 @@ -use std::path::PathBuf; - -// Composer ships its JSON schemas in res/ and JsonFile resolves them via __DIR__. -// We copy those schema files next to the built executable so they can be located -// at runtime through std::env::current_exe(). -fn main() { - let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); - let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap()); - - // OUT_DIR is target//build/-/out; its 3rd ancestor is target/. - let target_profile_dir = out_dir - .ancestors() - .nth(3) - .expect("OUT_DIR has an unexpected layout"); - - let composer_res = manifest_dir.join("../../composer/res"); - let files = ["composer-schema.json", "composer-lock-schema.json"]; - - // Binaries live in target/, test/example binaries in target//deps; - // populate a res/ directory next to both so current_exe()/../res resolves either way. - for dest_dir in [ - target_profile_dir.join("res"), - target_profile_dir.join("deps").join("res"), - ] { - std::fs::create_dir_all(&dest_dir).unwrap(); - for file in files { - std::fs::copy(composer_res.join(file), dest_dir.join(file)).unwrap(); - } - } - - for file in files { - println!( - "cargo:rerun-if-changed={}", - composer_res.join(file).display() - ); - } -} -- cgit v1.3.1