From 130b5fe331e908cd18b1a52d3c4f503e3c16d351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Tue, 2 Jul 2024 14:45:32 +0200 Subject: [PATCH 1/4] Hard-code machine part of universal `llvm_bin` download URL --- omnibus/config/software/crystal.rb | 2 +- omnibus/config/software/llvm_bin.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/omnibus/config/software/crystal.rb b/omnibus/config/software/crystal.rb index f3ce39c9..aeba6a81 100644 --- a/omnibus/config/software/crystal.rb +++ b/omnibus/config/software/crystal.rb @@ -55,7 +55,7 @@ crflags = "--no-debug" - copy "#{Dir.pwd}/crystal-#{ohai['os']}-#{ohai['kernel']['machine']}/embedded/bin/crystal", ".build/crystal" + copy "#{Dir.pwd}/crystal-#{ohai['os']}-x86_64/embedded/bin/crystal", ".build/crystal" # Compile for Intel command "make crystal stats=true release=true FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env diff --git a/omnibus/config/software/llvm_bin.rb b/omnibus/config/software/llvm_bin.rb index eaa62b1f..a3df5fa5 100644 --- a/omnibus/config/software/llvm_bin.rb +++ b/omnibus/config/software/llvm_bin.rb @@ -18,7 +18,7 @@ raise "llvm_bin not supported" end -source url: "http://crystal-lang.s3.amazonaws.com/llvm/llvm-#{version}-#{ohai['os']}-#{ohai['kernel']['machine']}.tar.gz", +source url: "http://crystal-lang.s3.amazonaws.com/llvm/llvm-#{version}-#{ohai['os']}-x86_64.tar.gz", md5: source_md5 relative_path "llvm-#{version}" From b84a42c2051bd3d79dca54b913f01daf806aa6d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Tue, 2 Jul 2024 14:48:24 +0200 Subject: [PATCH 2/4] Update `crystal` omnibus package config to be agnostic of runner architecture --- omnibus/config/software/crystal.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/omnibus/config/software/crystal.rb b/omnibus/config/software/crystal.rb index aeba6a81..a7956835 100644 --- a/omnibus/config/software/crystal.rb +++ b/omnibus/config/software/crystal.rb @@ -57,23 +57,27 @@ copy "#{Dir.pwd}/crystal-#{ohai['os']}-x86_64/embedded/bin/crystal", ".build/crystal" - # Compile for Intel - command "make crystal stats=true release=true FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env - move output_bin, "#{output_bin}_x86_64" + # Compile native + native_target = "#{ohai['kernel']['machine']}-apple-macosx#{ENV["MACOSX_DEPLOYMENT_TARGET"]}" + make "crystal stats=true release=true FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_TARGET=#{native_target} CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env + move output_bin, "#{output_bin}_#{ohai['kernel']['machine']}" # Clean up make "clean_cache clean", env: env - # Restore x86_64 compiler w/ cross-compile support + # Restore native compiler w/ cross-compile support mkdir ".build" - copy "#{output_bin}_x86_64", ".build/crystal" + copy "#{output_bin}_#{ohai['kernel']['machine']}", ".build/crystal" + + # Cross-compile for other arch make "deps", 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 + other_machine = ohai['kernel']['machine'] == "x86_64" ? "arm64" : "x86_64" + other_target = "#{other_machine}-apple-macosx#{ENV["MACOSX_DEPLOYMENT_TARGET"]}" + make "crystal stats=true release=true target=#{other_target} FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_TARGET=#{other_target} CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", 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 + command "clang #{output_path}/crystal.o -o #{output_bin}_#{other_machine} -target #{other_target} 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 From 69cd1ac89db039dabc898541b5d2462bd0474736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 3 Jul 2024 14:18:57 +0200 Subject: [PATCH 3/4] Update `shards` omnibus package config to be agnostic of runner architecture --- omnibus/config/software/shards.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/omnibus/config/software/shards.rb b/omnibus/config/software/shards.rb index 974ad371..ed2dcc4e 100644 --- a/omnibus/config/software/shards.rb +++ b/omnibus/config/software/shards.rb @@ -88,18 +88,19 @@ build do crflags = "--no-debug --release" - # Build for Intel + # Build native make "bin/shards SHARDS=false CRYSTAL=#{install_dir}/bin/crystal FLAGS='#{crflags}'", env: env - move "bin/shards", "bin/shards_x86_64" + move "bin/shards", "bin/shards_#{ohai['kernel']['machine']}" # Clean make "clean", env: env - # Build for ARM64 - crtarget = "arm64-apple-macosx#{ENV["MACOSX_DEPLOYMENT_TARGET"]}" - crflags += " --cross-compile --target #{crtarget}" + # Cross-compile for other arch + other_machine = ohai['kernel']['machine'] == "x86_64" ? "arm64" : "x86_64" + other_target = "#{other_machine}-apple-macosx#{ENV["MACOSX_DEPLOYMENT_TARGET"]}" + crflags += " --cross-compile --target #{other_target}" make "bin/shards SHARDS=false CRYSTAL=#{install_dir}/bin/crystal FLAGS='#{crflags}'", 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 + command "clang bin/shards.o -o bin/shards_#{other_machine} -target #{other_target} -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" From d69c72b0cde2277bf1761fb269911bd9ae8bfdaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Wed, 3 Jul 2024 10:40:51 +0200 Subject: [PATCH 4/4] Update Makefile to be agnostic of architecture --- darwin/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/darwin/Makefile b/darwin/Makefile index 9c9e1017..c7ba7c2e 100644 --- a/darwin/Makefile +++ b/darwin/Makefile @@ -66,8 +66,8 @@ endif && export SDKROOT=$(shell xcrun --sdk macosx --show-sdk-path) \ && bundle exec omnibus clean crystal shards \ && bundle exec omnibus build crystal \ - && cp ./pkg/$(DARWIN_NAME) $(CURDIR)/$(OUTPUT_DIR)/$(subst x86_64,universal,$(DARWIN_NAME)) \ - && cp ./pkg/$(DARWIN_PKG_NAME) $(CURDIR)/$(OUTPUT_DIR)/$(subst x86_64,universal,$(DARWIN_PKG_NAME)) + && cp ./pkg/$(DARWIN_NAME) $(CURDIR)/$(OUTPUT_DIR)/$(subst x86_64,universal,$(subst arm64,universal,$(DARWIN_NAME))) \ + && cp ./pkg/$(DARWIN_PKG_NAME) $(CURDIR)/$(OUTPUT_DIR)/$(subst x86_64,universal,$(subst arm64,universal,$(DARWIN_PKG_NAME))) .PHONY: clean clean: ## Clean up build directory