Skip to content

Commit ec1ea08

Browse files
committed
Explicitly specify target for Darwin Intel build
By default uses the target of the system where the script is executed. If run darwin build on MacOS M1 laptop, it generates 2 arm binaries. And command `lito` returns error that both files have same arch. Reproduction of the problem: ``` $ llvm-config --host-target arm64-apple-darwin23.0.0 $ make crystal stats=true release=true Using /usr/local/bin/llvm-config [version= 15.0.7] CRYSTAL_CONFIG_BUILD_COMMIT="1f592eca6" CRYSTAL_CONFIG_PATH='$ORIGIN/../share/crystal/src' SOURCE_DATE_EPOCH="1699639716" CRYSTAL_CONFIG_LIBRARY_PATH= ./bin/crystal build --no-debug -D strict_multi_assign .... $ file .../crystal/embedded/bin/crystal .../crystal/embedded/bin/crystal: Mach-O 64-bit executable arm64 ```
1 parent f2c1e13 commit ec1ea08

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

omnibus/config/software/crystal.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@
5858
copy "#{Dir.pwd}/crystal-#{ohai['os']}-#{ohai['kernel']['machine']}/embedded/bin/crystal", ".build/crystal"
5959

6060
# Compile for Intel
61-
command "make crystal stats=true release=true FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env
61+
command "make crystal stats=true release=true target=x86_64-apple-darwin FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env
6262
move output_bin, "#{output_bin}_x86_64"
63+
block { raise "Could not build crystal x86_64" unless File.exist?("#{output_bin}_x86_64") }
6364

6465
# Clean up
6566
make "clean_cache clean", env: env
@@ -77,14 +78,15 @@
7778

7879
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
7980
delete "#{output_path}/crystal.o"
81+
block { raise "Could not build crystal arm64" unless File.exist?("#{output_bin}_arm64") }
8082

8183
# Lipo them up
8284
command "lipo -create -output #{output_bin} #{output_bin}_x86_64 #{output_bin}_arm64"
8385
delete "#{output_bin}_x86_64"
8486
delete "#{output_bin}_arm64"
8587

8688
block do
87-
raise "Could not build crystal" unless File.exists?(output_bin)
89+
raise "Could not build crystal" unless File.exist?(output_bin)
8890

8991
if macos? || mac_os_x?
9092
otool_libs = `otool -L #{output_bin}`

0 commit comments

Comments
 (0)