Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Closed
wants to merge 2 commits into from

2 participants

@whitequark
Owner

This pull request is a follow up for #14.

  • I've fixed a typo preventing the extension/config module from being built.
  • I've removed all config options related to LLVM source or libraries. Ruby-LLVM requires LLVM to be built as a monolithic .so, and it is definitely redistributed without LLVM sources, hence there is no use case for these options.
  • I've also removed LLVM::CONFIG::VERSION, as there's already LLVM::LLVM_VERSION.
@jvoorhis
Owner

Closed by c8f395b.

@jvoorhis jvoorhis closed this
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
  2. @whitequark
This page is out of date. Refresh to see the latest.
Showing with 39 additions and 30 deletions.
  1. +2 −1  .gitignore
  2. +37 −10 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
47 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`
@@ -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
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.