From 4c3caaefe7a89d205b51b43708e443fbc91f83a1 Mon Sep 17 00:00:00 2001 From: ynqa Date: Thu, 14 Nov 2024 23:52:58 +0900 Subject: [PATCH] Revert "v0.1.4: remove unnecessary sources copy step" --- j9-sys/Cargo.toml | 3 +-- j9-sys/build.rs | 46 +++++++++++++++++++++++++++++++--------------- j9/Cargo.toml | 4 ++-- j9/README.md | 2 +- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/j9-sys/Cargo.toml b/j9-sys/Cargo.toml index 2c95959..1ccb118 100644 --- a/j9-sys/Cargo.toml +++ b/j9-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "j9-sys" -version = "0.1.4" +version = "0.1.3" authors = ["ynqa "] edition = "2021" description = "Rust bindings for jq" @@ -14,5 +14,4 @@ readme = "README.md" anyhow = "1.0.80" autotools = "0.2.6" bindgen = "0.69.4" -filetime = "0.2.25" walkdir = "2.5.0" diff --git a/j9-sys/build.rs b/j9-sys/build.rs index 81061c6..8bb2879 100644 --- a/j9-sys/build.rs +++ b/j9-sys/build.rs @@ -2,14 +2,11 @@ extern crate autotools; extern crate bindgen; use std::{ - env, + env, fs, path::{Path, PathBuf}, process::Command, - time::SystemTime, }; -use filetime::FileTime; - fn check_installed(name: &str) -> anyhow::Result<()> { let check = Command::new(name).arg("--version").output(); @@ -40,21 +37,40 @@ fn main() -> anyhow::Result<()> { let out_dir = env::var("OUT_DIR").map(PathBuf::from)?; let src_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("jq"); + let build_dir = out_dir.join("jq_build"); + + // Copy the contents of the src_dir to build_dir within OUT_DIR + // to avoid modifying the source directory during the build process. + // This ensures compliance with Cargo's policy that build scripts + // should not modify anything outside of OUT_DIR. + if build_dir.exists() { + fs::remove_dir_all(&build_dir)?; + } + fs::create_dir(&build_dir)?; + for entry in walkdir::WalkDir::new(&src_dir) { + let entry = entry?; + let target_path = build_dir.join(entry.path().strip_prefix(&src_dir)?); + if entry.file_type().is_dir() { + fs::create_dir_all(target_path)?; + } else { + fs::copy(entry.path(), target_path)?; + } + } - // Modify the timestamp of parser.c file - // to circumvent an error on building in Linux that goes something like: - // - // clang: error: no such file or directory: 'src/parser.c' - // clang: error: no input files - // make[2]: *** [Makefile:1051: src/parser.lo] Error 1 - // make[1]: *** [Makefile:1188: install-recursive] Error 1 - // make: *** [Makefile:1709: install] Error 2 - let now = FileTime::from(SystemTime::now()); + // It seems that modifying the timestamp of the lexer.c file by copying + // it to the target directory is necessary to circumvent an error that goes something like: + // cc1: fatal error: src/lexer.c: No such file or directory compilation terminated. + let lexer_src = src_dir.join("src/lexer.c"); + let lexer_target = build_dir.join("src/lexer.c"); + fs::copy(lexer_src, lexer_target)?; + // parser.c also + // error: src/parser.c: No such file or directory let parser_src = src_dir.join("src/parser.c"); - filetime::set_file_mtime(&parser_src, now)?; + let parser_target = build_dir.join("src/parser.c"); + fs::copy(parser_src, parser_target)?; // See https://github.com/jqlang/jq/tree/jq-1.7.1?#instructions - autotools::Config::new(&src_dir) + autotools::Config::new(&build_dir) .reconf("-i") .out_dir(&out_dir) .with("oniguruma", Some("builtin")) diff --git a/j9/Cargo.toml b/j9/Cargo.toml index c000b9a..49cde86 100644 --- a/j9/Cargo.toml +++ b/j9/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "j9" -version = "0.1.4" +version = "0.1.3" authors = ["ynqa "] edition = "2021" description = "Rust interface for jq-based JSON processing" @@ -12,7 +12,7 @@ name = "j9" path = "src/lib.rs" [dependencies] -j9-sys = { path = "../j9-sys", version = "0.1.4" } +j9-sys = { path = "../j9-sys", version = "0.1.3" } thiserror = "1.0.57" [dev-dependencies] diff --git a/j9/README.md b/j9/README.md index c26b401..26bbe6e 100644 --- a/j9/README.md +++ b/j9/README.md @@ -9,7 +9,7 @@ To use j9, add it as a dependency in your Cargo.toml: ```toml [dependencies] -j9 = "0.1.4" +j9 = "0.1.3" ``` ## Example