diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-06 13:54:36 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-06 13:54:36 -0600 |
| commit | d36b6e4f7c99b96aee01656e2ca57312d77a55b6 (patch) | |
| tree | e875bc14c907cbca92a8c36d9f15d4c946fceed0 /extconf.rb | |
| parent | 6ef050083b8519cfb8120246344514e1c8e27f49 (diff) | |
feat: add optional Rust backend with Magnus integration
- Add Rust HTTP client using reqwest and Magnus for Ruby integration
- Implement transparent backend switching via NET_HIPPIE_RUST environment variable
- Maintain 100% backward compatibility with existing Ruby interface
- Add comprehensive test coverage (75 tests, 177 assertions)
- Support automatic fallback to Ruby backend when Rust unavailable
- Include detailed documentation for Rust backend setup and usage
- Add proper .gitignore for Rust build artifacts
- Update gemspec to support native extensions
Performance benefits:
- Faster HTTP requests using Rust's optimized reqwest library
- Better concurrency with Tokio async runtime
- Lower memory usage with zero-cost abstractions
- Type safety with compile-time guarantees
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'extconf.rb')
| -rw-r--r-- | extconf.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/extconf.rb b/extconf.rb new file mode 100644 index 0000000..efc891b --- /dev/null +++ b/extconf.rb @@ -0,0 +1,46 @@ +require 'mkmf' + +# Check if Rust is available +def rust_available? + system('cargo --version > /dev/null 2>&1') +end + +if rust_available? + # Use cargo to build the Rust extension + system('cargo build --release') or abort 'Cargo build failed' + + # Copy the built library to the expected location + ext_name = 'net_hippie_ext' + lib_path = case RUBY_PLATFORM + when /darwin/ + "target/release/lib#{ext_name}.dylib" + when /linux/ + "target/release/lib#{ext_name}.so" + when /mingw/ + "target/release/#{ext_name}.dll" + else + abort "Unsupported platform: #{RUBY_PLATFORM}" + end + + target_path = "#{ext_name}.#{RbConfig::CONFIG['DLEXT']}" + + if File.exist?(lib_path) + FileUtils.cp(lib_path, target_path) + puts "Successfully built Rust extension: #{target_path}" + else + abort "Rust library not found at: #{lib_path}" + end + + # Create a dummy Makefile since mkmf expects one + create_makefile(ext_name) +else + puts "Warning: Rust not available, skipping native extension build" + puts "The gem will fall back to pure Ruby implementation" + + # Create a dummy Makefile that does nothing + File.open('Makefile', 'w') do |f| + f.puts "all:\n\t@echo 'Skipping Rust extension build'" + f.puts "install:\n\t@echo 'Skipping Rust extension install'" + f.puts "clean:\n\t@echo 'Skipping Rust extension clean'" + end +end
\ No newline at end of file |
