diff --git a/j9-sys/Cargo.toml b/j9-sys/Cargo.toml index 1ccb118..2c95959 100644 --- a/j9-sys/Cargo.toml +++ b/j9-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "j9-sys" -version = "0.1.3" +version = "0.1.4" authors = ["ynqa "] edition = "2021" description = "Rust bindings for jq" @@ -14,4 +14,5 @@ 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 8bb2879..81061c6 100644 --- a/j9-sys/build.rs +++ b/j9-sys/build.rs @@ -2,11 +2,14 @@ extern crate autotools; extern crate bindgen; use std::{ - env, fs, + env, 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(); @@ -37,40 +40,21 @@ 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)?; - } - } - // 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 + // 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()); let parser_src = src_dir.join("src/parser.c"); - let parser_target = build_dir.join("src/parser.c"); - fs::copy(parser_src, parser_target)?; + filetime::set_file_mtime(&parser_src, now)?; // See https://github.com/jqlang/jq/tree/jq-1.7.1?#instructions - autotools::Config::new(&build_dir) + autotools::Config::new(&src_dir) .reconf("-i") .out_dir(&out_dir) .with("oniguruma", Some("builtin")) diff --git a/j9/Cargo.toml b/j9/Cargo.toml index 49cde86..c000b9a 100644 --- a/j9/Cargo.toml +++ b/j9/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "j9" -version = "0.1.3" +version = "0.1.4" 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.3" } +j9-sys = { path = "../j9-sys", version = "0.1.4" } thiserror = "1.0.57" [dev-dependencies] diff --git a/j9/README.md b/j9/README.md index 26bbe6e..c26b401 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.3" +j9 = "0.1.4" ``` ## Example