From d1173d695a4e790f684f4efb1f7789acbe193ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Hovs=C3=A4ter?= Date: Sat, 6 Apr 2024 12:31:01 +0200 Subject: [PATCH] Fix target triple on macOS With the release of Xcode 15, a new linker was introduced and with it came warnings from the linker. It appears that the new linker is stricter in which target triples it considers valid. Specifically, it looks like the minimum deployment target is required. E.g., `aarch64-apple-darwin23.3.0` is valid, while `aarch64-apple-darwin` is not. See also: * https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Linking * https://github.com/crystal-lang/crystal/issues/13846 --- omnibus/config/software/crystal.rb | 8 +++----- omnibus/config/software/shards.rb | 5 +++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/omnibus/config/software/crystal.rb b/omnibus/config/software/crystal.rb index 4a31e3cb..f3ce39c9 100644 --- a/omnibus/config/software/crystal.rb +++ b/omnibus/config/software/crystal.rb @@ -68,14 +68,12 @@ mkdir ".build" copy "#{output_bin}_x86_64", ".build/crystal" - # Compile for ARM64. Apple's clang only understands arm64, LLVM uses aarch64, - # so we need to sub out aarch64 in our calls to Apple tools - env["CXXFLAGS"] << " -target arm64-apple-darwin" make "deps", env: env - make "crystal stats=true release=true target=aarch64-apple-darwin FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_TARGET=aarch64-apple-darwin CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env + crtarget = "arm64-apple-macosx#{ENV["MACOSX_DEPLOYMENT_TARGET"]}" + make "crystal stats=true release=true target=#{crtarget} FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_TARGET=#{crtarget} CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env - command "clang #{output_path}/crystal.o -o #{output_bin}_arm64 -target arm64-apple-darwin src/llvm/ext/llvm_ext.o `llvm-config --libs --system-libs --ldflags 2>/dev/null` -lstdc++ -lpcre2-8 -lgc -lpthread -levent -liconv -ldl -v", env: env + command "clang #{output_path}/crystal.o -o #{output_bin}_arm64 -target #{crtarget} src/llvm/ext/llvm_ext.o `llvm-config --libs --system-libs --ldflags 2>/dev/null` -lstdc++ -lpcre2-8 -lgc -lpthread -levent -liconv -ldl -v", env: env delete "#{output_path}/crystal.o" # Lipo them up diff --git a/omnibus/config/software/shards.rb b/omnibus/config/software/shards.rb index 8b33ac6b..974ad371 100644 --- a/omnibus/config/software/shards.rb +++ b/omnibus/config/software/shards.rb @@ -96,9 +96,10 @@ make "clean", env: env # Build for ARM64 - crflags += " --cross-compile --target aarch64-apple-darwin" + crtarget = "arm64-apple-macosx#{ENV["MACOSX_DEPLOYMENT_TARGET"]}" + crflags += " --cross-compile --target #{crtarget}" make "bin/shards SHARDS=false CRYSTAL=#{install_dir}/bin/crystal FLAGS='#{crflags}'", env: env - command "clang bin/shards.o -o bin/shards_arm64 -target arm64-apple-darwin -L#{install_dir}/embedded/lib -lyaml -lpcre2-8 -lgc -lpthread -levent -liconv -ldl", env: env + command "clang bin/shards.o -o bin/shards_arm64 -target #{crtarget} -L#{install_dir}/embedded/lib -lyaml -lpcre2-8 -lgc -lpthread -levent -liconv -ldl", env: env # Lipo them up command "lipo -create -output bin/shards bin/shards_x86_64 bin/shards_arm64"