class AdaUrl < Formula desc "WHATWG-compliant and fast URL parser written in modern C++" homepage "https://github.com/ada-url/ada" url "https://github.com/ada-url/ada/archive/refs/tags/v3.4.2.tar.gz" sha256 "3aceb6028eb0787ea77c8f3035a5aaa15108ab11d0fe24f23fe850cf94816523" license any_of: ["Apache-2.0", "MIT"] head "https://github.com/ada-url/ada.git", branch: "main" bottle do sha256 cellar: :any, arm64_tahoe: "41356152557a6b1b02f9a9090d552b7707e0e8c79ff869600bd20989853e9a79" sha256 cellar: :any, arm64_sequoia: "c83fd95d2edf0d18fd639b928b24afe54a01520c55012bdc162d60548c277d51" sha256 cellar: :any, arm64_sonoma: "3d35d5ef85efbd9e92d7d26977b12c950785bd70b8ccc3ec5330961a9051657e" sha256 cellar: :any, sonoma: "582ff15ce092a63c68441ab9a92ecc062d45049578472702f2e953854760b749" sha256 cellar: :any_skip_relocation, arm64_linux: "4d724189ae29307268b2f6a5385f25f6ac4424a0533b5454ae8af719c8ec705f" sha256 cellar: :any_skip_relocation, x86_64_linux: "92c9e1b952b20d5cdda6be51388278ea5d27b738d6e8c136cfaec26c92248fa3" end depends_on "cmake" => :build depends_on "cxxopts" => :build depends_on "fmt" uses_from_macos "python" => :build on_macos do depends_on "llvm" if DevelopmentTools.clang_build_version <= 1500 end fails_with :clang do build 1500 cause "Requires C++20 support" end fails_with :gcc do version "11" cause "Requires C++20" end def install # ld: unknown options: --gc-sections if OS.mac? && DevelopmentTools.clang_build_version <= 1500 inreplace "tools/cli/CMakeLists.txt", 'target_link_options(adaparse PRIVATE "-Wl,--gc-sections")', "" end # Do not statically link to libstdc++ inreplace "tools/cli/CMakeLists.txt", 'target_link_options(adaparse PRIVATE "-static-libstdc++")', "" if OS.linux? args = %W[ -DCMAKE_INSTALL_RPATH=#{rpath} -DBUILD_SHARED_LIBS=ON -DADA_TOOLS=ON -DCPM_LOCAL_PACKAGES_ONLY=ON -DFETCHCONTENT_FULLY_DISCONNECTED=ON ] system "cmake", "-S", ".", "-B", "build", *args, *std_cmake_args system "cmake", "--build", "build" system "cmake", "--install", "build" end test do (testpath/"test.cpp").write <<~CPP #include "ada.h" #include int main(int , char *[]) { auto url = ada::parse("https://www.github.com/ada-url/ada"); url->set_protocol("http"); std::cout << url->get_protocol() << std::endl; return EXIT_SUCCESS; } CPP system ENV.cxx, "test.cpp", "-std=c++20", "-I#{include}", "-L#{lib}", "-lada", "-o", "test" assert_equal "http:", shell_output("./test").chomp if OS.mac? output = shell_output("#{bin}/adaparse -d http://www.google.com/bal?a==11#fddfds") else require "pty" PTY.spawn(bin/"adaparse", "-d", "http://www.google.com/bal?a==11#fddfds") do |r, _w, pid| Process.wait(pid) output = r.read_nonblock(1024) end end assert_match "search_start 25", output end end