130 lines
4.1 KiB
Text
130 lines
4.1 KiB
Text
class Yams < Formula
|
|
desc "Yet Another Memory System - High-performance content-addressed storage"
|
|
homepage "https://github.com/trvon/yams"
|
|
version "__VERSION__"
|
|
license "GPL-3.0-or-later"
|
|
|
|
if Hardware::CPU.arm?
|
|
url "https://github.com/trvon/yams/releases/download/v#{version}/__ASSET_ARM64__"
|
|
sha256 "__SHA256_ARM64__"
|
|
else
|
|
url "https://github.com/trvon/yams/releases/download/v#{version}/__ASSET_X86_64__"
|
|
sha256 "__SHA256_X86_64__"
|
|
end
|
|
|
|
depends_on "onnxruntime"
|
|
|
|
livecheck do
|
|
url "https://github.com/trvon/yams/releases"
|
|
regex(/^v?(\d+(?:\.\d+)+)$/i)
|
|
end
|
|
|
|
def install
|
|
# Homebrew may stage archives either directly into buildpath (e.g. opt/homebrew/bin)
|
|
# or under an extra top-level directory. Be tolerant by searching for the yams binary.
|
|
root = if Dir.exist?("opt/homebrew/bin")
|
|
Pathname("opt/homebrew")
|
|
elsif Dir.exist?("local/bin")
|
|
Pathname("local")
|
|
elsif Dir.exist?("usr/local/bin")
|
|
Pathname("usr/local")
|
|
elsif Dir.exist?("bin")
|
|
Pathname(".")
|
|
else
|
|
yams_exe = Dir["**/bin/yams"].first
|
|
if yams_exe
|
|
Pathname(yams_exe).dirname.parent
|
|
else
|
|
odie "Could not locate install tree (expected opt/homebrew/bin, local/bin, usr/local/bin, bin, or a directory containing bin/yams)"
|
|
end
|
|
end
|
|
|
|
bin.install Dir[(root/"bin/*").to_s]
|
|
|
|
# Skip spdlog to avoid conflicts with homebrew's spdlog
|
|
(root/"include/spdlog").rmtree if (root/"include/spdlog").exist?
|
|
|
|
include.install Dir[(root/"include/*").to_s] if (root/"include").exist?
|
|
|
|
# Install lib contents preserving directory structure (plugins live in lib/yams/plugins/)
|
|
if (root/"lib").exist?
|
|
lib.install Dir[(root/"lib/*.{a,dylib,so}").to_s]
|
|
(lib/"pkgconfig").install Dir[(root/"lib/pkgconfig/*").to_s] if (root/"lib/pkgconfig").exist?
|
|
if (root/"lib/yams/plugins").exist?
|
|
(lib/"yams/plugins").mkpath
|
|
(lib/"yams/plugins").install Dir[(root/"lib/yams/plugins/*").to_s]
|
|
end
|
|
end
|
|
|
|
# Remove bundled onnxruntime — Homebrew manages this dependency
|
|
rm_f Dir[lib/"libonnxruntime*"]
|
|
|
|
# Runtime assets (schemas, etc.)
|
|
share.install Dir[(root/"share/*").to_s] if (root/"share").exist?
|
|
end
|
|
|
|
def post_install
|
|
plugin_dir = lib/"yams/plugins"
|
|
return unless plugin_dir.exist?
|
|
|
|
expected_rpath = (HOMEBREW_PREFIX/"lib").to_s
|
|
|
|
Dir[plugin_dir/"*.dylib"].sort.each do |plugin_path|
|
|
plugin = Pathname(plugin_path)
|
|
|
|
begin
|
|
next unless Utils.safe_popen_read("otool", "-L", plugin.to_s).include?("libonnxruntime")
|
|
|
|
mode = plugin.stat.mode & 0o777
|
|
plugin.chmod(mode | 0o200)
|
|
|
|
unless Utils.safe_popen_read("otool", "-l", plugin.to_s).include?(expected_rpath)
|
|
unless system "install_name_tool", "-add_rpath", expected_rpath, plugin.to_s
|
|
odie "Failed to add rpath '#{expected_rpath}' to #{plugin}"
|
|
end
|
|
end
|
|
|
|
unless Utils.safe_popen_read("otool", "-l", plugin.to_s).include?(expected_rpath)
|
|
odie "RPATH verification failed for #{plugin}; expected '#{expected_rpath}'"
|
|
end
|
|
rescue StandardError => e
|
|
odie "Failed to patch ONNX runtime rpath for #{plugin}: #{e.message}"
|
|
end
|
|
end
|
|
end
|
|
|
|
service do
|
|
run [opt_bin/"yams-daemon"]
|
|
keep_alive true
|
|
log_path var/"log/yams-daemon.log"
|
|
error_log_path var/"log/yams-daemon.log"
|
|
environment_variables YAMS_STORAGE: var/"lib/yams"
|
|
end
|
|
|
|
def caveats
|
|
<<~EOS
|
|
Initialize YAMS storage:
|
|
yams init .
|
|
|
|
Or specify custom location:
|
|
export YAMS_STORAGE="$HOME/.local/share/yams"
|
|
yams init
|
|
|
|
To start the YAMS daemon as a service:
|
|
brew services start yams
|
|
|
|
To stop the daemon:
|
|
brew services stop yams
|
|
|
|
Documentation: https://yamsmemory.ai
|
|
Repository: https://github.com/trvon/yams
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
assert_match version.to_s, shell_output("#{bin}/yams --version")
|
|
system "#{bin}/yams", "init", "--non-interactive", "--storage", testpath/"yams-test"
|
|
assert_predicate testpath/"yams-test/yams.db", :exist?
|
|
assert_predicate testpath/".config/yams/config.toml", :exist?
|
|
end
|
|
end
|