Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Generator for LLVM::CONFIG module #14

Closed
wants to merge 1 commit into from

2 participants

@jvoorhis
Owner

Builds LLVM::CONFIG at install time. Example: https://gist.github.com/4562750

@jvoorhis
Owner

Submitting this for review. /cc @whitequark

@whitequark
Owner

I didn't have a chance to try this pull request out, as the branch for some weird reason is not present in your repository, but the diff looks fine to me.

@whitequark
Owner

Oh, it's github not showing repository names. I've found a bug (which makes me think about adding Travis CI; but Ubuntu doesn't have recent enough LLVM AFAIK), and I think I can clean it up a bit. I'll send another PR when I'll finish it.

@jvoorhis jvoorhis closed this in c8f395b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 18, 2013
  1. @jvoorhis
This page is out of date. Refresh to see the latest.
Showing with 50 additions and 27 deletions.
  1. +2 −1  .gitignore
  2. +48 −7 ext/ruby-llvm-support/Rakefile
  3. +0 −19 lib/llvm/version.rb
View
3  .gitignore
@@ -12,4 +12,5 @@
coverage/*
doc/*
.bundle
-Gemfile.lock
+Gemfile.lock
+lib/llvm/config.rb
View
55 ext/ruby-llvm-support/Rakefile
@@ -2,8 +2,8 @@ require 'rake/clean'
require 'rubygems'
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`
@@ -28,15 +28,56 @@ LLVM_CONFIG = invoke_llvm_config('--cxxflags --ldflags')
CXX = "g++"
SRC = "support.cpp"
-OUTPUT = FFI.map_library_name("RubyLLVMSupport-#{LLVM_VERSION}")
+SUPPORT_LIB = FFI.map_library_name("RubyLLVMSupport-#{LLVM_VERSION}")
-CLEAN.include(OUTPUT)
+
+CLEAN.include(SUPPORT_LIB)
task :default => [:build]
-desc "Build the shared library"
-task :build => [OUTPUT]
+desc "Build the shared library and config module"
+task :build => [SUPPORT_LIB, :config]
-file OUTPUT => [SRC] do
+file SUPPORT_LIB => [SRC] do
sh "#{CXX} -shared -lLLVM-#{LLVM_VERSION} #{SRC} #{LLVM_CONFIG} -o #{OUTPUT}"
end
+
+MOD_LLVM_CONFIG = File.expand_path('../../lib/llvm/config.rb', File.dirname(__FILE__))
+LLVM_CONFIG_OPTS = [
+ ['VERSION', :string, '--version'],
+ ['PREFIX', :string, '--prefix'],
+ ['SRC_ROOT', :string, '--src-root'],
+ ['OBJ_ROOT', :string, '--obj-root'],
+ ['BIN_DIR', :string, '--bindir'],
+ ['INCLUDE_DIR', :string, '--includedir'],
+ ['LIB_DIR', :string, '--libdir'],
+ ['CPP_FLAGS', :array, '--cppflags'],
+ ['C_FLAGS', :array, '--cflags'],
+ ['CXX_FLAGS', :array, '--cxxflags'],
+ ['LD_FLAGS', :array, '--ldflags'],
+ ['LIBS', :array, '--libs'],
+ ['LIB_NAMES', :array, '--libnames'],
+ ['LIB_FILES', :array, '--libfiles'],
+ ['COMPONENTS', :array, '--components'],
+ ['TARGETS_BUILT', :array, '--targets-built'],
+ ['HOST_TARGET', :string, '--host-target'],
+ ['BUILD_MODE', :string, '--build-mode'],
+]
+
+task :config do
+ open(MOD_LLVM_CONFIG, '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
View
19 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
Something went wrong with that request. Please try again.