@@ -483,6 +483,14 @@ include shared.mak
483
483
# Define LIBPCREDIR=/foo/bar if your PCRE header and library files are
484
484
# in /foo/bar/include and /foo/bar/lib directories.
485
485
#
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
+ #
486
494
# == SHA-1 and SHA-256 defines ==
487
495
#
488
496
# === SHA-1 backend ===
@@ -683,6 +691,7 @@ OBJECTS =
683
691
OTHER_PROGRAMS =
684
692
PROGRAM_OBJS =
685
693
PROGRAMS =
694
+ RUST_SOURCES =
686
695
EXCLUDED_PROGRAMS =
687
696
SCRIPT_PERL =
688
697
SCRIPT_PYTHON =
@@ -918,6 +927,11 @@ TEST_SHELL_PATH = $(SHELL_PATH)
918
927
LIB_FILE = libgit.a
919
928
XDIFF_LIB = xdiff/lib.a
920
929
REFTABLE_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
921
935
922
936
# xdiff and reftable libs may in turn depend on what is in libgit.a
923
937
GITLIBS = common-main.o $(LIB_FILE ) $(XDIFF_LIB ) $(REFTABLE_LIB ) $(LIB_FILE )
@@ -943,6 +957,15 @@ BASIC_LDFLAGS =
943
957
ARFLAGS = rcs
944
958
PTHREAD_CFLAGS =
945
959
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
+
946
969
# For the 'sparse' target
947
970
SPARSE_FLAGS ?= -std=gnu99 -D__STDC_NO_VLA__
948
971
SP_EXTRA_FLAGS =
@@ -1475,6 +1498,8 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
1475
1498
1476
1499
UNIT_TEST_OBJS += $(UNIT_TEST_DIR ) /test-lib.o
1477
1500
1501
+ RUST_SOURCES += src/lib.rs
1502
+
1478
1503
GIT-VERSION-FILE : FORCE
1479
1504
@OLD=$$(cat $@ 2>/dev/null || : ) && \
1480
1505
$(call version_gen,"$(shell pwd) ",GIT-VERSION-FILE.in,$@ ) && \
@@ -1504,6 +1529,11 @@ endif
1504
1529
ALL_CFLAGS = $(DEVELOPER_CFLAGS ) $(CPPFLAGS ) $(CFLAGS ) $(CFLAGS_APPEND )
1505
1530
ALL_LDFLAGS = $(LDFLAGS ) $(LDFLAGS_APPEND )
1506
1531
1532
+ ifdef WITH_RUST
1533
+ BASIC_CFLAGS += -DWITH_RUST
1534
+ GITLIBS += $(RUST_LIB )
1535
+ endif
1536
+
1507
1537
ifdef SANITIZE
1508
1538
SANITIZERS := $(foreach flag,$(subst $(comma ) ,$(space ) ,$(SANITIZE ) ) ,$(flag ) )
1509
1539
BASIC_CFLAGS += -fsanitize=$(SANITIZE ) -fno-sanitize-recover=$(SANITIZE )
@@ -2918,6 +2948,12 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
2918
2948
$(LIB_FILE ) : $(LIB_OBJS )
2919
2949
$(QUIET_AR )$(RM ) $@ && $(AR ) $(ARFLAGS ) $@ $^
2920
2950
2951
+ $(RUST_LIB ) : Cargo.toml $(RUST_SOURCES )
2952
+ $(QUIET_CARGO ) cargo build $(CARGO_ARGS )
2953
+
2954
+ .PHONY : rust
2955
+ rust : $(RUST_LIB )
2956
+
2921
2957
$(XDIFF_LIB ) : $(XDIFF_OBJS )
2922
2958
$(QUIET_AR )$(RM ) $@ && $(AR ) $(ARFLAGS ) $@ $^
2923
2959
@@ -3768,6 +3804,7 @@ clean: profile-clean coverage-clean cocciclean
3768
3804
$(RM ) $(FUZZ_PROGRAMS )
3769
3805
$(RM ) $(SP_OBJ )
3770
3806
$(RM ) $(HCC )
3807
+ $(RM ) -r Cargo.lock target/
3771
3808
$(RM ) version-def.h
3772
3809
$(RM ) -r $(dep_dirs ) $(compdb_dir ) compile_commands.json
3773
3810
$(RM ) $(test_bindir_programs )
0 commit comments