rust: add a build.rs script for tests

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. Add a build.rs file for this case and specify the files we're going to be linking against. Because we cannot specify different dependencies when building our static library versus our tests, update the Makefile to specify these dependencies for our static library to avoid race conditions during build. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Feb 7, 2026 at 20:04 UTC 3bb0b0afaba588c04982103534afa2aae922f5bf
2 files changed +18 -1
Makefile
+1 -1
@@ -3008,7 +3008,7 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
3008 $(LIB_FILE): $(LIB_OBJS)
3009 $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
3010
3011 -$(RUST_LIB): Cargo.toml $(RUST_SOURCES)
3011 +$(RUST_LIB): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)
3012 $(QUIET_CARGO)cargo build $(CARGO_ARGS)
3013
3014 .PHONY: rust
build.rs new
+17
@@ -0,0 +1,17 @@
1 +// This program is free software; you can redistribute it and/or modify
2 +// it under the terms of the GNU General Public License as published by
3 +// the Free Software Foundation: version 2 of the License, dated June 1991.
4 +//
5 +// This program is distributed in the hope that it will be useful,
6 +// but WITHOUT ANY WARRANTY; without even the implied warranty of
7 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 +// GNU General Public License for more details.
9 +//
10 +// You should have received a copy of the GNU General Public License along
11 +// with this program; if not, see <https://www.gnu.org/licenses/>.
12 +
13 +fn main() {
14 + println!("cargo:rustc-link-search=.");
15 + println!("cargo:rustc-link-lib=git");
16 + println!("cargo:rustc-link-lib=z");
17 +}