rs
1require 'mkmf'
2
3# Check if Rust is available
4def rust_available?
5 system('cargo --version > /dev/null 2>&1')
6end
7
8if rust_available?
9 # Use cargo to build the Rust extension
10 system('cargo build --release') or abort 'Cargo build failed'
11
12 # Copy the built library to the expected location
13 ext_name = 'net_hippie_ext'
14 lib_path = case RUBY_PLATFORM
15 when /darwin/
16 "target/release/lib#{ext_name}.dylib"
17 when /linux/
18 "target/release/lib#{ext_name}.so"
19 when /mingw/
20 "target/release/#{ext_name}.dll"
21 else
22 abort "Unsupported platform: #{RUBY_PLATFORM}"
23 end
24
25 target_path = "#{ext_name}.#{RbConfig::CONFIG['DLEXT']}"
26
27 if File.exist?(lib_path)
28 FileUtils.cp(lib_path, target_path)
29 puts "Successfully built Rust extension: #{target_path}"
30 else
31 abort "Rust library not found at: #{lib_path}"
32 end
33
34 # Create a dummy Makefile since mkmf expects one
35 create_makefile(ext_name)
36else
37 puts "Warning: Rust not available, skipping native extension build"
38 puts "The gem will fall back to pure Ruby implementation"
39
40 # Create a dummy Makefile that does nothing
41 File.open('Makefile', 'w') do |f|
42 f.puts "all:\n\t@echo 'Skipping Rust extension build'"
43 f.puts "install:\n\t@echo 'Skipping Rust extension install'"
44 f.puts "clean:\n\t@echo 'Skipping Rust extension clean'"
45 end
46end