Skip to content

Commit

Permalink
Merge pull request #50 from sgrif/allow_other_crates_to_reuse_the_sta…
Browse files Browse the repository at this point in the history
…tic_build

Allow other crates to reuse the bundled static build
  • Loading branch information
weiznich committed Feb 9, 2024
2 parents 0bad18b + 5454b4f commit c2b080f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
1 change: 1 addition & 0 deletions pq-src/Cargo.toml
Expand Up @@ -17,6 +17,7 @@ include = [
description = "Bundled version of libpq"
license = "MIT OR Apache-2.0"
repository = "https://github.com/sgrif/pq-sys"
links = "pq_sys_src"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
60 changes: 51 additions & 9 deletions pq-src/build.rs
Expand Up @@ -220,15 +220,57 @@ fn main() {

basic_build
.clone()
.files(LIBPORTS.iter().map(|p| format!("{path}{port_path}{p}")))
.compile("ports");
.files(
LIBPORTS
.iter()
.map(|p| format!("{path}{port_path}{p}"))
.chain(LIBCOMMON.iter().map(|p| format!("{path}{common_path}{p}")))
.chain(LIBPQ.iter().map(|p| format!("{path}{pq_path}{p}"))),
)
.compile("pq");

basic_build
.clone()
.files(LIBCOMMON.iter().map(|p| format!("{path}{common_path}{p}")))
.compile("pgcommon");
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");

basic_build
.files(LIBPQ.iter().map(|p| format!("{path}{pq_path}{p}")))
.compile("pq");
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 c2b080f

Please sign in to comment.