git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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.rs
Where 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.

Previous: Junio C HamanoNext: Junio C Hamano
Message 16 of 23 in “Makefile update libgit.a: Include xdiff and reftable in libgit.a”
  1. 0/3 Makefile update libgit.a: Include xdiff and reftable in libgit.aEzekiel Newren via GitGitGadget, Oct 1, 2025
  2. 1/3 make: move xdiff and reftable objects before GITLIBSEzekiel Newren via GitGitGadget, Oct 1, 2025
  3. 2/3 make: delete XDIFF_LIB, add xdiff to LIB_OBJSEzekiel Newren via GitGitGadget, Oct 1, 2025
  4. Patrick SteinhardtOct 2, 2025
  5. Junio C HamanoOct 2, 2025
  6. Patrick SteinhardtOct 2, 2025
  7. Ezekiel NewrenOct 2, 2025
  8. Junio C HamanoOct 2, 2025
  9. Ezekiel NewrenOct 2, 2025
  10. Ezekiel NewrenOct 2, 2025
  11. 3/3 make: delete REFTABLE_LIB, add reftable to LIB_OBJSEzekiel Newren via GitGitGadget, Oct 1, 2025
  12. Patrick SteinhardtOct 2, 2025
  13. Junio C HamanoOct 2, 2025
  14. Ezekiel NewrenOct 2, 2025
  15. Junio C HamanoOct 1, 2025
  16. Ezekiel NewrenOct 2, 2025
  17. Junio C HamanoOct 2, 2025
  18. Ezekiel NewrenOct 2, 2025
  19. 0/2 Makefile update libgit.a: Include xdiff and reftable in libgit.aEzekiel Newren via GitGitGadget, Oct 2, 2025
  20. 1/2 make: delete XDIFF_LIB, add xdiff to LIB_OBJSEzekiel Newren via GitGitGadget, Oct 2, 2025
  21. 2/2 make: delete REFTABLE_LIB, add reftable to LIB_OBJSEzekiel Newren via GitGitGadget, Oct 2, 2025
  22. Junio C HamanoOct 3, 2025
  23. Patrick SteinhardtOct 8, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.