Class: RbSys::ToolchainInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/rb_sys/toolchain_info.rb,
lib/rb_sys/toolchain_info/data.rb

Overview

A class to get information about the Rust toolchains, and how they map to Ruby platforms.

Examples:

RbSys::ToolchainInfo.new("x86_64-unknown-linux-gnu").ruby_platform # => "x86_64-linux"
RbSys::ToolchainInfo.new("x86_64-unknown-linux-gnu").supported? # => true
RbSys::ToolchainInfo.new("x86_64-unknown-linux-gnu")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform) ⇒ ToolchainInfo

Create a new toolchain info object.

Parameters:

  • platform (String)

    The platform to get information about.



49
50
51
52
53
54
55
56
57
58
# File 'lib/rb_sys/toolchain_info.rb', line 49

def initialize(platform)
  @platform = platform
  @gem_platform = Gem::Platform.new(platform)
  data = DATA[platform] || DATA["#{gem_platform.cpu}-#{gem_platform.os}"] || raise(ArgumentError, "unknown ruby platform: #{platform.inspect}")
  @rust_target = data["rust-target"]
  @rake_compiler_dock_cc = data["rake-compiler-dock"]["cc"]
  @supported = data["supported"]
  @rake_compiler_dock_image = "rbsys/#{platform}:#{RbSys::VERSION}"
  @docker_platform = data["docker-platform"]
end

Instance Attribute Details

#docker_platformObject (readonly)

Returns the value of attribute docker_platform.



14
15
16
# File 'lib/rb_sys/toolchain_info.rb', line 14

def docker_platform
  @docker_platform
end

#gem_platformObject (readonly)

Returns the value of attribute gem_platform.



14
15
16
# File 'lib/rb_sys/toolchain_info.rb', line 14

def gem_platform
  @gem_platform
end

#platformObject (readonly)

Returns the value of attribute platform.



14
15
16
# File 'lib/rb_sys/toolchain_info.rb', line 14

def platform
  @platform
end

#rake_compiler_dock_ccObject (readonly)

Returns the value of attribute rake_compiler_dock_cc.



14
15
16
# File 'lib/rb_sys/toolchain_info.rb', line 14

def rake_compiler_dock_cc
  @rake_compiler_dock_cc
end

#rake_compiler_dock_imageObject (readonly)

Returns the value of attribute rake_compiler_dock_image.



14
15
16
# File 'lib/rb_sys/toolchain_info.rb', line 14

def rake_compiler_dock_image
  @rake_compiler_dock_image
end

#rust_targetObject (readonly)

Returns the value of attribute rust_target.



14
15
16
# File 'lib/rb_sys/toolchain_info.rb', line 14

def rust_target
  @rust_target
end

#supportedObject (readonly)

Returns the value of attribute supported.



14
15
16
# File 'lib/rb_sys/toolchain_info.rb', line 14

def supported
  @supported
end

Class Method Details

.allArray<RbSys::ToolchainInfo>

Get all known toolchains.

Returns:



20
21
22
# File 'lib/rb_sys/toolchain_info.rb', line 20

def all
  @all ||= DATA.keys.map { |k| new(k) }
end

.localRbSys::ToolchainInfo

Get the toolchain for the current platform.



41
42
43
# File 'lib/rb_sys/toolchain_info.rb', line 41

def local
  @current ||= new(RbConfig::CONFIG["arch"])
end

.supportedArray<RbSys::ToolchainInfo>

Get all supported toolchains.

Returns:



27
28
29
# File 'lib/rb_sys/toolchain_info.rb', line 27

def supported
  @supported ||= all.select(&:supported?)
end

.supported_ruby_platformsArray<String>

Get all supported toolchain names, as strings.

Returns:

  • (Array<String>)


34
35
36
# File 'lib/rb_sys/toolchain_info.rb', line 34

def supported_ruby_platforms
  supported.map(&:platform)
end

Instance Method Details

#==(other) ⇒ Boolean

Compare two toolchains.

Parameters:

Returns:

  • (Boolean)


78
79
80
# File 'lib/rb_sys/toolchain_info.rb', line 78

def ==(other)
  @gem_platform == other.gem_platform
end

#supported?Boolean

Whether this toolchain is supported.

Returns:

  • (Boolean)


63
64
65
# File 'lib/rb_sys/toolchain_info.rb', line 63

def supported?
  @supported
end

#to_sString

String representation of the toolchain.

Returns:

  • (String)


70
71
72
# File 'lib/rb_sys/toolchain_info.rb', line 70

def to_s
  "#{gem_platform.cpu}-#{gem_platform.os}"
end