public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] Move rust gitcore crate to a different subdirectory
@ 2026-02-04 23:22 Mike Hommey
  2026-02-05  0:10 ` brian m. carlson
  2026-02-09 22:48 ` [PATCH v2] " Mike Hommey
  0 siblings, 2 replies; 6+ messages in thread
From: Mike Hommey @ 2026-02-04 23:22 UTC (permalink / raw)
  To: git; +Cc: gitster, ps, Mike Hommey

While `src/` is the default directory convention for Rust projects, it
is too generic in the context of a multi-language project that is barely
starting to (optionally) use Rust code.

Additionally, 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.

Moving all Rust-specific files into a dedicated `rust/` subdirectory
makes things clearer.

---

The above is a post hoc justification. I do think it makes sense to do,
but I should mention my real immediate motivation.

git-cinnabar, a git remote helper used to talk to Mercurial servers, is
a project based on libgit (the C parts). As such, its repository
includes the git codebase as a submodule.

As of about 3 years ago, most code that is not libgit in git-cinnabar is
written in Rust, and is published on crates.io.

Part of publishing on crates.io involves running `cargo publish`, which
does `cargo package` under the hood. `cargo package` has the feature
of... not including directories that contain a Cargo.toml, so upgrading
libgit to 2.52.0 breaks the publishing process because all of the git
source code is skipped, and git-cinnabar can't be built as a result.

Of course, what this means is that this change is merely kicking the can
down the road, because the problem will reappear when the rust code
becomes non-optional in Git, thus why I'm making this RFC at the moment.

 .gitignore                    |  2 ++
 Makefile                      | 12 ++++++------
 meson.build                   |  2 +-
 Cargo.toml => rust/Cargo.toml |  1 +
 {src => rust}/cargo-meson.sh  |  0
 {src => rust}/lib.rs          |  0
 {src => rust}/meson.build     |  0
 {src => rust}/varint.rs       |  0
 8 files changed, 10 insertions(+), 7 deletions(-)
 rename Cargo.toml => rust/Cargo.toml (89%)
 rename {src => rust}/cargo-meson.sh (100%)
 rename {src => rust}/lib.rs (100%)
 rename {src => rust}/meson.build (100%)
 rename {src => rust}/varint.rs (100%)

diff --git a/.gitignore b/.gitignore
index 78a45cb5be..c7453b6fb2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -258,3 +258,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 8aa489f3b6..d7e9b7fd75 100644
--- a/Makefile
+++ b/Makefile
@@ -939,9 +939,9 @@ TEST_SHELL_PATH = $(SHELL_PATH)
 LIB_FILE = libgit.a
 
 ifdef DEBUG
-RUST_TARGET_DIR = target/debug
+RUST_TARGET_DIR = rust/target/debug
 else
-RUST_TARGET_DIR = target/release
+RUST_TARGET_DIR = rust/target/release
 endif
 
 ifeq ($(uname_S),Windows)
@@ -1545,8 +1545,8 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 
 UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
 
-RUST_SOURCES += src/lib.rs
-RUST_SOURCES += src/varint.rs
+RUST_SOURCES += rust/lib.rs
+RUST_SOURCES += rust/varint.rs
 
 GIT-VERSION-FILE: FORCE
 	@OLD=$$(cat $@ 2>/dev/null || :) && \
@@ -3007,8 +3007,8 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
 $(LIB_FILE): $(LIB_OBJS)
 	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
 
-$(RUST_LIB): Cargo.toml $(RUST_SOURCES)
-	$(QUIET_CARGO)cargo build $(CARGO_ARGS)
+$(RUST_LIB): rust/Cargo.toml $(RUST_SOURCES)
+	$(QUIET_CARGO)cargo build --manifest-path rust/Cargo.toml $(CARGO_ARGS)
 
 .PHONY: rust
 rust: $(RUST_LIB)
diff --git a/meson.build b/meson.build
index dd52efd1c8..6732198042 100644
--- a/meson.build
+++ b/meson.build
@@ -1723,7 +1723,7 @@ libgit_sources += version_def_h
 cargo = find_program('cargo', dirs: program_path, native: true, required: get_option('rust'))
 rust_option = get_option('rust').disable_auto_if(not cargo.found())
 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 89%
rename from Cargo.toml
rename to rust/Cargo.toml
index 2f51bf5d5f..29e6d1f4e1 100644
--- a/Cargo.toml
+++ b/rust/Cargo.toml
@@ -6,5 +6,6 @@ rust-version = "1.49.0"
 
 [lib]
 crate-type = ["staticlib"]
+path = "lib.rs"
 
 [dependencies]
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/lib.rs b/rust/lib.rs
similarity index 100%
rename from src/lib.rs
rename to rust/lib.rs
diff --git a/src/meson.build b/rust/meson.build
similarity index 100%
rename from src/meson.build
rename to rust/meson.build
diff --git a/src/varint.rs b/rust/varint.rs
similarity index 100%
rename from src/varint.rs
rename to rust/varint.rs
-- 
2.53.0.1.g318204b87e.dirty


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] Move rust gitcore crate to a different subdirectory
  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-09 22:48 ` [PATCH v2] " Mike Hommey
  1 sibling, 1 reply; 6+ messages in thread
From: brian m. carlson @ 2026-02-05  0:10 UTC (permalink / raw)
  To: Mike Hommey; +Cc: git, gitster, ps

[-- Attachment #1: Type: text/plain, Size: 2259 bytes --]

On 2026-02-04 at 23:22:08, Mike Hommey wrote:
> While `src/` is the default directory convention for Rust projects, it
> is too generic in the context of a multi-language project that is barely
> starting to (optionally) use Rust code.
> 
> Additionally, 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.
> 
> Moving all Rust-specific files into a dedicated `rust/` subdirectory
> makes things clearer.

If we're going to do this, we should place the `src` directory under the
`rust` subdirectory to maintain the normal layout.  There are many tools
that depend on this repository layout and we want to make it as easy as
possible for people to use native, standard tooling to build things.

Note that I don't have strong opinions for or against placing the Rust
code in a subdirectory, but I do very much want the standard layout to
be honoured.

> The above is a post hoc justification. I do think it makes sense to do,
> but I should mention my real immediate motivation.
> 
> git-cinnabar, a git remote helper used to talk to Mercurial servers, is
> a project based on libgit (the C parts). As such, its repository
> includes the git codebase as a submodule.
> 
> As of about 3 years ago, most code that is not libgit in git-cinnabar is
> written in Rust, and is published on crates.io.
> 
> Part of publishing on crates.io involves running `cargo publish`, which
> does `cargo package` under the hood. `cargo package` has the feature
> of... not including directories that contain a Cargo.toml, so upgrading
> libgit to 2.52.0 breaks the publishing process because all of the git
> source code is skipped, and git-cinnabar can't be built as a result.
> 
> Of course, what this means is that this change is merely kicking the can
> down the road, because the problem will reappear when the rust code
> becomes non-optional in Git, thus why I'm making this RFC at the moment.

Perhaps you could ask Cargo upstream to add a feature to override that
in the meantime (or add such a feature yourself).  I can imagine other
uses for such a feature.
-- 
brian m. carlson (they/them)
Toronto, Ontario, CA

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] Move rust gitcore crate to a different subdirectory
  2026-02-05  0:10 ` brian m. carlson
@ 2026-02-05  1:45   ` Mike Hommey
  2026-02-05  2:06     ` brian m. carlson
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Hommey @ 2026-02-05  1:45 UTC (permalink / raw)
  To: brian m. carlson, git, gitster, ps

On Thu, Feb 05, 2026 at 12:10:28AM +0000, brian m. carlson wrote:
> On 2026-02-04 at 23:22:08, Mike Hommey wrote:
> > While `src/` is the default directory convention for Rust projects, it
> > is too generic in the context of a multi-language project that is barely
> > starting to (optionally) use Rust code.
> > 
> > Additionally, 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.
> > 
> > Moving all Rust-specific files into a dedicated `rust/` subdirectory
> > makes things clearer.
> 
> If we're going to do this, we should place the `src` directory under the
> `rust` subdirectory to maintain the normal layout.  There are many tools
> that depend on this repository layout and we want to make it as easy as
> possible for people to use native, standard tooling to build things.

Not that I'm going to argue your preference, but I'm curious what tools
you'd know that would not support a layout different than the typical
one, because that means they're broken with some existing crates (e.g.
those from https://github.com/servo/servo/) and should probably be
fixed.

It might also be worth moving into a rust/gitcore/src directory too,
including the crate name in the path.

> Note that I don't have strong opinions for or against placing the Rust
> code in a subdirectory, but I do very much want the standard layout to
> be honoured.
> 
> > The above is a post hoc justification. I do think it makes sense to do,
> > but I should mention my real immediate motivation.
> > 
> > git-cinnabar, a git remote helper used to talk to Mercurial servers, is
> > a project based on libgit (the C parts). As such, its repository
> > includes the git codebase as a submodule.
> > 
> > As of about 3 years ago, most code that is not libgit in git-cinnabar is
> > written in Rust, and is published on crates.io.
> > 
> > Part of publishing on crates.io involves running `cargo publish`, which
> > does `cargo package` under the hood. `cargo package` has the feature
> > of... not including directories that contain a Cargo.toml, so upgrading
> > libgit to 2.52.0 breaks the publishing process because all of the git
> > source code is skipped, and git-cinnabar can't be built as a result.
> > 
> > Of course, what this means is that this change is merely kicking the can
> > down the road, because the problem will reappear when the rust code
> > becomes non-optional in Git, thus why I'm making this RFC at the moment.
> 
> Perhaps you could ask Cargo upstream to add a feature to override that
> in the meantime (or add such a feature yourself).  I can imagine other
> uses for such a feature.

I'm not sure this would be well received, considering there are already
`exclude` and `include` fields to control such things, and they
explicitly and purposely don't act on directories with a Cargo.toml:

| Regardless of whether exclude or include is specified, the following
| files are always excluded:
|   - Any sub-packages will be skipped (any subdirectory that contains a
|     Cargo.toml file).
|   - A directory named target in the root of the package will be skipped.
https://doc.rust-lang.org/cargo/reference/manifest.html#the-exclude-and-include-fields

Mike

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] Move rust gitcore crate to a different subdirectory
  2026-02-05  1:45   ` Mike Hommey
@ 2026-02-05  2:06     ` brian m. carlson
  2026-02-05  4:55       ` Mike Hommey
  0 siblings, 1 reply; 6+ messages in thread
From: brian m. carlson @ 2026-02-05  2:06 UTC (permalink / raw)
  To: Mike Hommey; +Cc: git, gitster, ps

[-- Attachment #1: Type: text/plain, Size: 2231 bytes --]

On 2026-02-05 at 01:45:53, Mike Hommey wrote:
> On Thu, Feb 05, 2026 at 12:10:28AM +0000, brian m. carlson wrote:
> > On 2026-02-04 at 23:22:08, Mike Hommey wrote:
> > > While `src/` is the default directory convention for Rust projects, it
> > > is too generic in the context of a multi-language project that is barely
> > > starting to (optionally) use Rust code.
> > > 
> > > Additionally, 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.
> > > 
> > > Moving all Rust-specific files into a dedicated `rust/` subdirectory
> > > makes things clearer.
> > 
> > If we're going to do this, we should place the `src` directory under the
> > `rust` subdirectory to maintain the normal layout.  There are many tools
> > that depend on this repository layout and we want to make it as easy as
> > possible for people to use native, standard tooling to build things.
> 
> Not that I'm going to argue your preference, but I'm curious what tools
> you'd know that would not support a layout different than the typical
> one, because that means they're broken with some existing crates (e.g.
> those from https://github.com/servo/servo/) and should probably be
> fixed.

One of my goals is to see if we can get Git's Rust code to compile with
mrustc since that might make it easier for NonStop, as well as some
Linux OSes on obsolete architectures.

I can tell you from my experience that mrustc's cargo implementation is
extremely limited and does only the bare minimum in terms of
functionality.  It already needs some help to work with static
libraries, but I'd really like to minimize the work that needs to be
done on it since it's not lovely code, and using a standard layout is
going to help with minimizing the necessary changes.  I will admit that
I haven't tested using a non-standard layout, but I fully expect it will
not work based on my experience of the codebase.

Certainly people may think this is folly, but it costs nothing for us to
keep the standard layout and make the porting process a little easier.
-- 
brian m. carlson (they/them)
Toronto, Ontario, CA

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] Move rust gitcore crate to a different subdirectory
  2026-02-05  2:06     ` brian m. carlson
@ 2026-02-05  4:55       ` Mike Hommey
  0 siblings, 0 replies; 6+ messages in thread
From: Mike Hommey @ 2026-02-05  4:55 UTC (permalink / raw)
  To: brian m. carlson, git, gitster, ps

On Thu, Feb 05, 2026 at 02:06:32AM +0000, brian m. carlson wrote:
> I can tell you from my experience that mrustc's cargo implementation is
> extremely limited and does only the bare minimum in terms of
> functionality.  It already needs some help to work with static
> libraries, but I'd really like to minimize the work that needs to be
> done on it since it's not lovely code, and using a standard layout is
> going to help with minimizing the necessary changes.  I will admit that
> I haven't tested using a non-standard layout, but I fully expect it will
> not work based on my experience of the codebase.

For what it's worth, it looks like mrustc supports non-standard layout
just fine[1], and that's not totally surprising, because the rustc codebase
used to use non-standard layouts a lot (although that's not true
anymore)

1. https://github.com/thepowersgang/mrustc/blob/7ff9513adb7cdbe0f8799e7b1f2e4df00ae21a14/tools/minicargo/manifest.cpp#L772

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] Move rust gitcore crate to a different subdirectory
  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-09 22:48 ` Mike Hommey
  1 sibling, 0 replies; 6+ messages in thread
From: Mike Hommey @ 2026-02-09 22:48 UTC (permalink / raw)
  To: git; +Cc: gitster, ps, sandals, Mike Hommey

While `src/` is the default directory convention for Rust projects, it
is too generic in the context of a multi-language project that is barely
starting to (optionally) use Rust code.

Additionally, 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.

Moving all Rust-specific files into a dedicated `rust/` subdirectory
makes things clearer.

Signed-off-by: Mike Hommey <mh@glandium.org>
---
 .gitignore                    |  2 ++
 Makefile                      | 12 ++++++------
 meson.build                   |  2 +-
 Cargo.toml => rust/Cargo.toml |  0
 {src => rust}/cargo-meson.sh  |  0
 {src => rust}/meson.build     |  6 +++---
 {src => rust/src}/lib.rs      |  0
 {src => rust/src}/varint.rs   |  0
 8 files changed, 12 insertions(+), 10 deletions(-)
 rename Cargo.toml => rust/Cargo.toml (100%)
 rename {src => rust}/cargo-meson.sh (100%)
 rename {src => rust}/meson.build (87%)
 rename {src => rust/src}/lib.rs (100%)
 rename {src => rust/src}/varint.rs (100%)

diff --git a/.gitignore b/.gitignore
index 78a45cb5be..c7453b6fb2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -258,3 +258,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 8aa489f3b6..b60af704ed 100644
--- a/Makefile
+++ b/Makefile
@@ -939,9 +939,9 @@ TEST_SHELL_PATH = $(SHELL_PATH)
 LIB_FILE = libgit.a
 
 ifdef DEBUG
-RUST_TARGET_DIR = target/debug
+RUST_TARGET_DIR = rust/target/debug
 else
-RUST_TARGET_DIR = target/release
+RUST_TARGET_DIR = rust/target/release
 endif
 
 ifeq ($(uname_S),Windows)
@@ -1545,8 +1545,8 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
 
 UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
 
-RUST_SOURCES += src/lib.rs
-RUST_SOURCES += src/varint.rs
+RUST_SOURCES += rust/src/lib.rs
+RUST_SOURCES += rust/src/varint.rs
 
 GIT-VERSION-FILE: FORCE
 	@OLD=$$(cat $@ 2>/dev/null || :) && \
@@ -3007,8 +3007,8 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
 $(LIB_FILE): $(LIB_OBJS)
 	$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
 
-$(RUST_LIB): Cargo.toml $(RUST_SOURCES)
-	$(QUIET_CARGO)cargo build $(CARGO_ARGS)
+$(RUST_LIB): rust/Cargo.toml $(RUST_SOURCES)
+	$(QUIET_CARGO)cargo build --manifest-path rust/Cargo.toml $(CARGO_ARGS)
 
 .PHONY: rust
 rust: $(RUST_LIB)
diff --git a/meson.build b/meson.build
index dd52efd1c8..3a92936241 100644
--- a/meson.build
+++ b/meson.build
@@ -1723,7 +1723,7 @@ libgit_sources += version_def_h
 cargo = find_program('cargo', dirs: program_path, native: true, required: get_option('rust'))
 rust_option = get_option('rust').disable_auto_if(not cargo.found())
 if rust_option.allowed()
-  subdir('src')
+  subdir('rust/src')
   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/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 87%
rename from src/meson.build
rename to rust/meson.build
index 25b9ad5a14..9490272521 100644
--- a/src/meson.build
+++ b/rust/meson.build
@@ -10,7 +10,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'
@@ -19,7 +19,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,
@@ -31,7 +31,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/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/varint.rs b/rust/src/varint.rs
similarity index 100%
rename from src/varint.rs
rename to rust/src/varint.rs
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-02-09 22:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox