Re: [PATCH 0/3] Makefile update libgit.a: Include xdiff and reftable in libgit.a
- From
Ezekiel Newren <ezekielnewren@gmail.com>
- Date
- Oct 2, 2025, 19:17 UTC
- Message-ID
- <CAH=ZcbCJjuKtVGmFv0xHTHt8XaAVPwh-Cjyba0jTaQMH7Dkh2Q@mail.gmail.com>
- In-Reply-To
- <xmqqecrmyz9j.fsf@gitster.g>
On Wed, Oct 1, 2025 at 5:32 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 22 quoted lines
> > "Ezekiel Newren via GitGitGadget" <gitgitgadget@gmail.com> writes: > > > The Rust compiler only needs to know how to link against libgit.a in 2 cases > > that I can think of: > > > > * Rust unit tests > > * Rust defining the main function > > > > Otherwise Rust can be compiled without linking, and then Makefile and Meson > > can use Cargo's produced static lib files to build Git. > > It is a bit unclear why two (or three) are so much more hassle than > one, but OK. Allowing both build systems to agree on the same set > of artifacts is very much desirable, and if meson based build rolls > everything into a single library archive, the the other one should > do the same. > > Of course we could run "ar" ourselves and combine the three into a > single library archive, but as an approach, what you have here is a > perfectly fine, and more preferable, way to achieve the goal of > ending up with a single archive file.
In order for Cargo to tell the Rust compiler how to link against the C
archives they need to be specified in the build.rs file for each
crate. That would look something like this:
tree gitcore/
gitcore/
├── build.rs
├── Cargo.toml
└── src
├── do_that.rs
├── do_this.rs
└── lib.rsWhere gitcore/build.rs would look something like this:
fn main() {
...
println!("cargo:rustc-link-search=native={}", git_build_dir);
println!("cargo:rustc-link-lib=static=git");
if let Some(built_with_makefile) = std::env::var("BUILT_WITH_MAKEFILE") {
println!("cargo:rustc-link-search=native={}",
git_build_dir.join("xdiff"));
println!("cargo:rustc-link-lib=static=xdiff");
println!("cargo:rustc-link-search=native={}",
git_build_dir.join("reftable"));
println!("cargo:rustc-link-lib=static=reftable");
}
}But `cargo build` is invoked by a shell script by both Makefile and Meson, and build.rs would need to have an environment variable set. Something like BUILT_WITH_MAKEFILE for only when build_rust.sh is invoked by makefile and then you'd have to remember to update both Makefile and every build.rs if the library files produced by Makefile are ever changed. It seems a lot cleaner to hardcode just libgit.a and leave it up to the build systems to ensure that everything inside that static library contains everything that is needed.
Show 5 quoted lines
> This topic, however, especially its first step, had caused rather > unpleasant textual conflicts when merged to 'seen' (I didn't check > which other topic was the most heavily conflicting, though). I may > attempt to get a clean merge again tomorrow, but due to time > pressure, tonight's 'seen' was done without these patches merged.
I wonder if Patrick's approach would cause fewer merge conflicts. If I add xdiff and reftable objects to LIB_OBJS directly then I don't need to bother with the move commit.