Skip to content

Commit e30c081

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f2301be commit e30c081

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/fuzz_corpora
2+
/target/
3+
/Cargo.lock
24
/GIT-BUILD-DIR
35
/GIT-BUILD-OPTIONS
46
/GIT-CFLAGS

Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 =
683691
OTHER_PROGRAMS =
684692
PROGRAM_OBJS =
685693
PROGRAMS =
694+
RUST_SOURCES =
686695
EXCLUDED_PROGRAMS =
687696
SCRIPT_PERL =
688697
SCRIPT_PYTHON =
@@ -918,6 +927,11 @@ TEST_SHELL_PATH = $(SHELL_PATH)
918927
LIB_FILE = libgit.a
919928
XDIFF_LIB = xdiff/lib.a
920929
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
921935

922936
# xdiff and reftable libs may in turn depend on what is in libgit.a
923937
GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(LIB_FILE)
@@ -943,6 +957,15 @@ BASIC_LDFLAGS =
943957
ARFLAGS = rcs
944958
PTHREAD_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
947970
SPARSE_FLAGS ?= -std=gnu99 -D__STDC_NO_VLA__
948971
SP_EXTRA_FLAGS =
@@ -1475,6 +1498,8 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
14751498

14761499
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
14771500

1501+
RUST_SOURCES += src/lib.rs
1502+
14781503
GIT-VERSION-FILE: FORCE
14791504
@OLD=$$(cat $@ 2>/dev/null || :) && \
14801505
$(call version_gen,"$(shell pwd)",GIT-VERSION-FILE.in,$@) && \
@@ -1504,6 +1529,11 @@ endif
15041529
ALL_CFLAGS = $(DEVELOPER_CFLAGS) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_APPEND)
15051530
ALL_LDFLAGS = $(LDFLAGS) $(LDFLAGS_APPEND)
15061531

1532+
ifdef WITH_RUST
1533+
BASIC_CFLAGS += -DWITH_RUST
1534+
GITLIBS += $(RUST_LIB)
1535+
endif
1536+
15071537
ifdef SANITIZE
15081538
SANITIZERS := $(foreach flag,$(subst $(comma),$(space),$(SANITIZE)),$(flag))
15091539
BASIC_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)

shared.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ ifndef V
5656
QUIET_MKDIR_P_PARENT = @echo ' ' MKDIR -p $(@D);
5757

5858
## Used in "Makefile"
59+
QUIET_CARGO = @echo ' ' CARGO $@;
5960
QUIET_CC = @echo ' ' CC $@;
6061
QUIET_AR = @echo ' ' AR $@;
6162
QUIET_LINK = @echo ' ' LINK $@;

0 commit comments

Comments
 (0)