|
1 | 1 | CRYSTAL_VERSION = ENV['CRYSTAL_VERSION']
|
2 | 2 | CRYSTAL_SHA1 = ENV['CRYSTAL_SHA1']
|
3 | 3 | 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') |
5 | 5 |
|
6 | 6 | name "crystal"
|
7 | 7 | default_version CRYSTAL_VERSION
|
8 | 8 | skip_transitive_dependency_licensing true
|
9 | 9 |
|
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 |
15 | 11 |
|
16 | 12 | dependency "pcre2"
|
17 | 13 | dependency "bdw-gc"
|
|
46 | 42 | end
|
47 | 43 |
|
48 | 44 | 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" } |
50 | 51 |
|
51 | 52 | mkdir "#{project_dir}/deps"
|
52 |
| - make "deps", env: env |
| 53 | + make "deps", env: env.dup |
53 | 54 | mkdir ".build"
|
54 |
| - command "echo #{Dir.pwd}", env: env |
55 |
| - |
56 |
| - crflags = "--no-debug" |
57 | 55 |
|
| 56 | + block { puts "\n=== Build native crystal bin with embedded universal crystal binary\n\n" } |
58 | 57 | 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 |
64 | 95 |
|
65 | 96 | # Clean up
|
66 | 97 | make "clean_cache clean", env: env
|
67 | 98 |
|
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 | + |
72 | 102 | # Compile for ARM64. Apple's clang only understands arm64, LLVM uses aarch64,
|
73 | 103 | # 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" |
75 | 105 | make "deps", env: env
|
76 | 106 |
|
77 | 107 | 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 |
| - |
79 | 108 | 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 |
80 | 116 | delete "#{output_path}/crystal.o"
|
81 |
| - block { raise "Could not build crystal arm64" unless File.exist?("#{output_bin}_arm64") } |
82 | 117 |
|
83 | 118 | # Lipo them up
|
| 119 | + block { puts "\n\n=== Combine x86_64 and arm64 binaries in single universal binary ===\n\n" } |
84 | 120 | command "lipo -create -output #{output_bin} #{output_bin}_x86_64 #{output_bin}_arm64"
|
| 121 | + |
| 122 | + # Clean up |
85 | 123 | delete "#{output_bin}_x86_64"
|
86 | 124 | delete "#{output_bin}_arm64"
|
87 | 125 |
|
|
0 commit comments