From: Ezekiel Newren Date: Tue, 28 Oct 2025 17:42:21 GMT Subject: Re: [PATCH 10/14] rust: add a build.rs script for tests Message-ID: In-Reply-To: On Tue, Oct 28, 2025 at 3:18 AM Patrick Steinhardt wrote: > > On Mon, Oct 27, 2025 at 12:44:00AM +0000, brian m. carlson wrote: > > diff --git a/Makefile b/Makefile > > index 7e5a735ca6..7c36302717 100644 > > --- a/Makefile > > +++ b/Makefile > > @@ -2948,7 +2948,7 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS) > > $(LIB_FILE): $(LIB_OBJS) > > $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^ > > > > -$(RUST_LIB): Cargo.toml $(RUST_SOURCES) > > +$(RUST_LIB): Cargo.toml $(RUST_SOURCES) $(XDIFF_LIB) $(LIB_FILE) $(REFTABLE_LIB) > > $(QUIET_CARGO)cargo build $(CARGO_ARGS) > > We have recently removed the separare xdiff and reftable libraries, so > it shouldn't be necessary to have these anymore. Patrick is referring to my Makefile update libgit.a patch series that has been merged into master [1]. > But one thing I'm curious about: don't we have a circular dependency > between the Rust and C library now? I guess that's somewhat expected, as > we'll want to call Rust from C and vice versa. But on the Meson side I > think we need to adjust our logic so that we don't pull the Rust library > into libgit.a to break this cycle. > > > diff --git a/build.rs b/build.rs > > new file mode 100644 > > index 0000000000..136d58c35a > > --- /dev/null > > +++ b/build.rs > > @@ -0,0 +1,21 @@ > > +// This program is free software; you can redistribute it and/or modify > > +// it under the terms of the GNU General Public License as published by > > +// the Free Software Foundation: version 2 of the License, dated June 1991. > > +// > > +// This program is distributed in the hope that it will be useful, > > +// but WITHOUT ANY WARRANTY; without even the implied warranty of > > +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > > +// GNU General Public License for more details. > > +// > > +// You should have received a copy of the GNU General Public License along > > +// with this program; if not, see . > > + > > +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"); > > +} > > How do we ensure that the correct libraries are linked here? E.g. for > libz, if there are multiple such libraries, which one gets precedence? I solved this problem in my own Introduce Rust series [2,3]. When Makefile or Meson is invoking Cargo it sets the environment variable `USE_LINKING=false` and build.rs doesn't link against libgit.a or any other library. When `cargo test` is called it will link against libgit.a because if USE_LINKING is not set then it assumes true. [1] Makefile update libgit.a https://lore.kernel.org/git/pull.2065.v2.git.git.1759447647.gitgitgadget@gmail.com/ [2] Ezekiel's Introduce Rust https://lore.kernel.org/git/6032a8740c0ba72420f42c3d8d801e1bdeec12d0.1758071798.git.gitgitgadget@gmail.com/ [3] Ezekiel's Introduce Rust https://lore.kernel.org/git/6a27e07e6310b6cad0e3feae817269b9b8eaed69.1758071798.git.gitgitgadget@gmail.com/