Makefile: add $(RUST_LIB) prerequisite to osxkeychain

When Rust is enabled, the git-credential-osxkeychain helper depends on Rust symbols compiled into $(RUST_LIB). While commit 522ea8ef7d ("osxkeychain: fix build with Rust") updated the linker command line to use $(LIBS), it omitted $(RUST_LIB) from the target prerequisite list. Without this prerequisite, running a parallel build ("make -j") from a clean working tree can fail because Make does not know to invoke Cargo to build libgitcore.a before linking git-credential-osxkeychain. Note that we depend explicitly on $(LIB_FILE) and $(RUST_LIB) rather than $(GITLIBS). Unlike standard Git builtins and programs like scalar (which define cmd_main() and rely on common-main.o to supply main()), git-credential-osxkeychain.c defines its own standalone int main(). If $(GITLIBS) were used, $(filter %.o,$^) in the link recipe would match both git-credential-osxkeychain.o and common-main.o, causing a duplicate symbol linking error for _main on macOS. Additionally, wrap the definitions of $(RUST_LIB) and the "rust" build target in "ifndef NO_RUST". This ensures that when NO_RUST=1 is specified, $(RUST_LIB) evaluates to empty, making the Rust dependency a clean no-op without needing intermediate variables. Signed-off-by: Shardul Natu <snatu@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shardul Natu committed Jul 8, 2026 at 03:21 UTC 87bd9bd40ee6e7f9fb80686e2d7526c524add195
1 file changed +6 -1
Makefile
+6 -1
@@ -939,6 +939,7 @@ TEST_SHELL_PATH = $(SHELL_PATH)
939
940 LIB_FILE = libgit.a
941
942 +ifndef NO_RUST
943 ifdef DEBUG
944 RUST_TARGET_DIR = target/debug
945 else
@@ -950,6 +951,7 @@ RUST_LIB = $(RUST_TARGET_DIR)/gitcore.lib
951 else
952 RUST_LIB = $(RUST_TARGET_DIR)/libgitcore.a
953 endif
954 +endif
955
956 GITLIBS = common-main.o $(LIB_FILE)
957 EXTLIBS =
@@ -3017,11 +3019,13 @@ scalar$X: scalar.o GIT-LDFLAGS $(GITLIBS)
3019 $(LIB_FILE): $(LIB_OBJS)
3020 $(QUIET_AR)$(RM) $@ && $(AR) $(ARFLAGS) $@ $^
3021
3022 +ifndef NO_RUST
3023 $(RUST_LIB): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)
3024 $(QUIET_CARGO)cargo build $(CARGO_ARGS)
3025
3026 .PHONY: rust
3027 rust: $(RUST_LIB)
3028 +endif
3029
3030 export DEFAULT_EDITOR DEFAULT_PAGER
3031
@@ -4072,7 +4076,8 @@ $(LIBGIT_HIDDEN_EXPORT): $(LIBGIT_PARTIAL_EXPORT)
4076 contrib/libgit-sys/libgitpub.a: $(LIBGIT_HIDDEN_EXPORT)
4077 $(AR) $(ARFLAGS) $@ $^
4078
4075 -contrib/credential/osxkeychain/git-credential-osxkeychain: contrib/credential/osxkeychain/git-credential-osxkeychain.o $(LIB_FILE) GIT-LDFLAGS
4079 +# When Rust is enabled, git-credential-osxkeychain depends on Rust symbols in $(RUST_LIB)
4080 +contrib/credential/osxkeychain/git-credential-osxkeychain: contrib/credential/osxkeychain/git-credential-osxkeychain.o $(LIB_FILE) $(RUST_LIB) GIT-LDFLAGS
4081 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) \
4082 $(filter %.o,$^) $(LIBS) -framework Security -framework CoreFoundation
4083