Class: RbSys::CargoBuilder Private
- Inherits:
-
Gem::Ext::Builder
- Object
- Gem::Ext::Builder
- RbSys::CargoBuilder
- Defined in:
- lib/rb_sys/cargo_builder.rb,
lib/rb_sys/cargo_builder/link_flag_converter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A class to build a Ruby gem Cargo. Extracted from ‘rubygems` gem, with some modifications.
Defined Under Namespace
Classes: DylibNotFoundError, LinkFlagConverter
Constant Summary collapse
- WELL_KNOWN_WRAPPERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w[sccache cachepot].freeze
Instance Attribute Summary collapse
- #config ⇒ Object private
- #dry_run ⇒ Object private
- #env ⇒ Object private
- #ext_dir ⇒ Object private
- #extra_cargo_args ⇒ Object private
- #extra_rustc_args ⇒ Object private
- #extra_rustflags ⇒ Object private
- #features ⇒ Object private
- #profile ⇒ Object private
- #runner ⇒ Object private
- #spec ⇒ Object private
- #target ⇒ Object private
Instance Method Summary collapse
- #build(_extension, dest_path, results, args = [], lib_dir = nil, cargo_dir = Dir.pwd) ⇒ Object private
- #build_crate(dest_path, results, args, cargo_dir) ⇒ Object private
- #build_env ⇒ Object private
- #cargo_command(dest_path, args = []) ⇒ Object private
- #cargo_dylib_path(dest_path) ⇒ Object private
-
#initialize(spec) ⇒ CargoBuilder
constructor
private
A new instance of CargoBuilder.
- #manifest_dir ⇒ Object private
- #rubygems_invoked? ⇒ Boolean private
-
#so_ext ⇒ Object
private
We have to basically reimplement RbConfig::CONFIG here to support Ruby < 2.5.
Constructor Details
#initialize(spec) ⇒ CargoBuilder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of CargoBuilder.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rb_sys/cargo_builder.rb', line 16 def initialize(spec) require "rubygems/command" require_relative "cargo_builder/link_flag_converter" @spec = spec @runner = self.class.method(:run) @profile = ENV.fetch("RB_SYS_CARGO_PROFILE", :release).to_sym @env = {} @features = [] @target = ENV["CARGO_BUILD_TARGET"] || ENV["RUST_TARGET"] || Cargo::Config.build_target @extra_rustc_args = [] @extra_cargo_args = [] @dry_run = true @ext_dir = "" @extra_rustflags = [] end |
Instance Attribute Details
#config ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rb_sys/cargo_builder.rb', line 12 def config @config end |
#dry_run ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rb_sys/cargo_builder.rb', line 12 def dry_run @dry_run end |
#env ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rb_sys/cargo_builder.rb', line 12 def env @env end |
#ext_dir ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rb_sys/cargo_builder.rb', line 12 def ext_dir @ext_dir end |
#extra_cargo_args ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rb_sys/cargo_builder.rb', line 12 def extra_cargo_args @extra_cargo_args end |
#extra_rustc_args ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rb_sys/cargo_builder.rb', line 12 def extra_rustc_args @extra_rustc_args end |
#extra_rustflags ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rb_sys/cargo_builder.rb', line 12 def extra_rustflags @extra_rustflags end |
#features ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rb_sys/cargo_builder.rb', line 12 def features @features end |
#profile ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 36 37 |
# File 'lib/rb_sys/cargo_builder.rb', line 33 def profile return :release if rubygems_invoked? @profile end |
#runner ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rb_sys/cargo_builder.rb', line 12 def runner @runner end |
#spec ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rb_sys/cargo_builder.rb', line 12 def spec @spec end |
#target ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/rb_sys/cargo_builder.rb', line 12 def target @target end |
Instance Method Details
#build(_extension, dest_path, results, args = [], lib_dir = nil, cargo_dir = Dir.pwd) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rb_sys/cargo_builder.rb', line 39 def build(_extension, dest_path, results, args = [], lib_dir = nil, cargo_dir = Dir.pwd) require "fileutils" require "shellwords" build_crate(dest_path, results, args, cargo_dir) validate_cargo_build!(dest_path) rename_cdylib_for_ruby_compatibility(dest_path) finalize_directory(dest_path, lib_dir, cargo_dir) results end |
#build_crate(dest_path, results, args, cargo_dir) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 53 54 55 56 |
# File 'lib/rb_sys/cargo_builder.rb', line 50 def build_crate(dest_path, results, args, cargo_dir) env = build_env cmd = cargo_command(dest_path, args) runner.call cmd, results, "cargo", cargo_dir, env results end |
#build_env ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 59 60 61 62 |
# File 'lib/rb_sys/cargo_builder.rb', line 58 def build_env build_env = rb_config_env build_env["RUBY_STATIC"] = "true" if ruby_static? && ENV.key?("RUBY_STATIC") build_env.merge(env) end |
#cargo_command(dest_path, args = []) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/rb_sys/cargo_builder.rb', line 68 def cargo_command(dest_path, args = []) cmd = [] cmd += if config.use_cargo_build ["cargo", "build"] else ["cargo", "rustc"] end cmd += ["--target", target] if target cmd += ["--target-dir", dest_path] cmd += ["--features", features.join(",")] unless features.empty? cmd += ["--lib"] cmd += ["--profile", profile.to_s] cmd += Gem::Command.build_args cmd += args if !config.use_cargo_build cmd += ["--"] cmd += [*rustc_args(dest_path)] cmd += extra_rustc_args end cmd end |
#cargo_dylib_path(dest_path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
90 91 92 93 94 95 96 |
# File 'lib/rb_sys/cargo_builder.rb', line 90 def cargo_dylib_path(dest_path) prefix = (so_ext == "dll") ? "" : "lib" path_parts = [dest_path] path_parts << target if target path_parts += [profile_target_directory, "#{prefix}#{cargo_crate_name}.#{so_ext}"] File.join(*path_parts) end |
#manifest_dir ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
64 65 66 |
# File 'lib/rb_sys/cargo_builder.rb', line 64 def manifest_dir ext_dir end |
#rubygems_invoked? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
114 115 116 |
# File 'lib/rb_sys/cargo_builder.rb', line 114 def rubygems_invoked? ENV.key?("SOURCE_DATE_EPOCH") && ENV["RB_SYS_TEST"] != "1" && !ENV.key?("NIX_STORE") end |
#so_ext ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
We have to basically reimplement RbConfig::CONFIG here to support Ruby < 2.5
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rb_sys/cargo_builder.rb', line 102 def so_ext return RbConfig::CONFIG["SOEXT"] if RbConfig::CONFIG.key?("SOEXT") if win_target? "dll" elsif darwin_target? "dylib" else "so" end end |