libgit: add higher-level libgit crate

The C functions exported by libgit-sys do not provide an idiomatic Rust
interface. To make it easier to use these functions via Rust, add a
higher-level "libgit" crate, that wraps the lower-level configset API
with an interface that is more Rust-y.

This combination of $X and $X-sys crates is a common pattern for FFI in
Rust, as documented in "The Cargo Book" [1].

[1] https://doc.rust-lang.org/cargo/reference/build-scripts.html#-sys-packages

Co-authored-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Josh Steadmon <steadmon@google.com>
Signed-off-by: Calvin Wan <calvinwan@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Calvin Wan
2025-01-29 13:50:44 -08:00
committed by Junio C Hamano
parent d76eb0dccc
commit 65c10aa8d5
13 changed files with 242 additions and 8 deletions

View File

@@ -417,7 +417,7 @@ include shared.mak
# programs in oss-fuzz/.
#
# Define INCLUDE_LIBGIT_RS if you want `make all` and `make test` to build and
# test the Rust crate in contrib/libgit-sys.
# test the Rust crates in contrib/libgit-sys and contrib/libgit-rs.
#
# === Optional library: libintl ===
#
@@ -3742,7 +3742,7 @@ clean: profile-clean coverage-clean cocciclean
$(RM) $(htmldocs).tar.gz $(manpages).tar.gz
$(MAKE) -C Documentation/ clean
$(RM) Documentation/GIT-EXCLUDED-PROGRAMS
$(RM) -r contrib/libgit-sys/target
$(RM) -r contrib/libgit-sys/target contrib/libgit-rs/target
$(RM) contrib/libgit-sys/partial_symbol_export.o
$(RM) contrib/libgit-sys/hidden_symbol_export.o
$(RM) contrib/libgit-sys/libgitpub.a
@@ -3908,14 +3908,14 @@ build-unit-tests: $(UNIT_TEST_PROGS) $(CLAR_TEST_PROG)
unit-tests: $(UNIT_TEST_PROGS) $(CLAR_TEST_PROG) t/helper/test-tool$X
$(MAKE) -C t/ unit-tests
.PHONY: libgit-sys
libgit-sys:
.PHONY: libgit-sys libgit-rs
libgit-sys libgit-rs:
$(QUIET)(\
cd contrib/libgit-sys && \
cd contrib/$@ && \
cargo build \
)
ifdef INCLUDE_LIBGIT_RS
all:: libgit-sys
all:: libgit-sys libgit-rs
endif
LIBGIT_PUB_OBJS += contrib/libgit-sys/public_symbol_export.o