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.
31 32 33 |
# File 'lib/thermite/cargo.rb', line 31 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
.
65 66 67 68 69 70 |
# File 'lib/thermite/cargo.rb', line 65 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.
88 89 90 91 92 93 94 95 |
# File 'lib/thermite/cargo.rb', line 88 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.
107 108 109 |
# File 'lib/thermite/cargo.rb', line 107 def cargo_recommended_msg cargo_msg('recommended (but not required)') end |
#cargo_required_msg ⇒ Object
Message used when cargo is required but not found.
100 101 102 |
# File 'lib/thermite/cargo.rb', line 100 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.
77 78 79 80 81 |
# File 'lib/thermite/cargo.rb', line 77 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
.
38 39 40 41 42 |
# File 'lib/thermite/cargo.rb', line 38 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.
47 48 49 |
# File 'lib/thermite/cargo.rb', line 47 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
).
54 55 56 57 58 59 60 |
# File 'lib/thermite/cargo.rb', line 54 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 |