Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator for LLVM::CONFIG module, cleaned up #15

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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