Skip to content

Commit 96e431e

Browse files
Update omnibus build instructions for aarch64 runner (#320)
* Hard-code machine part of universal `llvm_bin` download URL * Update `crystal` omnibus package config to be agnostic of runner architecture * Update `shards` omnibus package config to be agnostic of runner architecture * Update Makefile to be agnostic of architecture
1 parent c3e0d25 commit 96e431e

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

darwin/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ endif
6666
&& export SDKROOT=$(shell xcrun --sdk macosx --show-sdk-path) \
6767
&& bundle exec omnibus clean crystal shards \
6868
&& bundle exec omnibus build crystal \
69-
&& cp ./pkg/$(DARWIN_NAME) $(CURDIR)/$(OUTPUT_DIR)/$(subst x86_64,universal,$(DARWIN_NAME)) \
70-
&& cp ./pkg/$(DARWIN_PKG_NAME) $(CURDIR)/$(OUTPUT_DIR)/$(subst x86_64,universal,$(DARWIN_PKG_NAME))
69+
&& cp ./pkg/$(DARWIN_NAME) $(CURDIR)/$(OUTPUT_DIR)/$(subst x86_64,universal,$(subst arm64,universal,$(DARWIN_NAME))) \
70+
&& cp ./pkg/$(DARWIN_PKG_NAME) $(CURDIR)/$(OUTPUT_DIR)/$(subst x86_64,universal,$(subst arm64,universal,$(DARWIN_PKG_NAME)))
7171

7272
.PHONY: clean
7373
clean: ## Clean up build directory

omnibus/config/software/crystal.rb

+13-9
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,29 @@
5555

5656
crflags = "--no-debug"
5757

58-
copy "#{Dir.pwd}/crystal-#{ohai['os']}-#{ohai['kernel']['machine']}/embedded/bin/crystal", ".build/crystal"
58+
copy "#{Dir.pwd}/crystal-#{ohai['os']}-x86_64/embedded/bin/crystal", ".build/crystal"
5959

60-
# Compile for Intel
61-
command "make crystal stats=true release=true FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env
62-
move output_bin, "#{output_bin}_x86_64"
60+
# Compile native
61+
native_target = "#{ohai['kernel']['machine']}-apple-macosx#{ENV["MACOSX_DEPLOYMENT_TARGET"]}"
62+
make "crystal stats=true release=true FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_TARGET=#{native_target} CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env
63+
move output_bin, "#{output_bin}_#{ohai['kernel']['machine']}"
6364

6465
# Clean up
6566
make "clean_cache clean", env: env
6667

67-
# Restore x86_64 compiler w/ cross-compile support
68+
# Restore native compiler w/ cross-compile support
6869
mkdir ".build"
69-
copy "#{output_bin}_x86_64", ".build/crystal"
70+
copy "#{output_bin}_#{ohai['kernel']['machine']}", ".build/crystal"
71+
72+
# Cross-compile for other arch
7073

7174
make "deps", env: env
7275

73-
crtarget = "arm64-apple-macosx#{ENV["MACOSX_DEPLOYMENT_TARGET"]}"
74-
make "crystal stats=true release=true target=#{crtarget} FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_TARGET=#{crtarget} CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env
76+
other_machine = ohai['kernel']['machine'] == "x86_64" ? "arm64" : "x86_64"
77+
other_target = "#{other_machine}-apple-macosx#{ENV["MACOSX_DEPLOYMENT_TARGET"]}"
78+
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
7579

76-
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
80+
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
7781
delete "#{output_path}/crystal.o"
7882

7983
# Lipo them up

omnibus/config/software/llvm_bin.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
raise "llvm_bin not supported"
1919
end
2020

21-
source url: "http://crystal-lang.s3.amazonaws.com/llvm/llvm-#{version}-#{ohai['os']}-#{ohai['kernel']['machine']}.tar.gz",
21+
source url: "http://crystal-lang.s3.amazonaws.com/llvm/llvm-#{version}-#{ohai['os']}-x86_64.tar.gz",
2222
md5: source_md5
2323

2424
relative_path "llvm-#{version}"

omnibus/config/software/shards.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,19 @@
8888
build do
8989
crflags = "--no-debug --release"
9090

91-
# Build for Intel
91+
# Build native
9292
make "bin/shards SHARDS=false CRYSTAL=#{install_dir}/bin/crystal FLAGS='#{crflags}'", env: env
93-
move "bin/shards", "bin/shards_x86_64"
93+
move "bin/shards", "bin/shards_#{ohai['kernel']['machine']}"
9494

9595
# Clean
9696
make "clean", env: env
9797

98-
# Build for ARM64
99-
crtarget = "arm64-apple-macosx#{ENV["MACOSX_DEPLOYMENT_TARGET"]}"
100-
crflags += " --cross-compile --target #{crtarget}"
98+
# Cross-compile for other arch
99+
other_machine = ohai['kernel']['machine'] == "x86_64" ? "arm64" : "x86_64"
100+
other_target = "#{other_machine}-apple-macosx#{ENV["MACOSX_DEPLOYMENT_TARGET"]}"
101+
crflags += " --cross-compile --target #{other_target}"
101102
make "bin/shards SHARDS=false CRYSTAL=#{install_dir}/bin/crystal FLAGS='#{crflags}'", env: env
102-
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
103+
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
103104

104105
# Lipo them up
105106
command "lipo -create -output bin/shards bin/shards_x86_64 bin/shards_arm64"

0 commit comments

Comments
 (0)