@@ -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 ===
@@ -683,6 +691,7 @@ OBJECTS =
683691OTHER_PROGRAMS =
684692PROGRAM_OBJS =
685693PROGRAMS =
694+ RUST_SOURCES =
686695EXCLUDED_PROGRAMS =
687696SCRIPT_PERL =
688697SCRIPT_PYTHON =
@@ -918,6 +927,11 @@ TEST_SHELL_PATH = $(SHELL_PATH)
918927LIB_FILE = libgit.a
919928XDIFF_LIB = xdiff/lib.a
920929REFTABLE_LIB = reftable/libreftable.a
930+ ifdef DEBUG
931+ RUST_LIB = target/debug/libgitcore.a
932+ else
933+ RUST_LIB = target/release/libgitcore.a
934+ endif
921935
922936# xdiff and reftable libs may in turn depend on what is in libgit.a
923937GITLIBS = common-main.o $(LIB_FILE ) $(XDIFF_LIB ) $(REFTABLE_LIB ) $(LIB_FILE )
@@ -943,6 +957,15 @@ BASIC_LDFLAGS =
943957ARFLAGS = rcs
944958PTHREAD_CFLAGS =
945959
960+ # Rust flags
961+ CARGO_ARGS =
962+ ifndef V
963+ CARGO_ARGS += --quiet
964+ endif
965+ ifndef DEBUG
966+ CARGO_ARGS += --release
967+ endif
968+
946969# For the 'sparse' target
947970SPARSE_FLAGS ?= -std=gnu99 -D__STDC_NO_VLA__
948971SP_EXTRA_FLAGS =
@@ -1475,6 +1498,8 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
14751498
14761499UNIT_TEST_OBJS += $(UNIT_TEST_DIR ) /test-lib.o
14771500
1501+ RUST_SOURCES += src/lib.rs
1502+
14781503GIT-VERSION-FILE : FORCE
14791504 @OLD=$$(cat $@ 2>/dev/null || : ) && \
14801505 $(call version_gen,"$(shell pwd) ",GIT-VERSION-FILE.in,$@ ) && \
@@ -1504,6 +1529,11 @@ endif
15041529ALL_CFLAGS = $(DEVELOPER_CFLAGS ) $(CPPFLAGS ) $(CFLAGS ) $(CFLAGS_APPEND )
15051530ALL_LDFLAGS = $(LDFLAGS ) $(LDFLAGS_APPEND )
15061531
1532+ ifdef WITH_RUST
1533+ BASIC_CFLAGS += -DWITH_RUST
1534+ GITLIBS += $(RUST_LIB )
1535+ endif
1536+
15071537ifdef SANITIZE
15081538SANITIZERS := $(foreach flag,$(subst $(comma ) ,$(space ) ,$(SANITIZE ) ) ,$(flag ) )
15091539BASIC_CFLAGS += -fsanitize=$(SANITIZE ) -fno-sanitize-recover=$(SANITIZE )
@@ -2918,6 +2948,12 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
29182948$(LIB_FILE ) : $(LIB_OBJS )
29192949 $(QUIET_AR )$(RM ) $@ && $(AR ) $(ARFLAGS ) $@ $^
29202950
2951+ $(RUST_LIB ) : Cargo.toml $(RUST_SOURCES )
2952+ $(QUIET_CARGO ) cargo build $(CARGO_ARGS )
2953+
2954+ .PHONY : rust
2955+ rust : $(RUST_LIB )
2956+
29212957$(XDIFF_LIB ) : $(XDIFF_OBJS )
29222958 $(QUIET_AR )$(RM ) $@ && $(AR ) $(ARFLAGS ) $@ $^
29232959
@@ -3768,6 +3804,7 @@ clean: profile-clean coverage-clean cocciclean
37683804 $(RM ) $(FUZZ_PROGRAMS )
37693805 $(RM ) $(SP_OBJ )
37703806 $(RM ) $(HCC )
3807+ $(RM ) -r Cargo.lock target/
37713808 $(RM ) version-def.h
37723809 $(RM ) -r $(dep_dirs ) $(compdb_dir ) compile_commands.json
37733810 $(RM ) $(test_bindir_programs )
0 commit comments