diff --git a/Makefile b/Makefile index d794fcf87e..98e995e4be 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) @@ -3020,11 +3031,35 @@ 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) + $(call mkdir_p_parent_template) + $(QUIET_GEN)\ + if test $(words $(RUST_TARGETS)) -gt 1; \ + then \ + lipo -create $^ -output $@; \ + else \ + cp $< $@; \ + fi +endif .PHONY: rust rust: $(RUST_LIB) +endif export DEFAULT_EDITOR DEFAULT_PAGER @@ -4075,7 +4110,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 diff --git a/contrib/Makefile b/contrib/Makefile index 787cd07f52..1203c7263d 100644 --- a/contrib/Makefile +++ b/contrib/Makefile @@ -1,10 +1,22 @@ +include ../config.mak.uname +-include ../config.mak.autogen +-include ../config.mak + + +ifeq ($(uname_S),Darwin) +OS_CONTRIB += credential/osxkeychain +endif + all:: + $(foreach dir,$(OS_CONTRIB),$(MAKE) -C $(dir) $@;) test:: $(MAKE) -C diff-highlight $@ $(MAKE) -C subtree $@ + $(foreach dir,$(OS_CONTRIB),$(MAKE) -C $(dir) $@;) clean:: $(MAKE) -C contacts $@ $(MAKE) -C diff-highlight $@ $(MAKE) -C subtree $@ + $(foreach dir,$(OS_CONTRIB),$(MAKE) -C $(dir) $@;) diff --git a/contrib/credential/osxkeychain/Makefile b/contrib/credential/osxkeychain/Makefile index 219b0d7f49..d9fba07e8d 100644 --- a/contrib/credential/osxkeychain/Makefile +++ b/contrib/credential/osxkeychain/Makefile @@ -10,4 +10,6 @@ install: clean: $(MAKE) -C ../../.. clean-git-credential-osxkeychain -.PHONY: all git-credential-osxkeychain install clean +test: git-credential-osxkeychain + +.PHONY: all git-credential-osxkeychain install clean test