Skip to content

Commit

Permalink
Merge #15 (closes #14). Updated target_test.rb.
Browse files Browse the repository at this point in the history
  • Loading branch information
jvoorhis committed Jan 22, 2013
1 parent c167b6a commit c8f395b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -12,4 +12,5 @@
coverage/*
doc/*
.bundle
Gemfile.lock
Gemfile.lock
lib/llvm/config.rb
47 changes: 37 additions & 10 deletions ext/ruby-llvm-support/Rakefile
@@ -1,9 +1,9 @@
require 'rake/clean'
require 'rubygems'
require 'rake/clean'
require 'ffi'

# Change this when updating for a newer LLVM.
LLVM_VERSION = '3.2'
require File.expand_path('../../lib/llvm/version', File.dirname(__FILE__))
include LLVM

def check_llvm_config(name)
actual_version = `#{name} --version`
Expand All @@ -28,15 +28,42 @@ LLVM_CONFIG = invoke_llvm_config('--cxxflags --ldflags')

CXX = "g++"
SRC = "support.cpp"
OUTPUT = FFI.map_library_name("RubyLLVMSupport-#{LLVM_VERSION}")

CLEAN.include(OUTPUT)
SUPPORT_LIB = FFI.map_library_name("RubyLLVMSupport-#{LLVM_VERSION}")
CONFIG_MOD = File.expand_path('../../lib/llvm/config.rb', File.dirname(__FILE__))

CLEAN.include(SUPPORT_LIB, CONFIG_MOD)

task :default => [:build]
desc "Build the shared library and config module"
task :default => [SUPPORT_LIB, CONFIG_MOD]

file SUPPORT_LIB => [SRC] do
sh "#{CXX} -shared -lLLVM-#{LLVM_VERSION} #{SRC} #{LLVM_CONFIG} -o #{SUPPORT_LIB}"
end

desc "Build the shared library"
task :build => [OUTPUT]
LLVM_CONFIG_OPTS = [
['COMPONENTS', :array, '--components'],
['TARGETS_BUILT', :array, '--targets-built'],
['HOST_TARGET', :string, '--host-target'],
['BUILD_MODE', :string, '--build-mode'],
]

file OUTPUT => [SRC] do
sh "#{CXX} -shared -lLLVM-#{LLVM_VERSION} #{SRC} #{LLVM_CONFIG} -o #{OUTPUT}"
file CONFIG_MOD do
open(CONFIG_MOD, 'w') do |f|
f.puts '# Generated by ruby-llvm. Please do not change this file by hand.'
f.puts 'module LLVM'
f.puts ' module CONFIG'

LLVM_CONFIG_OPTS.each do |(const, fmt, flag)|
case fmt
when :string
f.puts ' ' << const << ' = ' << invoke_llvm_config(flag).strip.inspect
when :array
f.puts ' ' << const << ' = ' << invoke_llvm_config(flag).strip.split.inspect
end
end

f.puts ' end'
f.puts 'end'
end
end
19 changes: 0 additions & 19 deletions lib/llvm/version.rb
@@ -1,23 +1,4 @@
require 'find'

module LLVM
LLVM_VERSION = "3.2"
RUBY_LLVM_VERSION = "3.2.0.beta.1"
LLVM_CONFIG = begin
variants = %W(llvm-config-#{LLVM_VERSION} llvm-config)
llvm_config = nil
catch :done do
paths = ENV['PATH'].split(File::PATH_SEPARATOR).select(&File.method(:directory?))
Find.find(*paths) do |path|
if variants.include?(File.basename(path))
actual_version = `#{path} --version`.chomp
if LLVM_VERSION == actual_version
llvm_config = path
throw(:done)
end
end
end
end
llvm_config
end
end
3 changes: 2 additions & 1 deletion test/target_test.rb
@@ -1,5 +1,6 @@
require "test_helper"
require 'llvm/version'
require 'llvm/config'

class TargetTestCase < Test::Unit::TestCase

Expand All @@ -14,7 +15,7 @@ def test_init_native
assert_nothing_raised { LLVM::Target.init_native(true) }
end

if `#{LLVM::LLVM_CONFIG} --targets-built` =~ /ARM/
if LLVM::CONFIG::TARGETS_BUILT.include?('ARM')
def test_init_arm
assert_nothing_raised { LLVM::Target.init('ARM') }
assert_nothing_raised { LLVM::Target.init('ARM', true) }
Expand Down

0 comments on commit c8f395b

Please sign in to comment.