aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/build.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-22 23:40:47 +0900
committernsfisis <nsfisis@gmail.com>2026-06-22 23:40:47 +0900
commit99ef82a9807578c1e5749156a027949efaba75c4 (patch)
treee5f6bfb4c74c1ced20a9bc1c884f811f582e38eb /crates/shirabe/build.rs
parentffd3e239a56172d2a336fb4d6253c01f6b1a0100 (diff)
downloadphp-shirabe-99ef82a9807578c1e5749156a027949efaba75c4.tar.gz
php-shirabe-99ef82a9807578c1e5749156a027949efaba75c4.tar.zst
php-shirabe-99ef82a9807578c1e5749156a027949efaba75c4.zip
feat(json): resolve bundled Composer schema files via build.rs
JsonFile's schema paths previously relied on php_dir() (__DIR__), which has no runtime equivalent. Add a build.rs that copies composer-schema.json and composer-lock-schema.json next to the built executable, and resolve them with std::env::current_exe(). FilesystemRepository now embeds InstalledVersions.php directly via include_str! instead of reading it through php_dir(). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/build.rs')
-rw-r--r--crates/shirabe/build.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/crates/shirabe/build.rs b/crates/shirabe/build.rs
new file mode 100644
index 0000000..d98b07e
--- /dev/null
+++ b/crates/shirabe/build.rs
@@ -0,0 +1,37 @@
+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()
+ );
+ }
+}