1 class Crystal < Formula
2 desc "Fast and statically typed, compiled language with Ruby-like syntax"
3 homepage "https://crystal-lang.org/"
7 url "https://github.com/crystal-lang/crystal/archive/refs/tags/1.15.1.tar.gz"
8 sha256 "72b32f2da09059ca96331be124cf611d3c6bd6da80f52cd551df59bfe14e6ebd"
11 url "https://github.com/crystal-lang/shards/archive/refs/tags/v0.19.1.tar.gz"
12 sha256 "2a49e7ffa4025e0b3e8774620fa8dbc227d3d1e476211fefa2e8166dcabf82b5"
18 regex(/^v?(\d+(?:\.\d+)+)$/i)
22 sha256 cellar: :any, arm64_sequoia: "48d0c40f34fe8a56b4b9be12be92e07ca77febf8161f5ca935598369b08d77bc"
23 sha256 cellar: :any, arm64_sonoma: "984846d9b3147d3ab0a541dd77133b440f35befded818d01a1d52472b67b78b7"
24 sha256 cellar: :any, arm64_ventura: "fb23a172caa2d2344a2b532b0534de7eff7cd7e6b76a63ad5c97e4fe879cdffe"
25 sha256 cellar: :any, sonoma: "f1bee61902000836204198f5de56958e77debc7ecfed1a40001fe3e1a41fc22c"
26 sha256 cellar: :any, ventura: "6429ca72f367d24837091ae59ccf014cbf053c9bacf20413df6092c29bcac607"
27 sha256 cellar: :any_skip_relocation, x86_64_linux: "3fc4a30c4b4ba306b238d7de1ad46fdf65c4a3b53714c5697853c88333c3f6cf"
31 url "https://github.com/crystal-lang/crystal.git", branch: "master"
34 url "https://github.com/crystal-lang/shards.git", branch: "master"
39 depends_on "gmp" # std uses it but it's not linked
43 depends_on "openssl@3" # std uses it but it's not linked
45 depends_on "pkgconf" # @[Link] will use pkg-config if available
47 uses_from_macos "libffi" # for the interpreter
49 # It used to be the case that every new crystal release was built from a
50 # previous release, except patches. Crystal is updating its policy to
51 # allow 4 minor releases of compatibility unless otherwise specified.
52 # Therefore, the boot version should have the MINOR component be
53 # between the current minor - 4 and current minor - 1.
55 # See: https://github.com/Homebrew/homebrew-core/pull/81318
57 boot_version = Version.new("1.10.1-1")
61 url "https://github.com/crystal-lang/crystal/releases/download/#{boot_version.major_minor_patch}/crystal-#{boot_version}-darwin-universal.tar.gz"
62 # version boot_version
63 sha256 "e6490e6d09745483bacea43c4d8974273632526c1f98f13db5aae0a5fc2c7924"
68 url "https://github.com/crystal-lang/crystal/releases/download/#{boot_version.major_minor_patch}/crystal-#{boot_version}-linux-x86_64.tar.gz"
69 # version boot_version
70 sha256 "1742e3755d3653d1ba07c0291f10a517fa392af87130dba4497ed9d82c12348b"
75 # Check version in `shard.lock` in shards repo.
76 resource "molinillo" do
77 url "https://github.com/crystal-lang/crystal-molinillo/archive/refs/tags/v0.2.0.tar.gz"
78 sha256 "e231cf2411a6a11a1538983c7fb52b19e650acc3338bd3cdf6fdb13d6463861a"
82 llvm = deps.find { |dep| dep.name.match?(/^llvm(@\d+)?$/) }
84 non_keg_only_runtime_deps = deps.filter_map { |dep| dep.to_formula unless dep.build? }
87 resource("boot").stage "boot"
88 ENV.append_path "PATH", "boot/bin"
89 ENV["LLVM_CONFIG"] = llvm.opt_bin/"llvm-config"
90 ENV["CRYSTAL_LIBRARY_PATH"] = ENV["HOMEBREW_LIBRARY_PATHS"]
91 ENV.append_path "CRYSTAL_LIBRARY_PATH", MacOS.sdk_path_if_needed/"usr/lib" if OS.mac? && MacOS.sdk_path_if_needed
92 non_keg_only_runtime_deps.each do |dep|
93 # Our just built `crystal` won't link with some dependents (e.g. `bdw-gc`, `libevent`)
94 # unless they're explicitly added to `CRYSTAL_LIBRARY_PATH`. The keg-only dependencies
95 # are already in `HOMEBREW_LIBRARY_PATHS`, so there is no need to add them.
96 ENV.prepend_path "CRYSTAL_LIBRARY_PATH", dep.opt_lib
99 crystal_install_dir = OS.linux? ? libexec : bin
100 stdlib_install_dir = pkgshare
102 # Avoid embedding HOMEBREW_PREFIX references in `crystal` binary.
103 config_library_path = "\\$$ORIGIN/#{HOMEBREW_PREFIX.relative_path_from(crystal_install_dir)}/lib"
104 config_path = "\\$$ORIGIN/#{stdlib_install_dir.relative_path_from(crystal_install_dir)}/src"
106 release_flags = ["release=true", "FLAGS=--no-debug"]
107 crystal_build_opts = release_flags + [
108 "CRYSTAL_CONFIG_LIBRARY_PATH=#{config_library_path}",
109 "CRYSTAL_CONFIG_PATH=#{config_path}",
112 crystal_build_opts << "CRYSTAL_CONFIG_BUILD_COMMIT=#{Utils.git_short_head}" if build.head?
115 (buildpath/".build").mkpath
116 system "make", "deps"
117 system "make", "crystal", *crystal_build_opts
119 # Build shards (with recently built crystal)
120 resource("shards").stage do
123 shard_lock = YAML.load_file("shard.lock")
124 required_molinillo_version = shard_lock.dig("shards", "molinillo", "version")
125 available_molinillo_version = resource("molinillo").version.to_s
126 odie "`molinillo` resource is outdated!" if required_molinillo_version != available_molinillo_version
128 resource("molinillo").stage "lib/molinillo"
130 shards_build_opts = release_flags + [
131 "CRYSTAL=#{buildpath}/bin/crystal",
134 shards_build_opts << "SHARDS_CONFIG_BUILD_COMMIT=#{Utils.git_short_head}" if build.head?
135 system "make", "bin/shards", *shards_build_opts
138 bin.install "bin/shards"
139 man1.install "man/shards.1"
140 man5.install "man/shard.yml.5"
144 crystal_install_dir.install ".build/crystal"
145 stdlib_install_dir.install "src"
147 bash_completion.install "etc/completion.bash" => "crystal"
148 zsh_completion.install "etc/completion.zsh" => "_crystal"
149 fish_completion.install "etc/completion.fish" => "crystal.fish"
151 man1.install "man/crystal.1"
153 return unless OS.linux?
155 # Wrapper script so that Crystal can find libraries in HOMEBREW_PREFIX
156 (bin/"crystal").write_env_script(
157 crystal_install_dir/"crystal",
158 LD_RUN_PATH: "${LD_RUN_PATH:+${LD_RUN_PATH}:}#{HOMEBREW_PREFIX}/lib",
163 assert_match "1", shell_output("#{bin}/crystal eval puts 1")