Module: Libv8::Compiler

Defined in:
ext/libv8/compiler.rb,
ext/libv8/compiler/gcc.rb,
ext/libv8/compiler/clang.rb,
ext/libv8/compiler/apple_llvm.rb,
ext/libv8/compiler/generic_compiler.rb

Defined Under Namespace

Classes: AppleLLVM, Clang, ExecutionResult, GCC, GenericCompiler

Class Method Summary collapse

Class Method Details

.available?(command) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'ext/libv8/compiler.rb', line 53

def available?(command)
  execute_command("which #{command} 2>&1").status.success?
end

.available_compilers(*compiler_names) ⇒ Object



29
30
31
32
# File 'ext/libv8/compiler.rb', line 29

def available_compilers(*compiler_names)
  available = compiler_names.select { |compiler_name| available? compiler_name }
  available.map { |compiler_name| type_of(compiler_name).new compiler_name }
end

.execute_command(command) ⇒ Object



57
58
59
60
61
# File 'ext/libv8/compiler.rb', line 57

def execute_command(command)
  output = `env LC_ALL=C LANG=C #{command}`
  status = $?
  ExecutionResult.new output, status
end

.type_of(compiler_name) ⇒ Object



34
35
36
37
38
39
40
41
# File 'ext/libv8/compiler.rb', line 34

def type_of(compiler_name)
  case version_string_of(compiler_name)
  when /^Apple LLVM\b/ then AppleLLVM
  when /\bclang\b/i then Clang
  when /^gcc/i then GCC
  else GenericCompiler
  end
end

.version_string_of(compiler_name) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'ext/libv8/compiler.rb', line 43

def version_string_of(compiler_name)
  command_result = execute_command "#{compiler_name} -v 2>&1"

  unless command_result.status.success?
    raise "Could not get version string of compiler #{compiler_name}"
  end

  command_result.output
end

.well_known_compilersObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'ext/libv8/compiler.rb', line 11

def well_known_compilers
  compilers = []

  # The command Ruby was compiled with
  compilers << RbConfig::CONFIG['CXX']

  # The default system compiler
  compilers << 'c++'

  # FreeBSD GCC command names
  compilers += ['g++48', 'g++49', 'g++5']

  # Default compiler names
  compilers += ['clang++', 'g++']

  compilers.uniq
end