@@ -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 =
@@ -920,6 +929,108 @@ TEST_SHELL_PATH = $(SHELL_PATH)
920929LIB_FILE = libgit.a
921930XDIFF_LIB = xdiff/lib.a
922931REFTABLE_LIB = reftable/libreftable.a
932+ ifdef DEBUG
933+ RUST_LIB = target/debug/libgitcore.a
934+ else
935+ RUST_LIB = target/release/libgitcore.a
936+ endif
937+
938+ # xdiff and reftable libs may in turn depend on what is in libgit.a
939+ GITLIBS = common-main.o $(LIB_FILE ) $(XDIFF_LIB ) $(REFTABLE_LIB ) $(LIB_FILE )
940+ EXTLIBS =
941+
942+ GIT_USER_AGENT = git/$(GIT_VERSION )
943+
944+ ifeq ($(wildcard sha1collisiondetection/lib/sha1.h) ,sha1collisiondetection/lib/sha1.h)
945+ DC_SHA1_SUBMODULE = auto
946+ endif
947+
948+ # Set CFLAGS, LDFLAGS and other *FLAGS variables. These might be
949+ # tweaked by config.* below as well as the command-line, both of
950+ # which'll override these defaults.
951+ # Older versions of GCC may require adding "-std=gnu99" at the end.
952+ CFLAGS = -g -O2 -Wall
953+ LDFLAGS =
954+ CC_LD_DYNPATH = -Wl,-rpath,
955+ BASIC_CFLAGS = -I.
956+ BASIC_LDFLAGS =
957+
958+ # library flags
959+ ARFLAGS = rcs
960+ PTHREAD_CFLAGS =
961+
962+ # Rust flags
963+ CARGO_ARGS =
964+ ifndef V
965+ CARGO_ARGS += --quiet
966+ endif
967+ ifndef DEBUG
968+ CARGO_ARGS += --release
969+ endif
970+
971+ # For the 'sparse' target
972+ SPARSE_FLAGS ?= -std=gnu99 -D__STDC_NO_VLA__
973+ SP_EXTRA_FLAGS =
974+
975+ # For informing GIT-BUILD-OPTIONS of the SANITIZE=leak,address targets
976+ SANITIZE_LEAK =
977+ SANITIZE_ADDRESS =
978+
979+ # For the 'coccicheck' target
980+ SPATCH_INCLUDE_FLAGS = --all-includes
981+ SPATCH_FLAGS =
982+ SPATCH_TEST_FLAGS =
983+
984+ # If *.o files are present, have "coccicheck" depend on them, with
985+ # COMPUTE_HEADER_DEPENDENCIES this will speed up the common-case of
986+ # only needing to re-generate coccicheck results for the users of a
987+ # given API if it's changed, and not all files in the project. If
988+ # COMPUTE_HEADER_DEPENDENCIES=no this will be unset too.
989+ SPATCH_USE_O_DEPENDENCIES = YesPlease
990+
991+ # Set SPATCH_CONCAT_COCCI to concatenate the contrib/cocci/*.cocci
992+ # files into a single contrib/cocci/ALL.cocci before running
993+ # "coccicheck".
994+ #
995+ # Pros:
996+ #
997+ # - Speeds up a one-shot run of "make coccicheck", as we won't have to
998+ # parse *.[ch] files N times for the N *.cocci rules
999+ #
1000+ # Cons:
1001+ #
1002+ # - Will make incremental development of *.cocci slower, as
1003+ # e.g. changing strbuf.cocci will re-run all *.cocci.
1004+ #
1005+ # - Makes error and performance analysis harder, as rules will be
1006+ # applied from a monolithic ALL.cocci, rather than
1007+ # e.g. strbuf.cocci. To work around this either undefine this, or
1008+ # generate a specific patch, e.g. this will always use strbuf.cocci,
1009+ # not ALL.cocci:
1010+ #
1011+ # make contrib/coccinelle/strbuf.cocci.patch
1012+ SPATCH_CONCAT_COCCI = YesPlease
1013+
1014+ # Rebuild 'coccicheck' if $(SPATCH), its flags etc. change
1015+ TRACK_SPATCH_DEFINES =
1016+ TRACK_SPATCH_DEFINES += $(SPATCH )
1017+ TRACK_SPATCH_DEFINES += $(SPATCH_INCLUDE_FLAGS )
1018+ TRACK_SPATCH_DEFINES += $(SPATCH_FLAGS )
1019+ TRACK_SPATCH_DEFINES += $(SPATCH_TEST_FLAGS )
1020+ GIT-SPATCH-DEFINES : FORCE
1021+ @FLAGS=' $(TRACK_SPATCH_DEFINES)' ; \
1022+ if test x" $$ FLAGS" ! = x" ` cat GIT-SPATCH-DEFINES 2> /dev/null` " ; then \
1023+ echo >&2 " * new spatch flags" ; \
1024+ echo " $$ FLAGS" > GIT-SPATCH-DEFINES; \
1025+ fi
1026+
1027+ include config.mak.uname
1028+ -include config.mak.autogen
1029+ -include config.mak
1030+
1031+ ifdef DEVELOPER
1032+ include config.mak.dev
1033+ endif
9231034
9241035GENERATED_H += command-list.h
9251036GENERATED_H += config-list.h
@@ -1198,7 +1309,9 @@ LIB_OBJS += urlmatch.o
11981309LIB_OBJS += usage.o
11991310LIB_OBJS += userdiff.o
12001311LIB_OBJS += utf8.o
1312+ ifndef WITH_RUST
12011313LIB_OBJS += varint.o
1314+ endif
12021315LIB_OBJS += version.o
12031316LIB_OBJS += versioncmp.o
12041317LIB_OBJS += walker.o
@@ -1390,93 +1503,8 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
13901503
13911504UNIT_TEST_OBJS += $(UNIT_TEST_DIR ) /test-lib.o
13921505
1393- # xdiff and reftable libs may in turn depend on what is in libgit.a
1394- GITLIBS = common-main.o $(LIB_FILE ) $(XDIFF_LIB ) $(REFTABLE_LIB ) $(LIB_FILE )
1395- EXTLIBS =
1396-
1397- GIT_USER_AGENT = git/$(GIT_VERSION )
1398-
1399- ifeq ($(wildcard sha1collisiondetection/lib/sha1.h) ,sha1collisiondetection/lib/sha1.h)
1400- DC_SHA1_SUBMODULE = auto
1401- endif
1402-
1403- # Set CFLAGS, LDFLAGS and other *FLAGS variables. These might be
1404- # tweaked by config.* below as well as the command-line, both of
1405- # which'll override these defaults.
1406- # Older versions of GCC may require adding "-std=gnu99" at the end.
1407- CFLAGS = -g -O2 -Wall
1408- LDFLAGS =
1409- CC_LD_DYNPATH = -Wl,-rpath,
1410- BASIC_CFLAGS = -I.
1411- BASIC_LDFLAGS =
1412-
1413- # library flags
1414- ARFLAGS = rcs
1415- PTHREAD_CFLAGS =
1416-
1417- # For the 'sparse' target
1418- SPARSE_FLAGS ?= -std=gnu99 -D__STDC_NO_VLA__
1419- SP_EXTRA_FLAGS =
1420-
1421- # For informing GIT-BUILD-OPTIONS of the SANITIZE=leak,address targets
1422- SANITIZE_LEAK =
1423- SANITIZE_ADDRESS =
1424-
1425- # For the 'coccicheck' target
1426- SPATCH_INCLUDE_FLAGS = --all-includes
1427- SPATCH_FLAGS =
1428- SPATCH_TEST_FLAGS =
1429-
1430- # If *.o files are present, have "coccicheck" depend on them, with
1431- # COMPUTE_HEADER_DEPENDENCIES this will speed up the common-case of
1432- # only needing to re-generate coccicheck results for the users of a
1433- # given API if it's changed, and not all files in the project. If
1434- # COMPUTE_HEADER_DEPENDENCIES=no this will be unset too.
1435- SPATCH_USE_O_DEPENDENCIES = YesPlease
1436-
1437- # Set SPATCH_CONCAT_COCCI to concatenate the contrib/cocci/*.cocci
1438- # files into a single contrib/cocci/ALL.cocci before running
1439- # "coccicheck".
1440- #
1441- # Pros:
1442- #
1443- # - Speeds up a one-shot run of "make coccicheck", as we won't have to
1444- # parse *.[ch] files N times for the N *.cocci rules
1445- #
1446- # Cons:
1447- #
1448- # - Will make incremental development of *.cocci slower, as
1449- # e.g. changing strbuf.cocci will re-run all *.cocci.
1450- #
1451- # - Makes error and performance analysis harder, as rules will be
1452- # applied from a monolithic ALL.cocci, rather than
1453- # e.g. strbuf.cocci. To work around this either undefine this, or
1454- # generate a specific patch, e.g. this will always use strbuf.cocci,
1455- # not ALL.cocci:
1456- #
1457- # make contrib/coccinelle/strbuf.cocci.patch
1458- SPATCH_CONCAT_COCCI = YesPlease
1459-
1460- # Rebuild 'coccicheck' if $(SPATCH), its flags etc. change
1461- TRACK_SPATCH_DEFINES =
1462- TRACK_SPATCH_DEFINES += $(SPATCH )
1463- TRACK_SPATCH_DEFINES += $(SPATCH_INCLUDE_FLAGS )
1464- TRACK_SPATCH_DEFINES += $(SPATCH_FLAGS )
1465- TRACK_SPATCH_DEFINES += $(SPATCH_TEST_FLAGS )
1466- GIT-SPATCH-DEFINES : FORCE
1467- @FLAGS=' $(TRACK_SPATCH_DEFINES)' ; \
1468- if test x" $$ FLAGS" ! = x" ` cat GIT-SPATCH-DEFINES 2> /dev/null` " ; then \
1469- echo >&2 " * new spatch flags" ; \
1470- echo " $$ FLAGS" > GIT-SPATCH-DEFINES; \
1471- fi
1472-
1473- include config.mak.uname
1474- -include config.mak.autogen
1475- -include config.mak
1476-
1477- ifdef DEVELOPER
1478- include config.mak.dev
1479- endif
1506+ RUST_SOURCES += src/lib.rs
1507+ RUST_SOURCES += src/varint.rs
14801508
14811509GIT-VERSION-FILE : FORCE
14821510 @OLD=$$(cat $@ 2>/dev/null || : ) && \
@@ -1507,6 +1535,11 @@ endif
15071535ALL_CFLAGS = $(DEVELOPER_CFLAGS ) $(CPPFLAGS ) $(CFLAGS ) $(CFLAGS_APPEND )
15081536ALL_LDFLAGS = $(LDFLAGS ) $(LDFLAGS_APPEND )
15091537
1538+ ifdef WITH_RUST
1539+ BASIC_CFLAGS += -DWITH_RUST
1540+ GITLIBS += $(RUST_LIB )
1541+ endif
1542+
15101543ifdef SANITIZE
15111544SANITIZERS := $(foreach flag,$(subst $(comma ) ,$(space ) ,$(SANITIZE ) ) ,$(flag ) )
15121545BASIC_CFLAGS += -fsanitize=$(SANITIZE ) -fno-sanitize-recover=$(SANITIZE )
@@ -2921,6 +2954,12 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
29212954$(LIB_FILE ) : $(LIB_OBJS )
29222955 $(QUIET_AR )$(RM ) $@ && $(AR ) $(ARFLAGS ) $@ $^
29232956
2957+ $(RUST_LIB ) : Cargo.toml $(RUST_SOURCES )
2958+ $(QUIET_CARGO ) cargo build $(CARGO_ARGS )
2959+
2960+ .PHONY : rust
2961+ rust : $(RUST_LIB )
2962+
29242963$(XDIFF_LIB ) : $(XDIFF_OBJS )
29252964 $(QUIET_AR )$(RM ) $@ && $(AR ) $(ARFLAGS ) $@ $^
29262965
@@ -3771,6 +3810,7 @@ clean: profile-clean coverage-clean cocciclean
37713810 $(RM ) $(FUZZ_PROGRAMS )
37723811 $(RM ) $(SP_OBJ )
37733812 $(RM ) $(HCC )
3813+ $(RM ) -r Cargo.lock target/
37743814 $(RM ) version-def.h
37753815 $(RM ) -r $(dep_dirs ) $(compdb_dir ) compile_commands.json
37763816 $(RM ) $(test_bindir_programs )
0 commit comments