@@ -483,6 +483,14 @@ include shared.mak
483483# Define LIBPCREDIR=/foo/bar if your PCRE header and library files are
484484# in /foo/bar/include and /foo/bar/lib directories.
485485#
486+ # == Optional Rust support ==
487+ #
488+ # Define WITH_RUST if you want to include features and subsystems written in
489+ # Rust into Git. For now, Rust is still an optional feature of the build
490+ # process. With Git 3.0 though, Rust will always be enabled.
491+ #
492+ # Building Rust code requires Cargo.
493+ #
486494# == SHA-1 and SHA-256 defines ==
487495#
488496# === SHA-1 backend ===
@@ -918,6 +926,11 @@ TEST_SHELL_PATH = $(SHELL_PATH)
918926LIB_FILE = libgit.a
919927XDIFF_LIB = xdiff/lib.a
920928REFTABLE_LIB = reftable/libreftable.a
929+ ifdef DEBUG
930+ RUST_LIB = target/debug/libgit.a
931+ else
932+ RUST_LIB = target/release/libgit.a
933+ endif
921934
922935GENERATED_H += command-list.h
923936GENERATED_H += config-list.h
@@ -1196,7 +1209,9 @@ LIB_OBJS += urlmatch.o
11961209LIB_OBJS += usage.o
11971210LIB_OBJS += userdiff.o
11981211LIB_OBJS += utf8.o
1212+ ifndef WITH_RUST
11991213LIB_OBJS += varint.o
1214+ endif
12001215LIB_OBJS += version.o
12011216LIB_OBJS += versioncmp.o
12021217LIB_OBJS += walker.o
@@ -1388,8 +1403,12 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
13881403
13891404UNIT_TEST_OBJS += $(UNIT_TEST_DIR ) /test-lib.o
13901405
1391- # xdiff and reftable libs may in turn depend on what is in libgit.a
1392- GITLIBS = common-main.o $(LIB_FILE ) $(XDIFF_LIB ) $(REFTABLE_LIB ) $(LIB_FILE )
1406+ GITLIBS = common-main.o $(LIB_FILE ) $(XDIFF_LIB ) $(REFTABLE_LIB )
1407+ ifdef WITH_RUST
1408+ GITLIBS += $(RUST_LIB )
1409+ endif
1410+ # Other libs may in turn depend on what is in libgit.a.
1411+ GITLIBS += $(LIB_FILE )
13931412EXTLIBS =
13941413
13951414GIT_USER_AGENT = git/$(GIT_VERSION )
@@ -1412,6 +1431,19 @@ BASIC_LDFLAGS =
14121431ARFLAGS = rcs
14131432PTHREAD_CFLAGS =
14141433
1434+ # Rust flags
1435+ CARGO_ARGS =
1436+ ifndef V
1437+ CARGO_ARGS += --quiet
1438+ endif
1439+ ifndef DEBUG
1440+ CARGO_ARGS += --release
1441+ endif
1442+
1443+ ifdef WITH_RUST
1444+ BASIC_CFLAGS += -DWITH_RUST
1445+ endif
1446+
14151447# For the 'sparse' target
14161448SPARSE_FLAGS ?= -std=gnu99 -D__STDC_NO_VLA__
14171449SP_EXTRA_FLAGS =
@@ -2919,6 +2951,16 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
29192951$(LIB_FILE ) : $(LIB_OBJS )
29202952 $(QUIET_AR )$(RM ) $@ && $(AR ) $(ARFLAGS ) $@ $^
29212953
2954+ $(RUST_LIB ) : FORCE
2955+ @OLD_STAT=" $$ (stat $@ 2>/dev/null)" ; \
2956+ cargo build $(CARGO_ARGS ) ; \
2957+ if test $$ ? ! = 0 || test x" $$ OLD_STAT" ! = x" $$ (stat $@ 2>/dev/null)" ; then \
2958+ echo ' ' CARGO $@ ; \
2959+ fi
2960+
2961+ .PHONY : rust
2962+ rust : $(RUST_LIB )
2963+
29222964$(XDIFF_LIB ) : $(XDIFF_OBJS )
29232965 $(QUIET_AR )$(RM ) $@ && $(AR ) $(ARFLAGS ) $@ $^
29242966
@@ -3769,6 +3811,7 @@ clean: profile-clean coverage-clean cocciclean
37693811 $(RM ) $(FUZZ_PROGRAMS )
37703812 $(RM ) $(SP_OBJ )
37713813 $(RM ) $(HCC )
3814+ $(RM ) -r target/ Cargo.lock
37723815 $(RM ) version-def.h
37733816 $(RM ) -r $(dep_dirs ) $(compdb_dir ) compile_commands.json
37743817 $(RM ) $(test_bindir_programs )
0 commit comments