Skip to content

Commit

Permalink
fix: remove unnecessary sources copy step
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Nov 13, 2024
1 parent eabf1b1 commit e57c64c
Showing 1 changed file with 2 additions and 33 deletions.
35 changes: 2 additions & 33 deletions j9-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extern crate autotools;
extern crate bindgen;

use std::{
env, fs,
env,
path::{Path, PathBuf},
process::Command,
};
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit e57c64c

Please sign in to comment.