@@ -417,6 +417,9 @@ include shared.mak
417417# Define LINK_FUZZ_PROGRAMS if you want `make all` to also build the fuzz test
418418# programs in oss-fuzz/.
419419#
420+ # Define INCLUDE_LIBGIT_RS if you want `make all` and `make test` to build and
421+ # test the Rust crates in contrib/libgit-sys and contrib/libgit-rs.
422+ #
420423# === Optional library: libintl ===
421424#
422425# Define NO_GETTEXT if you don't want Git output to be translated.
@@ -658,6 +661,8 @@ CURL_CONFIG = curl-config
658661GCOV = gcov
659662STRIP = strip
660663SPATCH = spatch
664+ LD = ld
665+ OBJCOPY = objcopy
661666
662667export TCL_PATH TCLTK_PATH
663668
@@ -676,6 +681,7 @@ FUZZ_OBJS =
676681FUZZ_PROGRAMS =
677682GIT_OBJS =
678683LIB_OBJS =
684+ LIBGIT_PUB_OBJS =
679685SCALAR_OBJS =
680686OBJECTS =
681687OTHER_PROGRAMS =
@@ -984,6 +990,8 @@ LIB_OBJS += combine-diff.o
984990LIB_OBJS += commit-graph.o
985991LIB_OBJS += commit-reach.o
986992LIB_OBJS += commit.o
993+ LIB_OBJS += common-exit.o
994+ LIB_OBJS += common-init.o
987995LIB_OBJS += compat/nonblock.o
988996LIB_OBJS += compat/obstack.o
989997LIB_OBJS += compat/terminal.o
@@ -2252,6 +2260,12 @@ ifdef WITH_BREAKING_CHANGES
22522260 BASIC_CFLAGS += -DWITH_BREAKING_CHANGES
22532261endif
22542262
2263+ ifdef INCLUDE_LIBGIT_RS
2264+ # Enable symbol hiding in contrib/libgit-sys/libgitpub.a without making
2265+ # us rebuild the whole tree every time we run a Rust build.
2266+ BASIC_CFLAGS += -fvisibility=hidden
2267+ endif
2268+
22552269ifeq ($(TCLTK_PATH ) ,)
22562270NO_TCLTK = NoThanks
22572271endif
@@ -2748,6 +2762,10 @@ OBJECTS += $(UNIT_TEST_OBJS)
27482762OBJECTS += $(CLAR_TEST_OBJS )
27492763OBJECTS += $(patsubst % ,$(UNIT_TEST_DIR ) /% .o,$(UNIT_TEST_PROGRAMS ) )
27502764
2765+ ifdef INCLUDE_LIBGIT_RS
2766+ OBJECTS += contrib/libgit-sys/public_symbol_export.o
2767+ endif
2768+
27512769ifndef NO_CURL
27522770 OBJECTS += http.o http-walker.o remote-curl.o
27532771endif
@@ -3743,6 +3761,10 @@ clean: profile-clean coverage-clean cocciclean
37433761 $(RM ) $(htmldocs ) .tar.gz $(manpages ) .tar.gz
37443762 $(MAKE ) -C Documentation/ clean
37453763 $(RM ) Documentation/GIT-EXCLUDED-PROGRAMS
3764+ $(RM ) -r contrib/libgit-sys/target contrib/libgit-rs/target
3765+ $(RM ) contrib/libgit-sys/partial_symbol_export.o
3766+ $(RM ) contrib/libgit-sys/hidden_symbol_export.o
3767+ $(RM ) contrib/libgit-sys/libgitpub.a
37463768ifndef NO_PERL
37473769 $(RM) -r perl/build/
37483770endif
@@ -3904,3 +3926,31 @@ $(CLAR_TEST_PROG): $(UNIT_TEST_DIR)/clar.suite $(CLAR_TEST_OBJS) $(GITLIBS) GIT-
39043926build-unit-tests : $(UNIT_TEST_PROGS ) $(CLAR_TEST_PROG )
39053927unit-tests : $(UNIT_TEST_PROGS ) $(CLAR_TEST_PROG ) t/helper/test-tool$X
39063928 $(MAKE ) -C t/ unit-tests
3929+
3930+ .PHONY : libgit-sys libgit-rs
3931+ libgit-sys libgit-rs :
3932+ $(QUIET ) (\
3933+ cd contrib/$@ && \
3934+ cargo build \
3935+ )
3936+ ifdef INCLUDE_LIBGIT_RS
3937+ all :: libgit-sys libgit-rs
3938+ endif
3939+
3940+ LIBGIT_PUB_OBJS += contrib/libgit-sys/public_symbol_export.o
3941+ LIBGIT_PUB_OBJS += libgit.a
3942+ LIBGIT_PUB_OBJS += reftable/libreftable.a
3943+ LIBGIT_PUB_OBJS += xdiff/lib.a
3944+
3945+ LIBGIT_PARTIAL_EXPORT = contrib/libgit-sys/partial_symbol_export.o
3946+
3947+ LIBGIT_HIDDEN_EXPORT = contrib/libgit-sys/hidden_symbol_export.o
3948+
3949+ $(LIBGIT_PARTIAL_EXPORT ) : $(LIBGIT_PUB_OBJS )
3950+ $(LD ) -r $^ -o $@
3951+
3952+ $(LIBGIT_HIDDEN_EXPORT ) : $(LIBGIT_PARTIAL_EXPORT )
3953+ $(OBJCOPY ) --localize-hidden $^ $@
3954+
3955+ contrib/libgit-sys/libgitpub.a : $(LIBGIT_HIDDEN_EXPORT )
3956+ $(AR ) $(ARFLAGS ) $@ $^
0 commit comments