From e57c64c8651918a7aa56dc1f3e75d673284b48ae Mon Sep 17 00:00:00 2001 From: ynqa Date: Thu, 14 Nov 2024 00:37:14 +0900 Subject: [PATCH 1/3] fix: remove unnecessary sources copy step --- j9-sys/build.rs | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/j9-sys/build.rs b/j9-sys/build.rs index 8bb2879..f3475dc 100644 --- a/j9-sys/build.rs +++ b/j9-sys/build.rs @@ -2,7 +2,7 @@ extern crate autotools; extern crate bindgen; use std::{ - env, fs, + env, path::{Path, PathBuf}, process::Command, }; @@ -37,40 +37,9 @@ 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 - let parser_src = src_dir.join("src/parser.c"); - 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(&build_dir) + autotools::Config::new(&src_dir) .reconf("-i") .out_dir(&out_dir) .with("oniguruma", Some("builtin")) From 920bab4c30ac2f9bc3b5205c28116e833014795a Mon Sep 17 00:00:00 2001 From: ynqa Date: Thu, 14 Nov 2024 00:39:44 +0900 Subject: [PATCH 2/3] bump up version to v0.1.4 --- j9-sys/Cargo.toml | 2 +- j9/Cargo.toml | 4 ++-- j9/README.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/j9-sys/Cargo.toml b/j9-sys/Cargo.toml index 1ccb118..bb88e45 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" 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 From 739f3a8cda69e08c3f01ad0b2589668ba44d0652 Mon Sep 17 00:00:00 2001 From: ynqa Date: Thu, 14 Nov 2024 01:03:15 +0900 Subject: [PATCH 3/3] revert modification --- j9-sys/Cargo.toml | 1 + j9-sys/build.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/j9-sys/Cargo.toml b/j9-sys/Cargo.toml index bb88e45..2c95959 100644 --- a/j9-sys/Cargo.toml +++ b/j9-sys/Cargo.toml @@ -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 f3475dc..81061c6 100644 --- a/j9-sys/build.rs +++ b/j9-sys/build.rs @@ -5,8 +5,11 @@ use std::{ 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(); @@ -38,6 +41,18 @@ 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"); + // 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"); + filetime::set_file_mtime(&parser_src, now)?; + // See https://github.com/jqlang/jq/tree/jq-1.7.1?#instructions autotools::Config::new(&src_dir) .reconf("-i")