Git fork

Makefile: introduce infrastructure to build internal Rust library

Introduce infrastructure to build the internal Rust library. This
mirrors the infrastructure we have added to Meson in the preceding
commit. Developers can enable the infrastructure by passing the new
`WITH_RUST` build toggle.

Inspired-by: Ezekiel Newren <ezekielnewren@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
e30c081c f2301be0

+40
+2
.gitignore
··· 1 1 /fuzz_corpora 2 + /target/ 3 + /Cargo.lock 2 4 /GIT-BUILD-DIR 3 5 /GIT-BUILD-OPTIONS 4 6 /GIT-CFLAGS
+37
Makefile
··· 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 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 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 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 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 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 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 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)
+1
shared.mak
··· 56 56 QUIET_MKDIR_P_PARENT = @echo ' ' MKDIR -p $(@D); 57 57 58 58 ## Used in "Makefile" 59 + QUIET_CARGO = @echo ' ' CARGO $@; 59 60 QUIET_CC = @echo ' ' CC $@; 60 61 QUIET_AR = @echo ' ' AR $@; 61 62 QUIET_LINK = @echo ' ' LINK $@;