Re: [PATCH RFC v2 2/7] Makefile: introduce infrastructure to build internal Rust library

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Sep 5, 2025 at 4:51 AM Patrick Steinhardt <ps@xxxxxx> wrote:
>
> 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.

So, again, this makes it not a test balloon, which reduces the amount
of notice distributors will get.  I'd prefer a WITHOUT_RUST build
toggle, so they get as much notice as possible.

> Signed-off-by: Patrick Steinhardt <ps@xxxxxx>
> ---
>  .gitignore |  2 ++
>  Cargo.toml |  9 +++++++++
>  Makefile   | 45 +++++++++++++++++++++++++++++++++++++++++++--
>  3 files changed, 54 insertions(+), 2 deletions(-)
>
> diff --git a/.gitignore b/.gitignore
> index 1803023427..0833453cf6 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -1,4 +1,6 @@
>  /fuzz_corpora
> +/target/
> +/Cargo.lock
>  /GIT-BUILD-DIR
>  /GIT-BUILD-OPTIONS
>  /GIT-CFLAGS
> diff --git a/Cargo.toml b/Cargo.toml
> new file mode 100644
> index 0000000000..17a4f4da0c
> --- /dev/null
> +++ b/Cargo.toml
> @@ -0,0 +1,9 @@
> +[package]
> +name = "git"
> +version = "0.1.0"
> +edition = "2021"
> +
> +[lib]
> +crate-type = ["staticlib"]
> +
> +[dependencies]
> diff --git a/Makefile b/Makefile
> index 555b7f4dc3..e7b3c8e57b 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -483,6 +483,14 @@ include shared.mak
>  # Define LIBPCREDIR=/foo/bar if your PCRE header and library files are
>  # in /foo/bar/include and /foo/bar/lib directories.
>  #
> +# == Optional Rust support ==
> +#
> +# Define WITH_RUST if you want to include features and subsystems written in
> +# Rust into Git. For now, Rust is still an optional feature of the build
> +# process. With Git 3.0 though, Rust will always be enabled.
> +#
> +# Building Rust code requires Cargo.
> +#
>  # == SHA-1 and SHA-256 defines ==
>  #
>  # === SHA-1 backend ===
> @@ -918,6 +926,11 @@ TEST_SHELL_PATH = $(SHELL_PATH)
>  LIB_FILE = libgit.a
>  XDIFF_LIB = xdiff/lib.a
>  REFTABLE_LIB = reftable/libreftable.a
> +ifdef DEBUG
> +RUST_LIB = target/debug/libgit.a
> +else
> +RUST_LIB = target/release/libgit.a
> +endif
>
>  GENERATED_H += command-list.h
>  GENERATED_H += config-list.h
> @@ -1387,8 +1400,12 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
>
>  UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
>
> -# xdiff and reftable libs may in turn depend on what is in libgit.a
> -GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(LIB_FILE)
> +GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB)
> +ifdef WITH_RUST
> +GITLIBS += $(RUST_LIB)
> +endif
> +# Other libs may in turn depend on what is in libgit.a.
> +GITLIBS += $(LIB_FILE)
>  EXTLIBS =
>
>  GIT_USER_AGENT = git/$(GIT_VERSION)
> @@ -1411,6 +1428,19 @@ BASIC_LDFLAGS =
>  ARFLAGS = rcs
>  PTHREAD_CFLAGS =
>
> +# Rust flags
> +CARGO_ARGS =
> +ifndef V
> +CARGO_ARGS += --quiet
> +endif
> +ifndef DEBUG
> +CARGO_ARGS += --release
> +endif
> +
> +ifdef WITH_RUST
> +BASIC_CFLAGS += -DWITH_RUST
> +endif
> +
>  # For the 'sparse' target
>  SPARSE_FLAGS ?= -std=gnu99 -D__STDC_NO_VLA__
>  SP_EXTRA_FLAGS =
> @@ -2918,6 +2948,16 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
>  $(LIB_FILE): $(LIB_OBJS)
>         $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
>
> +$(RUST_LIB): FORCE
> +       @OLD_STAT="$$(stat $@ 2>/dev/null)"; \
> +           cargo build $(CARGO_ARGS); \
> +           if test $$? != 0 || test x"$$OLD_STAT" != x"$$(stat $@ 2>/dev/null)"; then \
> +               echo '   ' CARGO $@; \
> +           fi
> +
> +.PHONY: rust
> +rust: $(RUST_LIB)
> +
>  $(XDIFF_LIB): $(XDIFF_OBJS)
>         $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
>
> @@ -3768,6 +3808,7 @@ clean: profile-clean coverage-clean cocciclean
>         $(RM) $(FUZZ_PROGRAMS)
>         $(RM) $(SP_OBJ)
>         $(RM) $(HCC)
> +       $(RM) -r target/ Cargo.lock
>         $(RM) version-def.h
>         $(RM) -r $(dep_dirs) $(compdb_dir) compile_commands.json
>         $(RM) $(test_bindir_programs)
>
> --
> 2.51.0.417.g1ba7204a04.dirty

Johannes provided some additional tooling (an extra library to
download from git-for-windows) that was needed for building and
linking against Rust on Windows, which Ezekiel incorporated into his
series.  Is that not needed here for some reason, or are we just not
discovering that it's needed since you haven't created a test balloon
yet?





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux