Skip to content

Commit 28572bc

Browse files
committed
Package rubydex MCP executable in gem
1 parent cb809fa commit 28572bc

4 files changed

Lines changed: 27 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ THIRD_PARTY_LICENSES.html
2222
rust/THIRD_PARTY_LICENSES.html
2323
lib/rubydex/*.dylib
2424
lib/rubydex/*.so
25+
lib/rubydex/bin/

exe/rubydex_mcp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "rbconfig"
5+
6+
host_os = RbConfig::CONFIG.fetch("host_os")
7+
executable = host_os.match?(/mswin|mingw|cygwin/) ? "rubydex_mcp.exe" : "rubydex_mcp"
8+
binary = File.expand_path("../lib/rubydex/bin/#{executable}", __dir__)
9+
10+
unless File.executable?(binary)
11+
abort(<<~MESSAGE.chomp)
12+
rubydex_mcp is not available at #{binary}.
13+
Install a precompiled rubydex gem, or reinstall rubydex with Cargo available so the MCP executable can be built locally.
14+
MESSAGE
15+
end
16+
17+
exec(binary, *ARGV)

ext/rubydex/extconf.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "mkmf"
4+
require "fileutils"
45
require "pathname"
56

67
unless system("cargo", "--version", out: File::NULL, err: File::NULL)
@@ -81,6 +82,12 @@
8182
end
8283

8384
lib_dir = gem_dir.join("lib").join("rubydex")
85+
mcp_bin_dir = lib_dir.join("bin")
86+
FileUtils.mkdir_p(mcp_bin_dir)
87+
88+
mcp_executable = Gem.win_platform? ? "rubydex_mcp.exe" : "rubydex_mcp"
89+
mcp_src = target_dir.join(mcp_executable)
90+
mcp_dst = mcp_bin_dir.join(mcp_executable)
8491

8592
copy_dylib_commands = if Gem.win_platform?
8693
""
@@ -107,6 +114,7 @@
107114
.rust_built: $(RUST_SRCS)
108115
\t#{cargo_command} || (echo "Compiling Rust failed" && exit 1)
109116
\t$(COPY) #{bindings_path} #{__dir__}
117+
\t$(COPY) #{mcp_src} #{mcp_dst}
110118
\ttouch $@
111119
112120
compile_rust: .rust_built

rubydex.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
2828

2929
if ENV["RELEASE"]
3030
spec.files << "THIRD_PARTY_LICENSES.html"
31+
spec.files << "lib/rubydex/bin/#{Gem.win_platform? ? "rubydex_mcp.exe" : "rubydex_mcp"}"
3132
if RUBY_PLATFORM.include?("darwin")
3233
spec.files << "lib/rubydex/librubydex_sys.dylib"
3334
elsif RUBY_PLATFORM.include?("linux")

0 commit comments

Comments
 (0)