From: "Shardul Natu via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>,
Shnatu <snatu@google.com>, Koji Nakamaru <koji.nakamaru@gree.net>,
Shnatu <snatu@google.com>
Subject: [PATCH v2] Makefile: link osxkeychain & support universal Rust
Date: Wed, 01 Jul 2026 22:01:43 +0000 [thread overview]
Message-ID: <pull.2288.v2.git.git.1782943303219.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2288.git.git.1778001976709.gitgitgadget@gmail.com>
From: Shnatu <snatu@google.com>
When Rust is enabled, ensure that the git-credential-osxkeychain
helper is linked with the necessary Rust libraries.
Also, introduce native support for macOS Universal Binaries
(multi-architecture builds) in the Git build system by allowing
the user to specify a list of target triples in the RUST_TARGETS
environment variable.
To implement this cleanly without complex shell scripting in recipes:
1. We introduce a declarative Make pattern rule (target/%/...) to
compile each target-specific library slice (e.g.,
target/aarch64-apple-darwin/...).
2. We update the $(RUST_LIB) recipe to depend on the list of
compiled target-specific member libraries ($(RUST_MEMBER_LIBS)).
3. On macOS, if multiple targets are specified, we use lipo to
combine them into a single Universal static library at
target/release/libgitcore.a.
4. If only one target is specified, we copy it to the standard
path.
5. We enforce that building for multiple targets requires macOS
(as lipo is only available there), raising a clear make error
on other platforms.
This is a highly elegant and native Makefile solution that avoids
complex shell scripting in recipes and fully supports macOS Universal
Binaries.
Signed-off-by: Shardul Natu <snatu@google.com>
---
Makefile: link osxkeychain helper against Rust
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2288%2Fkiranani%2Fnext-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2288/kiranani/next-v2
Pull-Request: https://github.com/git/git/pull/2288
Range-diff vs v1:
1: 57046d2f78 ! 1: 6a11aff909 Makefile: link osxkeychain helper against Rust
@@ Metadata
Author: Shnatu <snatu@google.com>
## Commit message ##
- Makefile: link osxkeychain helper against Rust
+ Makefile: link osxkeychain & support universal Rust
When Rust is enabled, ensure that the git-credential-osxkeychain
helper is linked with the necessary Rust libraries.
- Introduce the RUST_LIBS variable inside ifndef NO_RUST block
- to hold the Rust library dependency, and use it in the helper's
- build target. This cleanly handles cases where Rust is disabled,
- making it a no-op and avoiding any build failures on systems
- without Cargo.
+ Also, introduce native support for macOS Universal Binaries
+ (multi-architecture builds) in the Git build system by allowing
+ the user to specify a list of target triples in the RUST_TARGETS
+ environment variable.
- This addresses reviewer feedback from internal CL 910223487
- by simplifying the variables and avoiding confusing "LINK"
- terminology.
+ To implement this cleanly without complex shell scripting in recipes:
+ 1. We introduce a declarative Make pattern rule (target/%/...) to
+ compile each target-specific library slice (e.g.,
+ target/aarch64-apple-darwin/...).
+ 2. We update the $(RUST_LIB) recipe to depend on the list of
+ compiled target-specific member libraries ($(RUST_MEMBER_LIBS)).
+ 3. On macOS, if multiple targets are specified, we use lipo to
+ combine them into a single Universal static library at
+ target/release/libgitcore.a.
+ 4. If only one target is specified, we copy it to the standard
+ path.
+ 5. We enforce that building for multiple targets requires macOS
+ (as lipo is only available there), raising a clear make error
+ on other platforms.
- Signed-off-by: Shnatu <snatu@google.com>
+ This is a highly elegant and native Makefile solution that avoids
+ complex shell scripting in recipes and fully supports macOS Universal
+ Binaries.
+
+ Signed-off-by: Shardul Natu <snatu@google.com>
## Makefile ##
-@@ Makefile: ALL_LDFLAGS = $(LDFLAGS) $(LDFLAGS_APPEND)
- ifndef NO_RUST
- BASIC_CFLAGS += -DWITH_RUST
- GITLIBS += $(RUST_LIB)
-+RUST_LIBS = $(RUST_LIB)
+@@ Makefile: include shared.mak
+ #
+ # Building Rust code requires Cargo.
+ #
++# Define RUST_TARGETS if you want to cross-compile. If left unspecified, it uses
++# the default rust target on the system.
++#
++# On macOS, this supports specifying multiple targets, separated by a space.
++# This will produce a Universal static library using `lipo`.
++#
++# Example: RUST_TARGETS="aarch64-apple-darwin x86_64-apple-darwin"
++#
+ # == SHA-1 and SHA-256 defines ==
+ #
+ # === SHA-1 backend ===
+@@ Makefile: TEST_SHELL_PATH = $(SHELL_PATH)
+
+ LIB_FILE = libgit.a
+
++ifndef NO_RUST
+ ifdef DEBUG
+-RUST_TARGET_DIR = target/debug
++RUST_BUILD_CONFIG = debug
+ else
+-RUST_TARGET_DIR = target/release
++RUST_BUILD_CONFIG = release
+ endif
+
ifeq ($(uname_S),Windows)
- EXTLIBS += -luserenv
+-RUST_LIB = $(RUST_TARGET_DIR)/gitcore.lib
++RUST_LIB_NAME = gitcore.lib
+ else
+-RUST_LIB = $(RUST_TARGET_DIR)/libgitcore.a
++RUST_LIB_NAME = libgitcore.a
++endif
++RUST_LIB = target/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME)
endif
+
+ GITLIBS = common-main.o $(LIB_FILE)
+@@ Makefile: scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
+ $(LIB_FILE): $(LIB_OBJS)
+ $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
+
++ifndef NO_RUST
++ifeq ($(RUST_TARGETS),)
+ $(RUST_LIB): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)
+ $(QUIET_CARGO)cargo build $(CARGO_ARGS)
++else
++ifneq ($(words $(RUST_TARGETS)),1)
++ifneq ($(uname_S),Darwin)
++$(error Building universal Rust libraries requires macOS (lipo is not available on $(uname_S)))
++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_LIB): $(RUST_MEMBER_LIBS)
++ $(QUIET_GEN)\
++ if [ $(words $(RUST_TARGETS)) -gt 1 ]; then \
++ lipo -create $^ -output $@; \
++ else \
++ cp $< $@; \
++ fi
++endif
+
+ .PHONY: rust
+ rust: $(RUST_LIB)
++endif
+
+ export DEFAULT_EDITOR DEFAULT_PAGER
+
@@ Makefile: $(LIBGIT_HIDDEN_EXPORT): $(LIBGIT_PARTIAL_EXPORT)
contrib/libgit-sys/libgitpub.a: $(LIBGIT_HIDDEN_EXPORT)
$(AR) $(ARFLAGS) $@ $^
-contrib/credential/osxkeychain/git-credential-osxkeychain: contrib/credential/osxkeychain/git-credential-osxkeychain.o $(LIB_FILE) GIT-LDFLAGS
-+contrib/credential/osxkeychain/git-credential-osxkeychain: contrib/credential/osxkeychain/git-credential-osxkeychain.o $(LIB_FILE) $(RUST_LIBS) GIT-LDFLAGS
++# When Rust is enabled, git-credential-osxkeychain depends on Rust symbols in $(RUST_LIB)
++contrib/credential/osxkeychain/git-credential-osxkeychain: contrib/credential/osxkeychain/git-credential-osxkeychain.o $(LIB_FILE) $(RUST_LIB) GIT-LDFLAGS
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
-- $(filter %.o,$^) $(LIB_FILE) $(EXTLIBS) -framework Security -framework CoreFoundation
-+ $(filter %.o,$^) $(LIB_FILE) $(RUST_LIBS) $(EXTLIBS) -framework Security -framework CoreFoundation
+ $(filter %.o,$^) $(LIBS) -framework Security -framework CoreFoundation
- contrib/credential/osxkeychain/git-credential-osxkeychain.o: contrib/credential/osxkeychain/git-credential-osxkeychain.c GIT-CFLAGS
- $(QUIET_LINK)$(CC) -o $@ -c $(dep_args) $(compdb_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $<
Makefile | 44 +++++++++++++++++++++++++++++++++++++++-----
1 file changed, 39 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index 1f3f099f5c..8d49ecc897 100644
--- a/Makefile
+++ b/Makefile
@@ -500,6 +500,14 @@ include shared.mak
#
# Building Rust code requires Cargo.
#
+# Define RUST_TARGETS if you want to cross-compile. If left unspecified, it uses
+# the default rust target on the system.
+#
+# On macOS, this supports specifying multiple targets, separated by a space.
+# This will produce a Universal static library using `lipo`.
+#
+# Example: RUST_TARGETS="aarch64-apple-darwin x86_64-apple-darwin"
+#
# == SHA-1 and SHA-256 defines ==
#
# === SHA-1 backend ===
@@ -939,16 +947,19 @@ TEST_SHELL_PATH = $(SHELL_PATH)
LIB_FILE = libgit.a
+ifndef NO_RUST
ifdef DEBUG
-RUST_TARGET_DIR = target/debug
+RUST_BUILD_CONFIG = debug
else
-RUST_TARGET_DIR = target/release
+RUST_BUILD_CONFIG = release
endif
ifeq ($(uname_S),Windows)
-RUST_LIB = $(RUST_TARGET_DIR)/gitcore.lib
+RUST_LIB_NAME = gitcore.lib
else
-RUST_LIB = $(RUST_TARGET_DIR)/libgitcore.a
+RUST_LIB_NAME = libgitcore.a
+endif
+RUST_LIB = target/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME)
endif
GITLIBS = common-main.o $(LIB_FILE)
@@ -3019,11 +3030,33 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
$(LIB_FILE): $(LIB_OBJS)
$(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
+ifndef NO_RUST
+ifeq ($(RUST_TARGETS),)
$(RUST_LIB): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)
$(QUIET_CARGO)cargo build $(CARGO_ARGS)
+else
+ifneq ($(words $(RUST_TARGETS)),1)
+ifneq ($(uname_S),Darwin)
+$(error Building universal Rust libraries requires macOS (lipo is not available on $(uname_S)))
+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_LIB): $(RUST_MEMBER_LIBS)
+ $(QUIET_GEN)\
+ if [ $(words $(RUST_TARGETS)) -gt 1 ]; then \
+ lipo -create $^ -output $@; \
+ else \
+ cp $< $@; \
+ fi
+endif
.PHONY: rust
rust: $(RUST_LIB)
+endif
export DEFAULT_EDITOR DEFAULT_PAGER
@@ -4074,7 +4107,8 @@ $(LIBGIT_HIDDEN_EXPORT): $(LIBGIT_PARTIAL_EXPORT)
contrib/libgit-sys/libgitpub.a: $(LIBGIT_HIDDEN_EXPORT)
$(AR) $(ARFLAGS) $@ $^
-contrib/credential/osxkeychain/git-credential-osxkeychain: contrib/credential/osxkeychain/git-credential-osxkeychain.o $(LIB_FILE) GIT-LDFLAGS
+# When Rust is enabled, git-credential-osxkeychain depends on Rust symbols in $(RUST_LIB)
+contrib/credential/osxkeychain/git-credential-osxkeychain: contrib/credential/osxkeychain/git-credential-osxkeychain.o $(LIB_FILE) $(RUST_LIB) GIT-LDFLAGS
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
$(filter %.o,$^) $(LIBS) -framework Security -framework CoreFoundation
base-commit: 43192e7977f5f05138abcdb3212a3f87ab513bef
--
gitgitgadget
next prev parent reply other threads:[~2026-07-01 22:01 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-05 17:26 [PATCH] Makefile: link osxkeychain helper against Rust Shardul Natu via GitGitGadget
2026-05-05 19:08 ` Kristoffer Haugsbakk
2026-05-07 0:39 ` Shnatu
2026-05-08 2:54 ` Junio C Hamano
2026-05-08 9:33 ` Koji Nakamaru
2026-05-08 17:44 ` Shnatu
2026-07-01 22:01 ` Shardul Natu via GitGitGadget [this message]
2026-07-02 1:35 ` [PATCH v2] Makefile: link osxkeychain & support universal Rust Junio C Hamano
2026-07-02 11:50 ` Patrick Steinhardt
2026-07-02 22:30 ` Shardul Natu
2026-07-03 5:15 ` Patrick Steinhardt
2026-07-03 12:02 ` lipo availability [was: [PATCH v2] Makefile: link osxkeychain & support universal Rust] Ben Knoble
2026-07-02 22:22 ` [PATCH v3 0/2] Makefile: link osxkeychain helper against Rust Shardul Natu via GitGitGadget
2026-07-02 22:22 ` [PATCH v3 1/2] Makefile: add $(RUST_LIB) prerequisite to osxkeychain Shardul Natu via GitGitGadget
2026-07-02 22:22 ` [PATCH v3 2/2] Makefile: support universal macOS builds via RUST_TARGETS Shardul Natu via GitGitGadget
2026-07-03 5:36 ` Junio C Hamano
2026-07-03 17:37 ` Shardul Natu
2026-07-04 18:05 ` [PATCH v4 0/2] Makefile: link osxkeychain helper against Rust Shardul Natu via GitGitGadget
2026-07-04 18:05 ` [PATCH v4 1/2] Makefile: add $(RUST_LIB) prerequisite to osxkeychain Shardul Natu via GitGitGadget
2026-07-06 10:49 ` Patrick Steinhardt
2026-07-04 18:05 ` [PATCH v4 2/2] Makefile: support universal macOS builds via RUST_TARGETS Shardul Natu via GitGitGadget
2026-07-06 10:49 ` Patrick Steinhardt
2026-07-05 4:08 ` [PATCH v4 0/2] Makefile: link osxkeychain helper against Rust Junio C Hamano
2026-07-05 17:38 ` Shardul Natu
2026-07-06 17:14 ` [PATCH v5 " Shardul Natu via GitGitGadget
2026-07-06 17:14 ` [PATCH v5 1/2] Makefile: add $(GITLIBS) prerequisite to osxkeychain Shardul Natu via GitGitGadget
2026-07-06 19:52 ` Junio C Hamano
2026-07-06 17:14 ` [PATCH v5 2/2] Makefile: support universal macOS builds via RUST_TARGETS Shardul Natu via GitGitGadget
2026-07-06 22:52 ` [PATCH v6 0/3] Makefile: link osxkeychain helper against Rust Shardul Natu via GitGitGadget
2026-07-06 22:52 ` [PATCH v6 1/3] Makefile: add $(RUST_LIB) prerequisite to osxkeychain Shardul Natu via GitGitGadget
2026-07-06 22:52 ` [PATCH v6 2/3] Makefile: support universal macOS builds via RUST_TARGETS Shardul Natu via GitGitGadget
2026-07-06 22:52 ` [PATCH v6 3/3] contrib: wire up osxkeychain in contrib/Makefile on macOS Shardul Natu via GitGitGadget
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=pull.2288.v2.git.git.1782943303219.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=koji.nakamaru@gree.net \
--cc=kristofferhaugsbakk@fastmail.com \
--cc=snatu@google.com \
/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