Module: RustBuildHelper

Defined in:
ext/rrtrace/rust_build_helper.rb

Class Method Summary collapse

Class Method Details

.build(root_dir) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'ext/rrtrace/rust_build_helper.rb', line 7

def self.build(root_dir)
  puts "--- Building Rust visualizer ---"
  cargo_toml = File.join(root_dir, "Cargo.toml")

  unless File.exist?(cargo_toml)
    puts "Cargo.toml not found at #{cargo_toml}. Skipping rust build (maybe pre-compiled gem?)"
    return
  end

  unless system("cargo --version")
    puts "Cargo not found. Please install Rust to build this gem from source."
    exit 1
  end

  # Build rust binary
  # We use --release for performance of the visualizer
  sh_cmd = "cargo build --release --locked"
  puts "Running: #{sh_cmd} in #{root_dir}"
  unless system(sh_cmd, chdir: root_dir)
    puts "Failed to build Rust visualizer."
    exit 1
  end

  # Copy to libexec
  exe = "rrtrace#{RbConfig::CONFIG["EXEEXT"]}"
  src_exe = File.join(root_dir, "target", "release", exe)
  dest_dir = File.join(root_dir, "libexec")
  FileUtils.mkdir_p(dest_dir)
  dest_exe = File.join(dest_dir, exe)

  puts "Copying #{src_exe} to #{dest_exe}"
  FileUtils.cp(src_exe, dest_exe)
  FileUtils.chmod(0755, dest_exe) unless Gem.win_platform?
end