Skip to content

Commit

Permalink
fix: copy sources to OUT_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
ynqa committed Mar 4, 2024
1 parent 5d55e87 commit d42091e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions j9-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ edition = "2021"
anyhow = "1.0.80"
autotools = "0.2.6"
bindgen = "0.69.4"
walkdir = "2.5.0"
23 changes: 21 additions & 2 deletions j9-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,35 @@ extern crate autotools;
extern crate bindgen;

use std::{
env,
env, fs,
path::{Path, PathBuf},
};

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)?;
}
}

// 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"))
Expand Down

0 comments on commit d42091e

Please sign in to comment.