Class: Gem::Ext::CargoBuilder::LinkFlagConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems/ext/cargo_builder/link_flag_converter.rb

Overview

Converts Ruby link flags into something cargo understands

Constant Summary collapse

FILTERED_PATTERNS =
[
  /compress-debug-sections/, # Not supported by all linkers, and not required for Rust
].freeze

Class Method Summary collapse

Class Method Details

.convert(arg) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rubygems/ext/cargo_builder/link_flag_converter.rb', line 10

def self.convert(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*([^:\s])+/ # -lfoo, but not -l:libfoo.a
    ["-l", $1]
  when /^-F\s*(.*)$/
    ["-l", "framework=#{$1}"]
  else
    ["-C", "link-args=#{arg}"]
  end
end