|
| 1 | +class Dartaotruntime < Formula |
| 2 | + desc "Command-line tool for running AOT-compiled snapshots of Dart code" |
| 3 | + homepage "https://dart.dev/tools/dartaotruntime" |
| 4 | + # NOTE: Using a placeholder file because the build source is fetched by gclient |
| 5 | + url "https://raw.githubusercontent.com/dart-lang/sdk/refs/tags/3.11.4/README.md" |
| 6 | + sha256 "ff4301ec8e5c1259c5778c4abc947e303308cd31af30acd55575f5ca7ed6f405" |
| 7 | + license "BSD-3-Clause" |
| 8 | + |
| 9 | + livecheck do |
| 10 | + formula "dart-sdk" |
| 11 | + end |
| 12 | + |
| 13 | + depends_on "ninja" => :build |
| 14 | + depends_on xcode: :build # for xcodebuild |
| 15 | + depends_on "dart-sdk" => :test |
| 16 | + |
| 17 | + uses_from_macos "curl" => :build |
| 18 | + uses_from_macos "python" => :build |
| 19 | + uses_from_macos "xz" => :build |
| 20 | + |
| 21 | + # always pull the latest commit from https://chromium.googlesource.com/chromium/tools/depot_tools.git/+/refs/heads/main |
| 22 | + resource "depot-tools" do |
| 23 | + url "https://chromium.googlesource.com/chromium/tools/depot_tools.git", |
| 24 | + revision: "4ce8ba39a3488397a2d1494f167020f21de502f3" |
| 25 | + version "4ce8ba39a3488397a2d1494f167020f21de502f3" |
| 26 | + |
| 27 | + livecheck do |
| 28 | + url "https://chromium.googlesource.com/chromium/tools/depot_tools.git/+/refs/heads/main?format=JSON" |
| 29 | + regex(/"commit":\s*"(\h+)"/i) |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + def install |
| 34 | + resource("depot-tools").stage(buildpath/"depot-tools") |
| 35 | + ENV["DEPOT_TOOLS_UPDATE"] = "0" |
| 36 | + ENV.append_path "PATH", buildpath/"depot-tools" |
| 37 | + |
| 38 | + system "gclient", "config", "--name", "sdk", "https://dart.googlesource.com/sdk.git@#{version}" |
| 39 | + system "gclient", "sync", "--no-history" |
| 40 | + |
| 41 | + # FIXME: Workaround for https://github.com/dart-lang/sdk/issues/63089 |
| 42 | + if OS.mac? && MacOS::Xcode.version >= "26.4" |
| 43 | + inreplace "sdk/build/config/compiler/BUILD.gn", |
| 44 | + "\"-Wno-tautological-constant-compare\",", |
| 45 | + "\"-Wno-tautological-constant-compare\", \"-Wno-deprecated-declarations\"," |
| 46 | + end |
| 47 | + |
| 48 | + cd "sdk" do |
| 49 | + arch = Hardware::CPU.intel? ? "x64" : Hardware::CPU.arch.to_s |
| 50 | + out = OS.mac? ? "xcodebuild" : "out" |
| 51 | + system "./tools/build.py", "--mode=release", "--arch=#{arch}", "copy_dart_aotruntime" |
| 52 | + bin.install "#{out}/Release#{arch.upcase}/dart-sdk/bin/dartaotruntime" |
| 53 | + prefix.install_metafiles Pathname.pwd |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + test do |
| 58 | + dart = Formula["dart-sdk"].bin/"dart" |
| 59 | + system dart, "create", "dart-test" |
| 60 | + cd "dart-test" do |
| 61 | + system dart, "compile", "aot-snapshot", "bin/dart_test.dart" |
| 62 | + assert_match "Hello world: 42!", shell_output("#{bin}/dartaotruntime bin/dart_test.aot") |
| 63 | + end |
| 64 | + end |
| 65 | +end |
0 commit comments