From 7371da86211b4280a83ad02da96b570ee46eb4df Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Sat, 23 Nov 2024 19:50:11 -0500 Subject: [PATCH] libunicode 0.6.0 (new formula) Signed-off-by: Rui Chen --- .github/autobump.txt | 1 + Formula/lib/libunicode.rb | 64 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 Formula/lib/libunicode.rb diff --git a/.github/autobump.txt b/.github/autobump.txt index d366f35723363..7f8cd8f220f45 100644 --- a/.github/autobump.txt +++ b/.github/autobump.txt @@ -1699,6 +1699,7 @@ libtrace libtrng libucl libunibreak +libunicode libuninameslist libunistring libunwind diff --git a/Formula/lib/libunicode.rb b/Formula/lib/libunicode.rb new file mode 100644 index 0000000000000..cd8a6dee20063 --- /dev/null +++ b/Formula/lib/libunicode.rb @@ -0,0 +1,64 @@ +class Libunicode < Formula + desc "Modern C++20 Unicode library" + homepage "https://github.com/contour-terminal/libunicode" + url "https://github.com/contour-terminal/libunicode/archive/refs/tags/v0.6.0.tar.gz" + sha256 "0c217f8264000f1b8c36e78969cb9cf91ac97de937cc141ab78e6b1ad7f404ef" + license "Apache-2.0" + + depends_on "cmake" => :build + + uses_from_macos "python" => :build + + on_macos do + depends_on "llvm" => :build if DevelopmentTools.clang_build_version <= 1500 + end + + on_linux do + depends_on "gcc" # C++20 + 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 + ENV.llvm_clang if OS.mac? && DevelopmentTools.clang_build_version <= 1500 + + args = %W[ + -DLIBUNICODE_EXAMPLES=OFF + -DLIBUNICODE_TESTING=OFF + -DLIBUNICODE_BENCHMARK=OFF + -DCMAKE_INSTALL_RPATH=#{rpath} + ] + + 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 + #include + + int main() { + u32_char_t u32_codepoints[] = { 'h', 'e', 'l', 'l', 'o', ' ', 0x1F30D }; + int gc_count = u32_gc_count(u32_codepoints, 7); + std::cout << "Grapheme cluster count: " << gc_count << "\\n"; + + return 0; + } + CPP + + system ENV.cxx, "-std=c++17", "-o", "test", "test.cpp", "-I#{include}", "-L#{lib}", "-lunicode" + assert_match "Grapheme cluster count: 7", shell_output("./test") + + assert_match "HYPHEN", shell_output("#{bin}/unicode-query U+2D") + end +end