[PATCH v5 0/2] Makefile: link osxkeychain helper against Rust
- From
- Shardul Natu via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Jul 6, 2026, 17:14 UTC
- Message-ID
- <pull.2288.v5.git.git.1783358097.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2288.v4.git.git.1783188355.gitgitgadget@gmail.com>
This series improves macOS build reliability and distribution support when Rust is enabled in the Git build system. It addresses two distinct challenges: a parallel build race condition in git-credential-osxkeychain and support for macOS Universal Binaries (multi-architecture distribution).
Why This Series is Needed =========================
1. Parallel Build Race Condition (make -j): While commit 522ea8ef7d
("osxkeychain: fix build with Rust") updated the link command for
git-credential-osxkeychain to pass $(LIBS), it omitted $(RUST_LIB) from
the target prerequisite list. When running a parallel build (make -j)
from a clean working tree, Make can attempt to link
git-credential-osxkeychain before Cargo has finished compiling
libgitcore.a, causing linker failures. 2. macOS Universal Binary (lipo) Support: On macOS, Universal Binaries
bundle native executable code for multiple architectures (Intel x86_64
and Apple Silicon arm64) into a single file. This is standard practice
for macOS distribution and CI packaging (such as Burrito, Homebrew, and
Git's macOS CI runners), allowing a single artifact to run natively
across all Macs without Rosetta translation.While Apple's C compiler (clang) natively supports universal builds by passing -arch x86_64 -arch arm64 in CFLAGS and LDFLAGS, Cargo and rustc do not support multiple -arch flags in a single invocation. Instead, Cargo must be invoked separately for each target triple (--target x86_64-apple-darwin and --target aarch64-apple-darwin). This series bridges that gap.
Overview of Patches ===================
* Patch 1: Makefile: add $(RUST_LIB) prerequisite to osxkeychain Adds $(RUST_LIB) as a prerequisite dependency to the osxkeychain target, eliminating the parallel build race condition. Additionally, wraps the definitions of $(RUST_LIB) and the rust build target in ifndef NO_RUST so that disabling Rust cleanly makes the dependency a no-op.
* Patch 2: Makefile: support universal macOS builds via RUST_TARGETS Allows users to specify space-separated target triples in RUST_TARGETS. Introduces declarative pattern rules (target/%/...) to compile each target slice via Cargo, and uses lipo (part of the mandatory Xcode Command Line Tools) to combine the resulting static archives into a universal library at target/release/libgitcore.a. Uses mkdir_p_parent_template to guarantee directory creation before lipo.
Changes since v4:
* Changed the osxkeychain prerequisite dependency from $(LIB_FILE) $(RUST_LIB) to $(GITLIBS) to match the canonical prerequisite pattern used by all other core Git targets linking $(LIBS).
Changes since v3:
* Removed leading @ from $(call mkdir_p_parent_template) so it relies on the built-in $(QUIET_MKDIR_P_PARENT) behavior, matching existing Makefile conventions. * Replaced if [ with if test in Bourne shell recipe snippets to strictly adhere to the project's CodingGuidelines.
Changes since v2:
* Split the original combined commit into a two-patch series to separate prerequisite bug fixes from Universal Binary features. * Added $(call mkdir_p_parent_template) prior to invoking lipo to guarantee that parent target directories exist.
Shardul Natu (2): Makefile: add $(GITLIBS) prerequisite to osxkeychain Makefile: support universal macOS builds via RUST_TARGETS
Makefile | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-)
base-commit: 602f6c329a7d99df269d382df353b4e1bbbbd8aa Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2288%2Fkiranani%2Fnext-v5 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2288/kiranani/next-v5 Pull-Request: https://github.com/git/git/pull/2288
Range-diff vs v4:
1: 41de7d391a ! 1: e0bb18ff01 Makefile: add $(RUST_LIB) prerequisite to osxkeychain
@@ Metadata
Author: Shardul Natu <snatu@google.com>
## Commit message ##
- Makefile: add $(RUST_LIB) prerequisite to osxkeychain
+ Makefile: add $(GITLIBS) prerequisite to osxkeychain
When Rust is enabled, the git-credential-osxkeychain helper depends on
Rust symbols compiled into $(RUST_LIB). While commit 522ea8ef7d
@@ Commit message
clean working tree can fail because Make does not know to invoke Cargo
to build libgitcore.a before linking git-credential-osxkeychain.
- Add $(RUST_LIB) as a prerequisite dependency to the
- git-credential-osxkeychain target.
+ All other core Git targets that link $(LIBS) already depend on
+ $(GITLIBS), which bundles common-main.o, $(LIB_FILE), and $(RUST_LIB)
+ when Rust is enabled. Add $(GITLIBS) as a prerequisite dependency to the
+ git-credential-osxkeychain target to make it consistent with the rest of
+ the codebase.
Additionally, wrap the definitions of $(RUST_LIB) and the "rust" build
target in "ifndef NO_RUST". This ensures that when NO_RUST=1 is
@@ Makefile: $(LIBGIT_HIDDEN_EXPORT): $(LIBGIT_PARTIAL_EXPORT)
-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
++contrib/credential/osxkeychain/git-credential-osxkeychain: contrib/credential/osxkeychain/git-credential-osxkeychain.o $(GITLIBS) GIT-LDFLAGS
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
$(filter %.o,$^) $(LIBS) -framework Security -framework CoreFoundation
2: 88fc2e0bd8 ! 2: 66f71fb0d7 Makefile: support universal macOS builds via RUST_TARGETS
@@ Commit message
3. On macOS, if multiple targets are specified, use "lipo" (part of
the mandatory Xcode Command Line Tools) to combine the resulting
static libraries into target/release/libgitcore.a.
- 4. Ensure target directory creation before invoking lipo via
- mkdir_p_parent_template.
Once $(RUST_LIB) is compiled into a universal static archive, the
standard C linker seamlessly links it with the C object files to
@@ 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.
++# 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`.-- gitgitgadget