Class: RbSys::CargoBuilder::LinkFlagConverter Private

Inherits:
Object
  • Object
show all
Defined in:
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.

Converts Ruby link flags into something cargo understands

Constant Summary collapse

FILTERED_PATTERNS =

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.

[
  /compress-debug-sections/, # Not supported by all linkers, and not required for Rust
  /^\s*-s\s*$/
]

Class Method Summary collapse

Class Method Details

.convert(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.



15
16
17
# File 'lib/rb_sys/cargo_builder/link_flag_converter.rb', line 15

def self.convert(args)
  Shellwords.split(args).flat_map { |arg| convert_arg(arg) }
end

.convert_arg(arg) ⇒ 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.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rb_sys/cargo_builder/link_flag_converter.rb', line 19

def self.convert_arg(arg)
  return [] if FILTERED_PATTERNS.any? { |p| p.match?(arg) }

  case arg.chomp
  when /^-L\s*(.+)$/
    ["-L", "native=#{$1}"]
  when /^--library=(\w+\S+)$/, /^-l\s*(\w+\S+)$/
    ["-l", $1]
  when /^-l\s*:lib(\S+).(so|dylib|dll)$/
    ["-l", "dylib=#{$1}"]
  when /^-F\s*(.*)$/
    ["-l", "framework=#{$1}"]
  else
    ["-C", "link-arg=#{arg}"]
  end
end