Skip to content

Commit dbcc79a

Browse files
committed
Update CXXFLAGS to have target argument before build
1 parent ec1ea08 commit dbcc79a

File tree

1 file changed

+61
-23
lines changed

1 file changed

+61
-23
lines changed

omnibus/config/software/crystal.rb

+61-23
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
CRYSTAL_VERSION = ENV['CRYSTAL_VERSION']
22
CRYSTAL_SHA1 = ENV['CRYSTAL_SHA1']
33
FIRST_RUN = ENV["FIRST_RUN"]
4-
CRYSTAL_SRC = (ENV['CRYSTAL_SRC'] || "").strip
4+
CRYSTAL_SRC = ENV.fetch('CRYSTAL_SRC', 'https://github.com/crystal-lang/crystal')
55

66
name "crystal"
77
default_version CRYSTAL_VERSION
88
skip_transitive_dependency_licensing true
99

10-
if CRYSTAL_SRC.empty?
11-
source git: "https://github.com/crystal-lang/crystal"
12-
else
13-
source git: CRYSTAL_SRC
14-
end
10+
source git: CRYSTAL_SRC
1511

1612
dependency "pcre2"
1713
dependency "bdw-gc"
@@ -46,42 +42,84 @@
4642
end
4743

4844
build do
49-
command "git checkout #{CRYSTAL_SHA1}", cwd: project_dir
45+
block { puts "\n=== Starting a build phase for crystal ===\n\n" }
46+
47+
command "git checkout '#{CRYSTAL_SHA1}'", cwd: project_dir
48+
49+
# Native crystal binary with cross-platform functionality
50+
block { puts "\n=== Build crystal's deps in #{project_dir}\n\n" }
5051

5152
mkdir "#{project_dir}/deps"
52-
make "deps", env: env
53+
make "deps", env: env.dup
5354
mkdir ".build"
54-
command "echo #{Dir.pwd}", env: env
55-
56-
crflags = "--no-debug"
5755

56+
block { puts "\n=== Build native crystal bin with embedded universal crystal binary\n\n" }
5857
copy "#{Dir.pwd}/crystal-#{ohai['os']}-#{ohai['kernel']['machine']}/embedded/bin/crystal", ".build/crystal"
59-
60-
# Compile for Intel
61-
command "make crystal stats=true release=true target=x86_64-apple-darwin FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env
62-
move output_bin, "#{output_bin}_x86_64"
63-
block { raise "Could not build crystal x86_64" unless File.exist?("#{output_bin}_x86_64") }
58+
command ".build/crystal --version", env: env.dup
59+
command "file .build/crystal", env: env.dup
60+
61+
crflags = "--no-debug"
62+
command "make crystal stats=true release=true FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env.dup
63+
block "Testing the result file" do
64+
puts "===> Testing the result file #{output_bin}"
65+
raise "Could not build native crystal binary: #{output_bin}" unless File.exist?("#{output_bin}")
66+
end
67+
command "file #{output_bin}", env: env.dup
68+
command "#{output_bin} --version", env: env.dup
69+
70+
# Restore compiler w/ cross-compile support
71+
block { puts "\n\n=== Restore compiler with cross-compile support ===\n\n" }
72+
move "#{output_bin}", ".build/crystal"
73+
74+
make "clean_cache clean", env: env
75+
76+
# x86_64 crystal binary
77+
block { puts "\n\n=== Building x86_64 binary ===\n\n" }
78+
79+
original_CXXFLAGS_env = env["CXXFLAGS"].dup
80+
original_LDFLAGS_env = env["LDFLAGS"].dup
81+
82+
env["CXXFLAGS"] = original_CXXFLAGS_env + " -target x86_64-apple-darwin"
83+
env["LDFLAGS"] = original_LDFLAGS_env + " -v -target x86_64-apple-darwin"
84+
env["LDLIBS"] = "-v -target x86_64-apple-darwin"
85+
make "deps", env: env.dup
86+
87+
make "crystal verbose=true stats=true release=true target=x86_64-apple-darwin CRYSTAL_CONFIG_TARGET=x86_64-apple-darwin FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env
88+
command "clang #{output_path}/crystal.o -o #{output_bin}_x86_64 -target x86_64-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
89+
block "Testing the result file" do
90+
puts "===> Testing the result file #{output_bin}_x86_64"
91+
raise "Could not build crystal x86_64" unless File.exist?("#{output_bin}_x86_64")
92+
end
93+
# NOTE: Add validation of the output
94+
command "file #{output_bin}_x86_64", env: env
6495

6596
# Clean up
6697
make "clean_cache clean", env: env
6798

68-
# Restore x86_64 compiler w/ cross-compile support
69-
mkdir ".build"
70-
copy "#{output_bin}_x86_64", ".build/crystal"
71-
99+
# arm64 crystal binary
100+
block { puts "\n\n=== Building arm64 version ===\n\n" }
101+
72102
# Compile for ARM64. Apple's clang only understands arm64, LLVM uses aarch64,
73103
# so we need to sub out aarch64 in our calls to Apple tools
74-
env["CXXFLAGS"] << " -target arm64-apple-darwin"
104+
env["CXXFLAGS"] = original_CXXFLAGS_env + " -target arm64-apple-darwin"
75105
make "deps", env: env
76106

77107
make "crystal stats=true release=true target=aarch64-apple-darwin FLAGS=\"#{crflags}\" CRYSTAL_CONFIG_TARGET=aarch64-apple-darwin CRYSTAL_CONFIG_LIBRARY_PATH= O=#{output_path}", env: env
78-
79108
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
109+
110+
block "Testing the result file" do
111+
puts "===> Testing the result file #{output_bin}_arm64"
112+
raise "Could not build crystal arm64" unless File.exist?("#{output_bin}_arm64")
113+
end
114+
# NOTE: Add validation of the output
115+
command "file #{output_bin}_arm64", env: env
80116
delete "#{output_path}/crystal.o"
81-
block { raise "Could not build crystal arm64" unless File.exist?("#{output_bin}_arm64") }
82117

83118
# Lipo them up
119+
block { puts "\n\n=== Combine x86_64 and arm64 binaries in single universal binary ===\n\n" }
84120
command "lipo -create -output #{output_bin} #{output_bin}_x86_64 #{output_bin}_arm64"
121+
122+
# Clean up
85123
delete "#{output_bin}_x86_64"
86124
delete "#{output_bin}_arm64"
87125

0 commit comments

Comments
 (0)