Skip to content

Commit

Permalink
help: special-case HOST_CPU universal
Browse files Browse the repository at this point in the history
When building Git as a universal binary on macOS, the binary supports more than
one target architecture. This is a bit of a problem for the `HOST_CPU`
setting that is woefully unprepared for such a situation, as it wants to
show architecture hard-coded at build time.

In preparation for releasing universal builds, work around this by
special-casing `universal` and replacing it at run-time with the known
values `x86_64` or `arm64`.

Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
jeffhostetler authored and dscho committed Nov 20, 2023
1 parent 2dc2755 commit c68b447
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions help.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,22 @@ const char *help_unknown_cmd(const char *cmd)
exit(1);
}

#if defined(__APPLE__)
static const char *git_host_cpu(void) {
if (!strcmp(GIT_HOST_CPU, "universal")) {
#if defined(__x86_64__)
return "x86_64";
#elif defined(__aarch64__)
return "arm64";
#endif
}

return GIT_HOST_CPU;
}
#undef GIT_HOST_CPU
#define GIT_HOST_CPU git_host_cpu()
#endif

void get_version_info(struct strbuf *buf, int show_build_options)
{
/*
Expand Down

0 comments on commit c68b447

Please sign in to comment.