Skip to content

Commit 596b34c

Browse files
committed
Merge branch 'ps/rust-balloon' into seen
* ps/rust-balloon: ci: enable Rust for breaking-changes jobs ci: convert "pedantic" job into full build with breaking changes BreakingChanges: announce Rust becoming mandatory rust: implement a test balloon via the "varint" subsystem help: report on whether or not Rust is enabled Makefile: introduce infrastructure to build internal Rust library meson: add infrastructure to build internal Rust library
2 parents a87c6a9 + 8c4dafb commit 596b34c

14 files changed

Lines changed: 240 additions & 31 deletions

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ jobs:
379379
- jobname: linux-breaking-changes
380380
cc: gcc
381381
image: ubuntu:rolling
382+
- jobname: fedora-breaking-changes-meson
383+
image: fedora:latest
382384
- jobname: linux-leaks
383385
image: ubuntu:rolling
384386
cc: gcc
@@ -396,8 +398,6 @@ jobs:
396398
# Supported until 2025-04-02.
397399
- jobname: linux32
398400
image: i386/ubuntu:focal
399-
- jobname: pedantic
400-
image: fedora:latest
401401
# A RHEL 8 compatible distro. Supported until 2029-05-31.
402402
- jobname: almalinux-8
403403
image: almalinux:8

.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

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ test:linux:
4545
- jobname: linux-breaking-changes
4646
image: ubuntu:20.04
4747
CC: gcc
48+
- jobname: fedora-breaking-changes-meson
49+
image: fedora:latest
4850
- jobname: linux-TEST-vars
4951
image: ubuntu:20.04
5052
CC: gcc
@@ -58,8 +60,6 @@ test:linux:
5860
- jobname: linux-asan-ubsan
5961
image: ubuntu:rolling
6062
CC: clang
61-
- jobname: pedantic
62-
image: fedora:latest
6363
- jobname: linux-musl-meson
6464
image: alpine:latest
6565
- jobname: linux32

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "git"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["staticlib"]
8+
9+
[dependencies]

Documentation/BreakingChanges.adoc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,42 @@ JGit, libgit2 and Gitoxide need to support it.
170170
useful advice about init.defaultBranch, 2020-12-11). The new name matches
171171
the default branch name used by many of the big Git forges.
172172

173+
* Git will require Rust as a mandatory part of the build process. While Git
174+
already started to adopt Rust in the Git 2.52, all parts written in Rust are
175+
optional for the time being. This includes:
176+
+
177+
** Subsystems that have an alternative implementation in Rust to test
178+
interoperability between our C and Rust codebase.
179+
** Newly written features that are not mission critical for a fully functional
180+
Git client.
181+
+
182+
These changes are meant as test balloons to allow distributors of Git to prepare
183+
for Rust becoming a mandatory part of the build process. There will be multiple
184+
milestones for the introduction of Rust:
185+
+
186+
1. Initially, with Git 2.52, support for Rust will be auto-detected by Rust and
187+
disabled in our Makefile so that the project can sort out the initial
188+
infrastructure.
189+
2. In Git 2.53, support for Rust will be made mandatory in case Git is compiled
190+
with breaking changes. Breaking changes can be enabled for Meson by saying
191+
`meson configure -Dbreaking_changes=true` and for Makefiles via `make
192+
WITH_BREAKING_CHANGES=YesPlease`. It will still be possible to compile with
193+
breaking changes, but explicitly disable Rust.
194+
3. In Git 2.54, both build systems will default-enable support for Rust so that
195+
builds will break if Rust is not available on the build host. The use of Rust
196+
can still be explicitly disabled via build flags.
197+
4. In Git 3.0, the build options will be removed and support for Rust is
198+
mandatory.
199+
+
200+
You can explicitly ask both Meson and our Makefile-based system to enable Rust
201+
by saying `meson configure -Drust=enabled` and `make WITH_RUST=YesPlease`,
202+
respectively.
203+
+
204+
The Git project will declare the last version before Git 3.0 to be a long-term
205+
support release that is maintained until alternate Rust backends like gcc-rs are
206+
able to build Git. The Git project may need to rely on distributions to help
207+
with identifying and backporting important bugfixes.
208+
173209
=== Removals
174210

175211
* Support for grafting commits has long been superseded by git-replace(1).

Makefile

Lines changed: 45 additions & 2 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 ===
@@ -918,6 +926,11 @@ TEST_SHELL_PATH = $(SHELL_PATH)
918926
LIB_FILE = libgit.a
919927
XDIFF_LIB = xdiff/lib.a
920928
REFTABLE_LIB = reftable/libreftable.a
929+
ifdef DEBUG
930+
RUST_LIB = target/debug/libgit.a
931+
else
932+
RUST_LIB = target/release/libgit.a
933+
endif
921934

922935
GENERATED_H += command-list.h
923936
GENERATED_H += config-list.h
@@ -1196,7 +1209,9 @@ LIB_OBJS += urlmatch.o
11961209
LIB_OBJS += usage.o
11971210
LIB_OBJS += userdiff.o
11981211
LIB_OBJS += utf8.o
1212+
ifndef WITH_RUST
11991213
LIB_OBJS += varint.o
1214+
endif
12001215
LIB_OBJS += version.o
12011216
LIB_OBJS += versioncmp.o
12021217
LIB_OBJS += walker.o
@@ -1388,8 +1403,12 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
13881403

13891404
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
13901405

1391-
# xdiff and reftable libs may in turn depend on what is in libgit.a
1392-
GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(LIB_FILE)
1406+
GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB)
1407+
ifdef WITH_RUST
1408+
GITLIBS += $(RUST_LIB)
1409+
endif
1410+
# Other libs may in turn depend on what is in libgit.a.
1411+
GITLIBS += $(LIB_FILE)
13931412
EXTLIBS =
13941413

13951414
GIT_USER_AGENT = git/$(GIT_VERSION)
@@ -1412,6 +1431,19 @@ BASIC_LDFLAGS =
14121431
ARFLAGS = rcs
14131432
PTHREAD_CFLAGS =
14141433

1434+
# Rust flags
1435+
CARGO_ARGS =
1436+
ifndef V
1437+
CARGO_ARGS += --quiet
1438+
endif
1439+
ifndef DEBUG
1440+
CARGO_ARGS += --release
1441+
endif
1442+
1443+
ifdef WITH_RUST
1444+
BASIC_CFLAGS += -DWITH_RUST
1445+
endif
1446+
14151447
# For the 'sparse' target
14161448
SPARSE_FLAGS ?= -std=gnu99 -D__STDC_NO_VLA__
14171449
SP_EXTRA_FLAGS =
@@ -2919,6 +2951,16 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
29192951
$(LIB_FILE): $(LIB_OBJS)
29202952
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
29212953

2954+
$(RUST_LIB): FORCE
2955+
@OLD_STAT="$$(stat $@ 2>/dev/null)"; \
2956+
cargo build $(CARGO_ARGS); \
2957+
if test $$? != 0 || test x"$$OLD_STAT" != x"$$(stat $@ 2>/dev/null)"; then \
2958+
echo ' ' CARGO $@; \
2959+
fi
2960+
2961+
.PHONY: rust
2962+
rust: $(RUST_LIB)
2963+
29222964
$(XDIFF_LIB): $(XDIFF_OBJS)
29232965
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
29242966

@@ -3769,6 +3811,7 @@ clean: profile-clean coverage-clean cocciclean
37693811
$(RM) $(FUZZ_PROGRAMS)
37703812
$(RM) $(SP_OBJ)
37713813
$(RM) $(HCC)
3814+
$(RM) -r target/ Cargo.lock
37723815
$(RM) version-def.h
37733816
$(RM) -r $(dep_dirs) $(compdb_dir) compile_commands.json
37743817
$(RM) $(test_bindir_programs)

ci/install-dependencies.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ alpine-*)
3131
;;
3232
fedora-*|almalinux-*)
3333
dnf -yq update >/dev/null &&
34-
dnf -yq install shadow-utils sudo make gcc findutils diffutils perl python3 gawk gettext zlib-devel expat-devel openssl-devel curl-devel pcre2-devel >/dev/null
34+
dnf -yq install shadow-utils sudo meson ninja pkg-config gcc findutils diffutils perl python3 gawk gettext zlib-devel expat-devel openssl-devel curl-devel pcre2-devel rustc >/dev/null
3535
;;
3636
ubuntu-*|i386/ubuntu-*|debian-*)
3737
# Required so that apt doesn't wait for user input on certain packages.
@@ -58,7 +58,7 @@ ubuntu-*|i386/ubuntu-*|debian-*)
5858
make libssl-dev libcurl4-openssl-dev libexpat-dev wget sudo default-jre \
5959
tcl tk gettext zlib1g-dev perl-modules liberror-perl libauthen-sasl-perl \
6060
libemail-valid-perl libio-pty-perl libio-socket-ssl-perl libnet-smtp-ssl-perl libdbd-sqlite3-perl libcgi-pm-perl \
61-
libsecret-1-dev libpcre2-dev meson ninja-build pkg-config \
61+
libsecret-1-dev libpcre2-dev meson ninja-build pkg-config cargo \
6262
${CC_PACKAGE:-${CC:-gcc}} $PYTHON_PACKAGE
6363

6464
case "$distro" in

ci/run-build-and-tests.sh

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
. ${0%/*}/lib.sh
77

8-
run_tests=t
9-
108
case "$jobname" in
11-
linux-breaking-changes)
9+
fedora-breaking-changes-musl|linux-breaking-changes)
1210
export WITH_BREAKING_CHANGES=YesPlease
11+
export WITH_RUST=YesPlease
12+
MESONFLAGS="$MESONFLAGS -Dbreaking_changes=true"
13+
MESONFLAGS="$MESONFLAGS -Drust=enabled"
1314
;;
1415
linux-TEST-vars)
1516
export OPENSSL_SHA1_UNSAFE=YesPlease
@@ -35,12 +36,6 @@ linux-sha256)
3536
linux-reftable|linux-reftable-leaks|osx-reftable)
3637
export GIT_TEST_DEFAULT_REF_FORMAT=reftable
3738
;;
38-
pedantic)
39-
# Don't run the tests; we only care about whether Git can be
40-
# built.
41-
export DEVOPTS=pedantic
42-
run_tests=
43-
;;
4439
esac
4540

4641
case "$jobname" in
@@ -53,21 +48,15 @@ case "$jobname" in
5348
-Dtest_output_directory="${TEST_OUTPUT_DIRECTORY:-$(pwd)/t}" \
5449
$MESONFLAGS
5550
group "Build" meson compile -C build --
56-
if test -n "$run_tests"
57-
then
58-
group "Run tests" meson test -C build --print-errorlogs --test-args="$GIT_TEST_OPTS" || (
59-
./t/aggregate-results.sh "${TEST_OUTPUT_DIRECTORY:-t}/test-results"
60-
handle_failed_tests
61-
)
62-
fi
51+
group "Run tests" meson test -C build --print-errorlogs --test-args="$GIT_TEST_OPTS" || (
52+
./t/aggregate-results.sh "${TEST_OUTPUT_DIRECTORY:-t}/test-results"
53+
handle_failed_tests
54+
)
6355
;;
6456
*)
6557
group Build make
66-
if test -n "$run_tests"
67-
then
68-
group "Run tests" make test ||
69-
handle_failed_tests
70-
fi
58+
group "Run tests" make test ||
59+
handle_failed_tests
7160
;;
7261
esac
7362

help.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,12 @@ void get_version_info(struct strbuf *buf, int show_build_options)
791791
strbuf_addf(buf, "shell-path: %s\n", SHELL_PATH);
792792
/* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
793793

794+
#if defined WITH_RUST
795+
strbuf_addstr(buf, "rust: enabled\n");
796+
#else
797+
strbuf_addstr(buf, "rust: disabled\n");
798+
#endif
799+
794800
if (fsmonitor_ipc__is_supported())
795801
strbuf_addstr(buf, "feature: fsmonitor--daemon\n");
796802
#if defined LIBCURL_VERSION

meson.build

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,6 @@ libgit_sources = [
522522
'usage.c',
523523
'userdiff.c',
524524
'utf8.c',
525-
'varint.c',
526525
'version.c',
527526
'versioncmp.c',
528527
'walker.c',
@@ -1703,8 +1702,21 @@ version_def_h = custom_target(
17031702
)
17041703
libgit_sources += version_def_h
17051704

1705+
libgit_libraries = [ ]
1706+
1707+
rust_available = add_languages('rust', native: false, required: get_option('rust'))
1708+
rust_option = get_option('rust').disable_auto_if(not rust_available)
1709+
if rust_option.allowed()
1710+
subdir('src')
1711+
libgit_c_args += '-DWITH_RUST'
1712+
else
1713+
libgit_sources += [
1714+
'varint.c',
1715+
]
1716+
endif
1717+
17061718
libgit = declare_dependency(
1707-
link_with: static_library('git',
1719+
link_with: libgit_libraries + static_library('git',
17081720
sources: libgit_sources,
17091721
c_args: libgit_c_args + [
17101722
'-DGIT_VERSION_H="' + version_def_h.full_path() + '"',
@@ -2240,6 +2252,7 @@ summary({
22402252
'pcre2': pcre2,
22412253
'perl': perl_features_enabled,
22422254
'python': target_python.found(),
2255+
'rust': rust_option.allowed(),
22432256
}, section: 'Auto-detected features', bool_yn: true)
22442257

22452258
summary({

0 commit comments

Comments
 (0)