Module: Thermite::Cargo

Included in:
Tasks
Defined in:
lib/thermite/cargo.rb

Overview

Cargo helpers

Instance Method Summary collapse

Instance Method Details

#cargoObject

Path to cargo. Can be overwritten by using the CARGO environment variable.



32
33
34
# File 'lib/thermite/cargo.rb', line 32

def cargo
  @cargo ||= find_executable(ENV.fetch('CARGO', 'cargo'))
end

#cargo_required_msgObject

Message used when cargo is required but not found.



62
63
64
65
66
67
68
69
# File 'lib/thermite/cargo.rb', line 62

def cargo_required_msg
  <<EOM
****
Rust's Cargo is required to build this extension. Please install Rust and put
it in the PATH, or set the CARGO environment variable appropriately.
****
EOM
end

#run_cargo(*args) ⇒ Object

Run cargo with the given args and return STDOUT.



39
40
41
# File 'lib/thermite/cargo.rb', line 39

def run_cargo(*args)
  sh "#{cargo} #{Shellwords.join(args)}"
end

#run_cargo_build(target) ⇒ Object

Run cargo build, given a target (i.e., release [default] or debug).



53
54
55
56
57
# File 'lib/thermite/cargo.rb', line 53

def run_cargo_build(target)
  cargo_args = %w(build)
  cargo_args << '--release' if target == 'release'
  run_cargo(*cargo_args)
end

#run_cargo_if_exists(*args) ⇒ Object

Only run_cargo if it is found in the executable paths.



46
47
48
# File 'lib/thermite/cargo.rb', line 46

def run_cargo_if_exists(*args)
  run_cargo(*args) if cargo
end