Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Formula/lib/libkiwix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
class Libkiwix < Formula
desc "Common code base for all Kiwix ports"
homepage "https://github.com/kiwix/libkiwix"
url "https://github.com/kiwix/libkiwix/archive/refs/tags/14.2.0.tar.gz"
sha256 "244b69120d132de3079774ee439f9adfb7b556e88b9ef6ce5300f37dfc3737bc"
license "GPL-3.0-or-later"

depends_on "meson" => :build
depends_on "ninja" => :build
depends_on "pkgconf" => :build

depends_on "icu4c@78"
depends_on "libmicrohttpd"
depends_on "libzim"
depends_on "pugixml"
depends_on "xapian"

uses_from_macos "python" => :build
uses_from_macos "curl"
uses_from_macos "zlib"

# Mustache header-only library (required dependency)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the header will be used in other formula, too. So this should be a separated formula but the tag is outdated and cannot build without patch. For now, please leave a comment as follows:

Suggested change
# Mustache header-only library (required dependency)
# TODO: separate as a new formula once upstream release a new tag

resource "mustache" do
url "https://github.com/kainjow/Mustache/archive/refs/tags/v4.1.tar.gz"
sha256 "acd66359feb4318b421f9574cfc5a511133a77d916d0b13c7caa3783c0bfe167"
end

def install
# Install Mustache header
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Install Mustache header

resource("mustache").stage do
(buildpath/"mustache").install "mustache.hpp"
end

# On macOS, CLT 17+ moved C++ stdlib headers into the SDK; pass them explicitly so
# meson's atomics check can find <atomic> when configuring.
# Also pass mustache include path via cpp_args so meson's has_header check finds it.
extra_cxx_args = ["-I#{buildpath}/mustache"]
if OS.mac?
sdk_cxx_include = MacOS::CLT.sdk_path/"usr/include/c++/v1"
extra_cxx_args << "-isystem#{sdk_cxx_include}" if sdk_cxx_include.exist?
end

system "meson", "setup", "build",
"-Dcpp_args=#{extra_cxx_args.join(" ")}",
*std_meson_args
Comment on lines +34 to +45
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# On macOS, CLT 17+ moved C++ stdlib headers into the SDK; pass them explicitly so
# meson's atomics check can find <atomic> when configuring.
# Also pass mustache include path via cpp_args so meson's has_header check finds it.
extra_cxx_args = ["-I#{buildpath}/mustache"]
if OS.mac?
sdk_cxx_include = MacOS::CLT.sdk_path/"usr/include/c++/v1"
extra_cxx_args << "-isystem#{sdk_cxx_include}" if sdk_cxx_include.exist?
end
system "meson", "setup", "build",
"-Dcpp_args=#{extra_cxx_args.join(" ")}",
*std_meson_args
Is mustache build only? Since `buildpath` is a temporary path, this will not work at runtime.
Anyway, this can be changed for now as follows:
```suggestion
ENV.append_to_cflags "-I#{buildpath}/mustache"
system "meson", "setup", "build", *std_meson_args

system "meson", "compile", "-C", "build", "--verbose"
system "meson", "install", "-C", "build"
end

test do
(testpath/"test.cpp").write <<~CPP
#include <kiwix/kiwix_config.h>
#include <iostream>
int main() {
std::cout << "libkiwix " << LIBKIWIX_VERSION << std::endl;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope there will be more functional test, not just printing version.

return 0;
}
CPP

# Get icu4c path for compilation
icu4c = Formula["icu4c@78"]

cxx_args = ["-std=c++17", "-I#{include}", "-I#{icu4c.opt_include}",
"-L#{lib}", "-L#{icu4c.opt_lib}", "-lkiwix", "-o", "test"]
if OS.mac?
sdk_cxx_include = MacOS::CLT.sdk_path/"usr/include/c++/v1"
cxx_args = ["-isystem#{sdk_cxx_include}"] + cxx_args if sdk_cxx_include.exist?
end
system ENV.cxx, "test.cpp", *cxx_args
Comment on lines +60 to +69
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Get icu4c path for compilation
icu4c = Formula["icu4c@78"]
cxx_args = ["-std=c++17", "-I#{include}", "-I#{icu4c.opt_include}",
"-L#{lib}", "-L#{icu4c.opt_lib}", "-lkiwix", "-o", "test"]
if OS.mac?
sdk_cxx_include = MacOS::CLT.sdk_path/"usr/include/c++/v1"
cxx_args = ["-isystem#{sdk_cxx_include}"] + cxx_args if sdk_cxx_include.exist?
end
system ENV.cxx, "test.cpp", *cxx_args
icu4c = Formula["icu4c@78"]
system ENV.cxx, "test.cpp", "-std=c++17", "-o", "test", "-I#{include}", "-I#{icu4c.opt_include}",
"-L#{lib}", "-L#{icu4c.opt_lib}", "-lkiwix"


assert_match "libkiwix #{version}", shell_output("./test")
end
end
Loading