git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH v1 4/4] libgit-sys: exclude unnecessary directories in git-src

From
Josh Steadmon <steadmon@google.com>
Date
Mar 18, 2025, 23:24 UTC
Message-ID
<8bd61ee5dd33d0529240b677caaff361876ec271.1742339107.git.josh@steadmon.net>
In-Reply-To
<cover.1742339107.git.josh@steadmon.net>

We can avoid copying tens of megabytes of unnecessary source files by excluding a few directories which are not needed to compile libgitpub.a. This helps us stay below crates.io's 10 MB size limit.

Signed-off-by: Josh Steadmon <steadmon@google.com>
---
 Makefile                      | 14 +++++++++++++-
 contrib/libgit-sys/Cargo.toml | 12 ++++++++++++
 contrib/libgit-sys/build.rs   |  8 +++++++-
 3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index e7d8786e4e..c75f1d0208 100644
--- a/Makefile
+++ b/Makefile
@@ -651,6 +651,7 @@ export prefix bindir sharedir sysconfdir perllibdir localedir
 CC = cc
 AR = ar
 RM = rm -f
+RMDIR = rmdir --ignore-fail-on-non-empty
 DIFF = diff
 TAR = tar
 FIND = find
@@ -3477,13 +3478,13 @@ coccicheck-pending: $(COCCICHECK_PATCHES_PENDING_INTREE)
 
 # "Sub"-Makefiles, not really because they can't be run stand-alone,
 # only there to contain directory-specific rules and variables
+ifndef NO_GITWEB
 ## gitweb/Makefile inclusion:
 MAK_DIR_GITWEB = gitweb/
 include gitweb/Makefile
 
 .PHONY: gitweb
 gitweb: $(MAK_DIR_GITWEB_ALL)
-ifndef NO_GITWEB
 all:: gitweb
 endif
 
@@ -3763,7 +3764,9 @@ clean: profile-clean coverage-clean cocciclean
 	$(RM) -r .dist-tmp-dir .doc-tmp-dir
 	$(RM) $(GIT_TARNAME).tar.gz
 	$(RM) $(htmldocs).tar.gz $(manpages).tar.gz
+ifndef INCLUDE_LIBGIT_RS
 	$(MAKE) -C Documentation/ clean
+endif
 	$(RM) Documentation/GIT-EXCLUDED-PROGRAMS
 ifndef PRESERVE_LIBGIT_TARGET
 	$(RM) -r contrib/libgit-sys/target contrib/libgit-rs/target
@@ -3775,7 +3778,9 @@ ifndef NO_PERL
 	$(RM) -r perl/build/
 endif
 	$(MAKE) -C templates/ clean
+ifndef INCLUDE_LIBGIT_RS
 	$(MAKE) -C t/ clean
+endif
 ifndef NO_TCLTK
 	$(MAKE) -C gitk-git clean
 	$(MAKE) -C git-gui clean
@@ -3798,6 +3803,13 @@ ifdef MSVC
 	$(RM) compat/vcbuild/MSVC-DEFS-GEN
 endif
 
+# Handle additional cleanup needed for running `cargo package` for libgit-sys.
+ifdef INCLUDE_LIBGIT_RS
+libgit-pkg-clean: clean
+	$(RMDIR) t/helper t/unit-tests/clar t/unit-tests t
+	$(RMDIR) oss-fuzz
+endif
+
 .PHONY: all install profile-clean cocciclean clean strip
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
 .PHONY: FORCE
diff --git a/contrib/libgit-sys/Cargo.toml b/contrib/libgit-sys/Cargo.toml
index e0623022c3..4b8facccfe 100644
--- a/contrib/libgit-sys/Cargo.toml
+++ b/contrib/libgit-sys/Cargo.toml
@@ -7,6 +7,18 @@ links = "gitpub"
 rust-version = "1.63" # TODO: Once we hit 1.84 or newer, we may want to remove Cargo.lock from
                       # version control. See https://lore.kernel.org/git/Z47jgK-oMjFRSslr@tapette.crustytoothpaste.net/
 description = "Native bindings to a portion of libgit"
+exclude = [
+  "git-src/.github",
+  "git-src/ci",
+  "git-src/Documentation",
+  "git-src/git-gui",
+  "git-src/gitk-git",
+  "git-src/gitweb",
+  "git-src/oss-fuzz",
+  "git-src/perl",
+  "git-src/po",
+  "git-src/t"
+]
 
 [lib]
 path = "src/lib.rs"
diff --git a/contrib/libgit-sys/build.rs b/contrib/libgit-sys/build.rs
index 16e0d66afb..0a72040726 100644
--- a/contrib/libgit-sys/build.rs
+++ b/contrib/libgit-sys/build.rs
@@ -17,6 +17,9 @@ pub fn main() -> std::io::Result<()> {
         .current_dir(git_root.clone())
         .args([
             "INCLUDE_LIBGIT_RS=YesPlease",
+            "NO_GITWEB=YesPlease",
+            "NO_PERL=YesPlease",
+            "NO_TCLTK=YesPlease",
             "contrib/libgitpub/libgitpub.a",
         ])
         .output()
@@ -40,8 +43,11 @@ pub fn main() -> std::io::Result<()> {
         .current_dir(git_root.clone())
         .args([
             "INCLUDE_LIBGIT_RS=YesPlease",
+            "NO_GITWEB=YesPlease",
+            "NO_PERL=YesPlease",
+            "NO_TCLTK=YesPlease",
             "PRESERVE_LIBGIT_TARGET=YesPlease",
-            "clean",
+            "libgit-pkg-clean",
         ])
         .output()
         .expect("`make clean` failed to run");
-- 
2.49.0.rc1.451.g8f38331e32-goog
Previous: Josh SteadmonNext: Josh Steadmon
Message 8 of 21 in “Fix `cargo package` for libgit-sys”
  1. 0/4 Fix `cargo package` for libgit-sysJosh Steadmon, Mar 18, 2025
  2. 1/4 libgitpub: move to separate contrib/ directoryJosh Steadmon, Mar 18, 2025
  3. 2/4 libgit-sys: add symlink to git repo root and clean after buildJosh Steadmon, Mar 18, 2025
  4. Josh SteadmonMar 19, 2025
  5. Phillip WoodMar 20, 2025
  6. Josh SteadmonMar 21, 2025
  7. 3/4 libgit-sys: parallelize build with Cargo's jobserverJosh Steadmon, Mar 18, 2025
  8. 4/4 libgit-sys: exclude unnecessary directories in git-srcJosh Steadmon, Mar 18, 2025
  9. 0/5 Fix `cargo package` for libgit-sysJosh Steadmon, Mar 21, 2025
  10. 1/5 libgitpub: move to separate contrib/ directoryJosh Steadmon, Mar 21, 2025
  11. 2/5 libgit-sys: add symlink to git repo root and build out of treeJosh Steadmon, Mar 21, 2025
  12. Eric SunshineMar 23, 2025
  13. Junio C HamanoMar 24, 2025
  14. Josh SteadmonMar 25, 2025
  15. Junio C HamanoMar 25, 2025
  16. Josh SteadmonMar 27, 2025
  17. Junio C HamanoMar 29, 2025
  18. Johannes SchindelinMar 31, 2025
  19. 3/5 libgit-sys: parallelize build with Cargo's jobserverJosh Steadmon, Mar 21, 2025
  20. 4/5 libgit-sys: exclude unnecessary directories in git-srcJosh Steadmon, Mar 21, 2025
  21. 5/5 libgit-{sys,rs}: add license and description fieldsJosh Steadmon, Mar 21, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.