|  | 
| 55 | 55 | 
 | 
| 56 | 56 |   crflags = "--no-debug" | 
| 57 | 57 | 
 | 
| 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" | 
| 59 | 59 | 
 | 
| 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']}" | 
| 63 | 64 | 
 | 
| 64 | 65 |   # Clean up | 
| 65 | 66 |   make "clean_cache clean", env: env | 
| 66 | 67 | 
 | 
| 67 |  | -  # Restore x86_64 compiler w/ cross-compile support | 
|  | 68 | +  # Restore native compiler w/ cross-compile support | 
| 68 | 69 |   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 | 
| 70 | 73 | 
 | 
| 71 | 74 |   make "deps", env: env | 
| 72 | 75 | 
 | 
| 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 | 
| 75 | 79 | 
 | 
| 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 | 
| 77 | 81 |   delete "#{output_path}/crystal.o" | 
| 78 | 82 | 
 | 
| 79 | 83 |   # Lipo them up | 
|  | 
0 commit comments