Skip to content

Commit

Permalink
Explicitly specify target for Darwin Intel build
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
miry committed Nov 10, 2023
1 parent f2c1e13 commit ec1ea08
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions omnibus/config/software/crystal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@
copy "#{Dir.pwd}/crystal-#{ohai['os']}-#{ohai['kernel']['machine']}/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
command "make crystal stats=true release=true target=x86_64-apple-darwin FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env
move output_bin, "#{output_bin}_x86_64"
block { raise "Could not build crystal x86_64" unless File.exist?("#{output_bin}_x86_64") }

# Clean up
make "clean_cache clean", env: env
Expand All @@ -77,14 +78,15 @@

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

# Lipo them up
command "lipo -create -output #{output_bin} #{output_bin}_x86_64 #{output_bin}_arm64"
delete "#{output_bin}_x86_64"
delete "#{output_bin}_arm64"

block do
raise "Could not build crystal" unless File.exists?(output_bin)
raise "Could not build crystal" unless File.exist?(output_bin)

if macos? || mac_os_x?
otool_libs = `otool -L #{output_bin}`
Expand Down

0 comments on commit ec1ea08

Please sign in to comment.