Re: [PATCH 10/14] rust: add a build.rs script for tests
From: Ezekiel Newren <hidden>
Date: 2025-10-29 22:10:40
On Wed, Oct 29, 2025 at 10:43 AM Junio C Hamano [off-list ref] wrote:
"brian m. carlson" [off-list ref] writes:quoted
Cargo uses the build.rs script to determine how to compile and link a binary. The only binary we're generating, however, is for our tests, but in a future commit, we're going to link against libgit.a for some functionality and we'll need to make sure the test binaries are complete.OK.quoted
-$(RUST_LIB): Cargo.toml $(RUST_SOURCES) +$(RUST_LIB): Cargo.toml $(RUST_SOURCES) $(XDIFF_LIB) $(LIB_FILE) $(REFTABLE_LIB) $(QUIET_CARGO)cargo build $(CARGO_ARGS) ... +fn main() { + println!("cargo::rustc-link-search=."); + println!("cargo::rustc-link-search=reftable"); + println!("cargo::rustc-link-search=xdiff"); + println!("cargo::rustc-link-lib=git"); + println!("cargo::rustc-link-lib=reftable"); + println!("cargo::rustc-link-lib=z"); + println!("cargo::rustc-link-lib=xdiff"); +}Hmm, I recall Ezekiel earlier arguing to roll reftable and xdiff libraries into libgit.a as it is a lot more cumbersome to have to link with multiple libraries (sorry, I may be misremembering and do not have reference handy), but if the above is all it takes to link with these, perhaps it is not such a huge deal?
I think Brian might have written this before my series was merged in.
I am a bit confused. XDIFF_LIB and REFTABLE_LIB are gone from Makefile on 'master' already. Perhaps we should revert earlier series from him?
I don't think we should revert my series. Brian should delete certain
lines like so:
fn main() {
println!("cargo::rustc-link-search=.");
- println!("cargo::rustc-link-search=reftable");
- println!("cargo::rustc-link-search=xdiff");
println!("cargo::rustc-link-lib=git");
- println!("cargo::rustc-link-lib=reftable");
println!("cargo::rustc-link-lib=z");
- println!("cargo::rustc-link-lib=xdiff");
}
Also the makefile needs to add the flag -fPIC or -fPIE when compiling with Rust.