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_manifest_path_args ⇒ Object
If the
cargo_workspace_member
option is set, the--manifest-path
argument tocargo
. -
#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
cargo
with the givenargs
and returnSTDOUT
. -
#run_cargo_if_exists(*args) ⇒ Object
Only
run_cargo
if it is found in the executable paths. -
#run_cargo_rustc(target) ⇒ Object
Run
cargo rustc
, given a target (i.e.,release
[default] ordebug
).
Instance Method Details
#cargo ⇒ Object
Path to cargo
. Can be overwritten by using the CARGO
environment variable.
30 31 32 |
# File 'lib/thermite/cargo.rb', line 30 def cargo @cargo ||= find_executable(ENV.fetch('CARGO', 'cargo')) end |
#cargo_manifest_path_args ⇒ Object
If the cargo_workspace_member
option is set, the --manifest-path
argument to cargo
.
64 65 66 67 68 69 |
# File 'lib/thermite/cargo.rb', line 64 def cargo_manifest_path_args return [] unless config.cargo_workspace_member manifest = File.join(config.cargo_workspace_member, 'Cargo.toml') ['--manifest-path', manifest] 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.
87 88 89 90 91 92 93 94 |
# File 'lib/thermite/cargo.rb', line 87 def cargo_msg(require_severity) <<MESSAGE **** 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. **** MESSAGE end |
#cargo_recommended_msg ⇒ Object
Message used when cargo is recommended but not found.
106 107 108 |
# File 'lib/thermite/cargo.rb', line 106 def cargo_recommended_msg cargo_msg('recommended (but not required)') end |
#cargo_required_msg ⇒ Object
Message used when cargo is required but not found.
99 100 101 |
# File 'lib/thermite/cargo.rb', line 99 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.
76 77 78 79 80 |
# File 'lib/thermite/cargo.rb', line 76 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
.
37 38 39 40 41 |
# File 'lib/thermite/cargo.rb', line 37 def run_cargo(*args) Dir.chdir(config.rust_toplevel_dir) do sh cargo, *args end 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 |
#run_cargo_rustc(target) ⇒ Object
Run cargo rustc
, given a target (i.e., release
[default] or debug
).
53 54 55 56 57 58 59 |
# File 'lib/thermite/cargo.rb', line 53 def run_cargo_rustc(target) cargo_args = %w[rustc] cargo_args.push(*cargo_manifest_path_args) cargo_args << '--release' if target == 'release' cargo_args.push(*cargo_rustc_args) run_cargo(*cargo_args) end |