aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/build.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-07-25 22:33:35 +0900
committernsfisis <nsfisis@gmail.com>2026-07-25 22:33:35 +0900
commit2760e7e466fcf581d67cc2574241a824fbe158ff (patch)
tree8890233bcde7bc0eebafebd53e865576959fa8e1 /crates/shirabe/build.rs
parent53f4444c5ac9cc1c14749afb7ba2c3ccd1929889 (diff)
downloadphp-shirabe-2760e7e466fcf581d67cc2574241a824fbe158ff.tar.gz
php-shirabe-2760e7e466fcf581d67cc2574241a824fbe158ff.tar.zst
php-shirabe-2760e7e466fcf581d67cc2574241a824fbe158ff.zip
refactor(json): embed Composer schemas instead of copying them to target
build.rs guessed target/<profile> 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.
Diffstat (limited to 'crates/shirabe/build.rs')
-rw-r--r--crates/shirabe/build.rs37
1 files changed, 0 insertions, 37 deletions
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/<profile>/build/<pkg>-<hash>/out; its 3rd ancestor is target/<profile>.
- 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/<profile>, test/example binaries in target/<profile>/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()
- );
- }
-}