From 28572bcbdb05d78fa573d4733f93c8d36b23dbdc Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Mon, 25 May 2026 22:53:00 +0100 Subject: [PATCH] Package rubydex MCP executable in gem --- .gitignore | 1 + exe/rubydex_mcp | 17 +++++++++++++++++ ext/rubydex/extconf.rb | 8 ++++++++ rubydex.gemspec | 1 + 4 files changed, 27 insertions(+) create mode 100755 exe/rubydex_mcp diff --git a/.gitignore b/.gitignore index b2e16d225..db8bd90aa 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ THIRD_PARTY_LICENSES.html rust/THIRD_PARTY_LICENSES.html lib/rubydex/*.dylib lib/rubydex/*.so +lib/rubydex/bin/ diff --git a/exe/rubydex_mcp b/exe/rubydex_mcp new file mode 100755 index 000000000..bca33de47 --- /dev/null +++ b/exe/rubydex_mcp @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "rbconfig" + +host_os = RbConfig::CONFIG.fetch("host_os") +executable = host_os.match?(/mswin|mingw|cygwin/) ? "rubydex_mcp.exe" : "rubydex_mcp" +binary = File.expand_path("../lib/rubydex/bin/#{executable}", __dir__) + +unless File.executable?(binary) + abort(<<~MESSAGE.chomp) + rubydex_mcp is not available at #{binary}. + Install a precompiled rubydex gem, or reinstall rubydex with Cargo available so the MCP executable can be built locally. + MESSAGE +end + +exec(binary, *ARGV) diff --git a/ext/rubydex/extconf.rb b/ext/rubydex/extconf.rb index b2e070e9f..c17f5de15 100644 --- a/ext/rubydex/extconf.rb +++ b/ext/rubydex/extconf.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "mkmf" +require "fileutils" require "pathname" unless system("cargo", "--version", out: File::NULL, err: File::NULL) @@ -81,6 +82,12 @@ end lib_dir = gem_dir.join("lib").join("rubydex") +mcp_bin_dir = lib_dir.join("bin") +FileUtils.mkdir_p(mcp_bin_dir) + +mcp_executable = Gem.win_platform? ? "rubydex_mcp.exe" : "rubydex_mcp" +mcp_src = target_dir.join(mcp_executable) +mcp_dst = mcp_bin_dir.join(mcp_executable) copy_dylib_commands = if Gem.win_platform? "" @@ -107,6 +114,7 @@ .rust_built: $(RUST_SRCS) \t#{cargo_command} || (echo "Compiling Rust failed" && exit 1) \t$(COPY) #{bindings_path} #{__dir__} + \t$(COPY) #{mcp_src} #{mcp_dst} \ttouch $@ compile_rust: .rust_built diff --git a/rubydex.gemspec b/rubydex.gemspec index 3008c1c25..be4e8eca1 100644 --- a/rubydex.gemspec +++ b/rubydex.gemspec @@ -28,6 +28,7 @@ Gem::Specification.new do |spec| if ENV["RELEASE"] spec.files << "THIRD_PARTY_LICENSES.html" + spec.files << "lib/rubydex/bin/#{Gem.win_platform? ? "rubydex_mcp.exe" : "rubydex_mcp"}" if RUBY_PLATFORM.include?("darwin") spec.files << "lib/rubydex/librubydex_sys.dylib" elsif RUBY_PLATFORM.include?("linux")