Git development
 help / color / mirror / Atom feed
From: Mike Hommey <mh@glandium.org>
To: git@vger.kernel.org
Cc: gitster@pobox.com, ps@pks.im, sandals@crustytoothpaste.net,
	Mike Hommey <mh@glandium.org>
Subject: [PATCH v5] move rust gitcore crate to a different subdirectory
Date: Thu, 17 Sep 2026 15:04:15 +0900	[thread overview]
Message-ID: <20260917060415.2986259-1-mh@glandium.org> (raw)
In-Reply-To: <xmqq5x0df19l.fsf@gitster.g>

Having `Cargo.toml` at the top-level of the repository implies that one
can run `cargo build` directly, but this doesn't produce anything useful
on its own.

Additionally, when including the git source as a submodule of a Rust
project, it prevents the git source from being included at all in the
crate package because cargo skips directories that contain a Cargo.toml,
assuming that everything in the directory is relevant to the crate.

Move all Rust-specific files into a dedicated `rust/` subdirectory.

Signed-off-by: Mike Hommey <mh@glandium.org>
---
 .gitignore                     |  4 ++--
 Makefile                       | 24 ++++++++++++------------
 ci/run-rust-checks.sh          |  6 +++---
 meson.build                    |  2 +-
 Cargo.toml => rust/Cargo.toml  |  0
 build.rs => rust/build.rs      |  0
 {src => rust}/cargo-meson.sh   |  0
 {src => rust}/meson.build      | 16 ++++++++--------
 {src => rust/src}/csum_file.rs |  0
 {src => rust/src}/hash.rs      |  0
 {src => rust/src}/lib.rs       |  0
 {src => rust/src}/loose.rs     |  0
 {src => rust/src}/varint.rs    |  0
 13 files changed, 26 insertions(+), 26 deletions(-)
 rename Cargo.toml => rust/Cargo.toml (100%)
 rename build.rs => rust/build.rs (100%)
 rename {src => rust}/cargo-meson.sh (100%)
 rename {src => rust}/meson.build (81%)
 rename {src => rust/src}/csum_file.rs (100%)
 rename {src => rust/src}/hash.rs (100%)
 rename {src => rust/src}/lib.rs (100%)
 rename {src => rust/src}/loose.rs (100%)
 rename {src => rust/src}/varint.rs (100%)

diff --git a/.gitignore b/.gitignore
index 4da58c6754..add6597643 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,4 @@
 /fuzz_corpora
-/target/
-/Cargo.lock
 /GIT-BUILD-DIR
 /GIT-BUILD-OPTIONS
 /GIT-CFLAGS
@@ -261,3 +259,5 @@ Release/
 /contrib/buildsystems/out
 /contrib/libgit-rs/target
 /contrib/libgit-sys/target
+/rust/target
+/rust/Cargo.lock
diff --git a/Makefile b/Makefile
index c649c93c51..67e74c30cc 100644
--- a/Makefile
+++ b/Makefile
@@ -959,7 +959,7 @@ RUST_LIB_NAME = gitcore.lib
 else
 RUST_LIB_NAME = libgitcore.a
 endif
-RUST_LIB = target$(if $(CARGO_BUILD_TARGET),/$(CARGO_BUILD_TARGET))/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME)
+RUST_LIB = rust/target$(if $(CARGO_BUILD_TARGET),/$(CARGO_BUILD_TARGET))/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME)
 endif
 
 GITLIBS = common-main.o $(LIB_FILE)
@@ -1571,11 +1571,11 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 
 UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
 
-RUST_SOURCES += src/csum_file.rs
-RUST_SOURCES += src/hash.rs
-RUST_SOURCES += src/lib.rs
-RUST_SOURCES += src/loose.rs
-RUST_SOURCES += src/varint.rs
+RUST_SOURCES += rust/src/csum_file.rs
+RUST_SOURCES += rust/src/hash.rs
+RUST_SOURCES += rust/src/lib.rs
+RUST_SOURCES += rust/src/loose.rs
+RUST_SOURCES += rust/src/varint.rs
 
 GIT-VERSION-FILE: FORCE
 	@OLD=$$(cat $@ 2>/dev/null || :) && \
@@ -3038,8 +3038,8 @@ $(LIB_FILE): $(LIB_OBJS)
 
 ifndef NO_RUST
 ifeq ($(RUST_TARGETS),)
-$(RUST_LIB): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)
-	$(QUIET_CARGO)cargo build $(CARGO_ARGS)
+$(RUST_LIB): rust/Cargo.toml $(RUST_SOURCES) $(LIB_FILE)
+	$(QUIET_CARGO)cargo build --manifest-path rust/Cargo.toml $(CARGO_ARGS)
 else
 ifneq ($(words $(RUST_TARGETS)),1)
 ifneq ($(uname_S),Darwin)
@@ -3047,9 +3047,9 @@ $(error Building universal Rust libraries requires macOS (lipo is not available
 endif
 endif
 
-RUST_MEMBER_LIBS = $(foreach target,$(RUST_TARGETS),target/$(target)/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME))
-$(RUST_MEMBER_LIBS): target/%/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)
-	$(QUIET_CARGO)cargo build $(CARGO_ARGS) --target $*
+RUST_MEMBER_LIBS = $(foreach target,$(RUST_TARGETS),rust/target/$(target)/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME))
+$(RUST_MEMBER_LIBS): rust/target/%/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME): rust/Cargo.toml $(RUST_SOURCES) $(LIB_FILE)
+	$(QUIET_CARGO)cargo build --manifest-path rust/Cargo.toml $(CARGO_ARGS) --target $*
 
 $(RUST_LIB): $(RUST_MEMBER_LIBS)
 	$(call mkdir_p_parent_template)
@@ -3913,7 +3913,7 @@ clean: profile-clean coverage-clean cocciclean
 	$(RM) $(FUZZ_PROGRAMS)
 	$(RM) $(SP_OBJ)
 	$(RM) $(HCC)
-	$(RM) -r Cargo.lock target/
+	$(RM) -r rust/Cargo.lock rust/target/
 	$(RM) version-def.h
 	$(RM) -r $(dep_dirs) $(compdb_dir) compile_commands.json
 	$(RM) $(test_bindir_programs)
diff --git a/ci/run-rust-checks.sh b/ci/run-rust-checks.sh
index b5ad9e8dc6..47fccc3a02 100755
--- a/ci/run-rust-checks.sh
+++ b/ci/run-rust-checks.sh
@@ -4,17 +4,17 @@
 
 set +x
 
-if ! group "Check Rust formatting" cargo fmt --all --check
+if ! group "Check Rust formatting" cargo fmt --manifest-path rust/Cargo.toml --all --check
 then
 	RET=1
 fi
 
-if ! group "Check for common Rust mistakes" cargo clippy --all-targets --all-features -- -Dwarnings
+if ! group "Check for common Rust mistakes" cargo clippy --manifest-path rust/Cargo.toml --all-targets --all-features -- -Dwarnings
 then
 	RET=1
 fi
 
-if ! group "Check for minimum required Rust version" cargo msrv verify
+if ! group "Check for minimum required Rust version" cargo msrv --path rust verify
 then
 	RET=1
 fi
diff --git a/meson.build b/meson.build
index 0a95d90d21..432e306b21 100644
--- a/meson.build
+++ b/meson.build
@@ -1795,7 +1795,7 @@ libgit_sources += version_def_h
 
 rust_option = get_option('rust')
 if rust_option.allowed()
-  subdir('src')
+  subdir('rust')
   libgit_c_args += '-DWITH_RUST'
 
   if host_machine.system() == 'windows'
diff --git a/Cargo.toml b/rust/Cargo.toml
similarity index 100%
rename from Cargo.toml
rename to rust/Cargo.toml
diff --git a/build.rs b/rust/build.rs
similarity index 100%
rename from build.rs
rename to rust/build.rs
diff --git a/src/cargo-meson.sh b/rust/cargo-meson.sh
similarity index 100%
rename from src/cargo-meson.sh
rename to rust/cargo-meson.sh
diff --git a/src/meson.build b/rust/meson.build
similarity index 81%
rename from src/meson.build
rename to rust/meson.build
index 41a4b231e6..4c617371a5 100644
--- a/src/meson.build
+++ b/rust/meson.build
@@ -1,9 +1,9 @@
 libgit_rs_sources = [
-  'csum_file.rs',
-  'hash.rs',
-  'lib.rs',
-  'loose.rs',
-  'varint.rs',
+  'src/csum_file.rs',
+  'src/hash.rs',
+  'src/lib.rs',
+  'src/loose.rs',
+  'src/varint.rs',
 ]
 
 # Unfortunately we must use a wrapper command to move the output file into the
@@ -13,7 +13,7 @@ libgit_rs_sources = [
 cargo_command = [
   shell,
   meson.current_source_dir() / 'cargo-meson.sh',
-  meson.project_source_root(),
+  meson.current_source_dir(),
   meson.current_build_dir(),
 ]
 if get_option('buildtype') == 'release'
@@ -22,7 +22,7 @@ endif
 
 libgit_rs = custom_target('git_rs',
   input: libgit_rs_sources + [
-    meson.project_source_root() / 'Cargo.toml',
+    meson.current_source_dir() / 'Cargo.toml',
   ],
   output: 'libgitcore.a',
   command: cargo_command,
@@ -35,7 +35,7 @@ if get_option('tests')
     args: [
       'test',
       '--manifest-path',
-      meson.project_source_root() / 'Cargo.toml',
+      meson.current_source_dir() / 'Cargo.toml',
       '--target-dir',
       meson.current_build_dir() / 'target',
     ],
diff --git a/src/csum_file.rs b/rust/src/csum_file.rs
similarity index 100%
rename from src/csum_file.rs
rename to rust/src/csum_file.rs
diff --git a/src/hash.rs b/rust/src/hash.rs
similarity index 100%
rename from src/hash.rs
rename to rust/src/hash.rs
diff --git a/src/lib.rs b/rust/src/lib.rs
similarity index 100%
rename from src/lib.rs
rename to rust/src/lib.rs
diff --git a/src/loose.rs b/rust/src/loose.rs
similarity index 100%
rename from src/loose.rs
rename to rust/src/loose.rs
diff --git a/src/varint.rs b/rust/src/varint.rs
similarity index 100%
rename from src/varint.rs
rename to rust/src/varint.rs
-- 
2.55.0.807.gc06c3eb732


  reply	other threads:[~2026-09-17  6:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-04 23:22 [RFC PATCH] Move rust gitcore crate to a different subdirectory Mike Hommey
2026-02-05  0:10 ` brian m. carlson
2026-02-05  1:45   ` Mike Hommey
2026-02-05  2:06     ` brian m. carlson
2026-02-05  4:55       ` Mike Hommey
2026-02-09 22:48 ` [PATCH v2] " Mike Hommey
2026-09-09  1:38   ` [PATCH v3] " Mike Hommey
2026-09-09 19:54     ` Junio C Hamano
2026-09-10 12:09       ` Mike Hommey
2026-09-09 21:13     ` brian m. carlson
2026-09-10 12:05       ` Mike Hommey
2026-09-10  6:27     ` Tuomas Ahola
2026-09-10 12:21       ` Junio C Hamano
2026-09-10 12:10     ` [PATCH v4] " Mike Hommey
2026-09-10 17:45       ` Junio C Hamano
2026-09-17  6:04         ` Mike Hommey [this message]
2026-09-18  8:20           ` [PATCH v5] move " Junio C Hamano
2026-09-18 15:02             ` Mike Hommey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260917060415.2986259-1-mh@glandium.org \
    --to=mh@glandium.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ps@pks.im \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox