Skip to content

Commit

Permalink
Copy headers to a distinct include directory in target
Browse files Browse the repository at this point in the history
  • Loading branch information
weiznich committed Jan 30, 2024
1 parent 77e6729 commit 5454b4f
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions pq-src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,48 @@ fn main() {
)
.compile("pq");

println!("cargo:include={path}/src/include");
println!("cargo:lib_dir={}", std::env::var("OUT_DIR").expect("Set by cargo"));
let out = std::env::var("OUT_DIR").expect("Set by cargo");
let include_path = PathBuf::from(&out).join("include");
let lib_pq_path = PathBuf::from(format!("{path}/{pq_path}"));
std::fs::create_dir_all(&include_path).expect("Failed to create include directory");
std::fs::create_dir_all(include_path.join("postgres").join("internal"))
.expect("Failed to create include directory");
std::fs::copy(
lib_pq_path.join("libpq-fe.h"),
include_path.join("libpq-fe.h"),
)
.expect("Copying headers failed");
std::fs::copy(
lib_pq_path.join("libpq-events.h"),
include_path.join("libpq-events.h"),
)
.expect("Copying headers failed");

std::fs::copy(
lib_pq_path.join("libpq-int.h"),
include_path
.join("postgres")
.join("internal")
.join("libpq-int.h"),
)
.expect("Copying headers failed");
std::fs::copy(
lib_pq_path.join("fe-auth-sasl.h"),
include_path
.join("postgres")
.join("internal")
.join("fe-auth-sasl.h"),
)
.expect("Copying headers failed");
std::fs::copy(
lib_pq_path.join("pqexpbuffer.h"),
include_path
.join("postgres")
.join("internal")
.join("pqexpbuffer.h"),
)
.expect("Copying headers failed");

println!("cargo:include={out}/include");
println!("cargo:lib_dir={}", out);
}

0 comments on commit 5454b4f

Please sign in to comment.