ARM64 and macOS: AAPCS64 struct passing, aarch64/macos targets, Apple frameworks and ld messages, tests/cross.sh, CI on ARM64 Linux and macOS

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Nexoniarz 2026-10-09 00:34:00 +02:00
commit 484c14fe77
12 changed files with 256 additions and 78 deletions

View file

@ -1,5 +1,6 @@
#include "target.h"
#include <llvm/Support/TargetSelect.h>
#include <llvm/TargetParser/Host.h>
#include <cstdio>
@ -21,27 +22,72 @@ static bool hostIsWindows() {
#endif
}
// The Finch-generated code needs these LLVM backends (the same C functions LLVM's own tools call).
extern "C" {
#ifdef FINCH_TARGET_X86
void LLVMInitializeX86TargetInfo();
void LLVMInitializeX86Target();
void LLVMInitializeX86TargetMC();
void LLVMInitializeX86AsmPrinter();
#endif
#ifdef FINCH_TARGET_AARCH64
void LLVMInitializeAArch64TargetInfo();
void LLVMInitializeAArch64Target();
void LLVMInitializeAArch64TargetMC();
void LLVMInitializeAArch64AsmPrinter();
#endif
}
void initTargets() {
#ifdef FINCH_TARGET_X86
LLVMInitializeX86TargetInfo();
LLVMInitializeX86Target();
LLVMInitializeX86TargetMC();
LLVMInitializeX86AsmPrinter();
#endif
#ifdef FINCH_TARGET_AARCH64
LLVMInitializeAArch64TargetInfo();
LLVMInitializeAArch64Target();
LLVMInitializeAArch64TargetMC();
LLVMInitializeAArch64AsmPrinter();
#endif
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmPrinter();
}
void setTarget(const std::string &name) {
std::string host = llvm::sys::getDefaultTargetTriple();
llvm::Triple hostTriple(llvm::Triple::normalize(host));
std::string t = name;
if (name.empty()) t = host;
else if (name == "windows") t = hostIsWindows() ? host : "x86_64-w64-mingw32";
else if (name == "linux") t = "x86_64-unknown-linux-gnu";
else if (name == "arm64" || name == "aarch64" || name == "linux-arm64") t = "aarch64-unknown-linux-gnu";
else if (name == "macos") t = hostTriple.isAArch64() ? "arm64-apple-macosx14.0.0" : "x86_64-apple-macosx14.0.0";
g_target.triple = llvm::Triple(llvm::Triple::normalize(t));
g_target.windows = g_target.triple.isOSWindows();
g_target.msvc = g_target.triple.isWindowsMSVCEnvironment();
g_target.cross = llvm::Triple(llvm::Triple::normalize(host)).getOS() != g_target.triple.getOS();
g_target.darwin = g_target.triple.isOSDarwin();
g_target.cross = hostTriple.getOS() != g_target.triple.getOS() || hostTriple.getArch() != g_target.triple.getArch();
g_target.exe = g_target.windows ? ".exe" : "";
// FINCH_CC chooses the C compiler for any target; CC only when not cross-compiling.
if (const char *fc = std::getenv("FINCH_CC")) g_target.cc = fc;
else if (!g_target.cross && std::getenv("CC")) g_target.cc = std::getenv("CC");
else if (g_target.cross && g_target.windows) g_target.cc = "x86_64-w64-mingw32-gcc";
else if (g_target.cross && g_target.triple.isAArch64() && g_target.triple.isOSLinux()) g_target.cc = "aarch64-linux-gnu-gcc";
else if (g_target.cross) g_target.cc = "clang --target=" + g_target.triple.str();
else if (hostIsWindows()) g_target.cc = "clang";
else g_target.cc = "cc";
}
std::string runPrefix() {
if (!g_target.cross) return "";
if (g_target.windows && !hostIsWindows()) return "wine ";
if (g_target.triple.isAArch64() && g_target.triple.isOSLinux()) return "qemu-aarch64 ";
return "";
}
std::string shellQuote(const std::string &s) {
#ifdef _WIN32
// cmd.exe: double quotes; a " inside a file name is impossible on Windows