Module: Thermite::Cargo
- Included in:
- Tasks
- Defined in:
- lib/thermite/cargo.rb
Overview
Cargo helpers
Instance Method Summary collapse
-
#cargo ⇒ Object
Path to
cargo. -
#cargo_msg(require_severity) ⇒ Object
Message used when cargo is not found.
-
#cargo_recommended_msg ⇒ Object
Message used when cargo is recommended but not found.
-
#cargo_required_msg ⇒ Object
Message used when cargo is required but not found.
-
#inform_user_about_cargo ⇒ Object
Inform the user about cargo if it doesn't exist.
-
#run_cargo(*args) ⇒ Object
Run
cargowith the givenargsand returnSTDOUT. -
#run_cargo_build(target) ⇒ Object
Run
cargo build, given a target (i.e.,release[default] ordebug). -
#run_cargo_if_exists(*args) ⇒ Object
Only
run_cargoif it is found in the executable paths.
Instance Method Details
#cargo ⇒ Object
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_msg(require_severity) ⇒ Object
Message used when cargo is not found.
require_severity is the verb that indicates how important Rust is to the library.
77 78 79 80 81 82 83 84 |
# File 'lib/thermite/cargo.rb', line 77 def cargo_msg(require_severity) <<EOM **** Rust's Cargo is #{require_severity} to build this extension. Please install Rust and put it in the PATH, or set the CARGO environment variable appropriately. **** EOM end |
#cargo_recommended_msg ⇒ Object
Message used when cargo is recommended but not found.
96 97 98 |
# File 'lib/thermite/cargo.rb', line 96 def cargo_recommended_msg cargo_msg('recommended (but not required)') end |
#cargo_required_msg ⇒ Object
Message used when cargo is required but not found.
89 90 91 |
# File 'lib/thermite/cargo.rb', line 89 def cargo_required_msg cargo_msg('required') end |
#inform_user_about_cargo ⇒ Object
Inform the user about cargo if it doesn't exist.
If optional_rust_extension is true, print message to STDERR. Otherwise, raise an exception.
66 67 68 69 70 |
# File 'lib/thermite/cargo.rb', line 66 def inform_user_about_cargo raise cargo_required_msg unless [:optional_rust_extension] $stderr.write(cargo_recommended_msg) end |
#run_cargo(*args) ⇒ Object
Run cargo with the given args and return STDOUT.
39 40 41 42 43 |
# File 'lib/thermite/cargo.rb', line 39 def run_cargo(*args) Dir.chdir(config.rust_toplevel_dir) do sh "#{cargo} #{Shellwords.join(args)}" end end |
#run_cargo_build(target) ⇒ Object
Run cargo build, given a target (i.e., release [default] or debug).
55 56 57 58 59 |
# File 'lib/thermite/cargo.rb', line 55 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.
48 49 50 |
# File 'lib/thermite/cargo.rb', line 48 def run_cargo_if_exists(*args) run_cargo(*args) if cargo end |