Skip to content

Commit dfda9d6

Browse files
committed
Merge pull request #104 from larskanis/x64-mingw32-lars
More Windows x64 support
2 parents 75f502f + 13c1b51 commit dfda9d6

File tree

4 files changed

+81
-29
lines changed

4 files changed

+81
-29
lines changed

Gemfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- ruby -*-
2+
3+
# DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
4+
5+
source "https://rubygems.org/"
6+
7+
8+
gem "minitest", "~>5.0", :group => [:development, :test]
9+
gem "rdoc", "~>4.0", :group => [:development, :test]
10+
gem "rake-compiler", "~>0.9.1", :group => [:development, :test]
11+
gem "mini_portile", "~>0.2.2", :group => [:development, :test]
12+
gem "hoe-bundler", "~>1.0", :group => [:development, :test]
13+
gem "hoe", "~>3.7", :group => [:development, :test]
14+
15+
# vim: syntax=ruby

tasks/gem.rake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ rescue LoadError
66
require 'hoe'
77
end
88

9-
Hoe.plugin :debugging, :doofus, :git, :minitest
9+
Hoe.plugin :debugging, :doofus, :git, :minitest, :bundler
1010

1111
HOE = Hoe.spec 'sqlite3' do
1212
developer 'Jamis Buck', 'jamis@37signals.com'
@@ -23,9 +23,10 @@ HOE = Hoe.spec 'sqlite3' do
2323
spec_extras[:extensions] = ["ext/sqlite3/extconf.rb"]
2424
spec_extras[:license] = "MIT"
2525

26-
extra_dev_deps << ['rake-compiler', "~> 0.8.2"]
26+
extra_dev_deps << ['rake-compiler', "~> 0.9.1"]
2727
extra_dev_deps << ["mini_portile", "~> 0.2.2"]
2828
extra_dev_deps << ["minitest", "~> 5.0"]
29+
extra_dev_deps << ["hoe-bundler", "~> 1.0"]
2930

3031
clean_globs.push('**/test.db')
3132
end

tasks/native.rake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ require 'rake/extensiontask'
44
# NOTE: version used by cross compilation of Windows native extension
55
# It do not affect compilation under other operating systems
66
# The version indicated is the minimum DLL suggested for correct functionality
7-
BINARY_VERSION = "3.7.13"
8-
URL_VERSION = "3071300"
7+
BINARY_VERSION = "3.7.17"
8+
URL_VERSION = "3071700"
9+
URL_PATH = "/2013"
910

1011
# build sqlite3_native C extension
11-
Rake::ExtensionTask.new('sqlite3_native', HOE.spec) do |ext|
12+
RUBY_EXTENSION = Rake::ExtensionTask.new('sqlite3_native', HOE.spec) do |ext|
1213
# where to locate the extension
1314
ext.ext_dir = 'ext/sqlite3'
1415

@@ -26,8 +27,7 @@ Rake::ExtensionTask.new('sqlite3_native', HOE.spec) do |ext|
2627
ext.config_options << "--enable-local"
2728
else
2829
ext.cross_compile = true
29-
ext.cross_platform = ['i386-mswin32-60', 'i386-mingw32']
30-
ext.cross_config_options << "--enable-local"
30+
ext.cross_platform = ['i386-mswin32-60', 'i386-mingw32', 'x64-mingw32']
3131
end
3232
end
3333

tasks/vendor_sqlite3.rake

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ require "rake/clean"
22
require "rake/extensioncompiler"
33
require "mini_portile"
44

5-
$recipes = {}
5+
CLOBBER.include("ports")
66

7-
$recipes[:sqlite3] = MiniPortile.new "sqlite3", BINARY_VERSION
8-
$recipes[:sqlite3].files << "http://sqlite.org/sqlite-autoconf-#{URL_VERSION}.tar.gz"
7+
directory "ports"
98

10-
namespace :ports do
11-
directory "ports"
9+
def define_sqlite_task(platform, host)
10+
recipe = MiniPortile.new "sqlite3", BINARY_VERSION
11+
recipe.files << "http://sqlite.org#{URL_PATH}/sqlite-autoconf-#{URL_VERSION}.tar.gz"
12+
recipe.host = host
1213

13-
desc "Install port sqlite3 #{$recipes[:sqlite3].version}"
14-
task :sqlite3 => ["ports"] do
15-
recipe = $recipes[:sqlite3]
14+
desc "Compile sqlite3 for #{platform} (#{host})"
15+
task "ports:sqlite3:#{platform}" => ["ports"] do |t|
1616
checkpoint = "ports/.#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
1717

1818
unless File.exist?(checkpoint)
@@ -22,30 +22,66 @@ namespace :ports do
2222
recipe.cook
2323
touch checkpoint
2424
end
25-
26-
recipe.activate
2725
end
26+
27+
recipe
2828
end
2929

30+
# native sqlite3 compilation
31+
define_sqlite_task RUBY_PLATFORM, RbConfig::CONFIG["host"]
32+
33+
# trick to test local compilation of sqlite3
34+
if ENV["USE_MINI_PORTILE"] == "true"
35+
# fake recipe so we can build a directory to it
36+
recipe = MiniPortile.new "sqlite3", BINARY_VERSION
37+
recipe.host = RbConfig::CONFIG["host"]
38+
39+
RUBY_EXTENSION.config_options << "--with-opt-dir=#{recipe.path}"
40+
41+
# compile sqlite3 first
42+
Rake::Task["compile"].prerequisites.unshift "ports:sqlite3:#{RUBY_PLATFORM}"
43+
end
44+
45+
# force compilation of sqlite3 when working natively under MinGW
3046
if RUBY_PLATFORM =~ /mingw/
31-
Rake::Task['compile'].prerequisites.unshift "ports:sqlite3"
47+
Rake::Task['compile'].prerequisites.unshift "ports:sqlite3:#{RUBY_PLATFORM}"
3248
end
3349

34-
if ENV["USE_MINI_PORTILE"] == "true"
35-
Rake::Task["compile"].prerequisites.unshift "ports:sqlite3"
50+
# iterate over all cross-compilation platforms and define the proper
51+
# sqlite3 recipe for it.
52+
if RUBY_EXTENSION.cross_compile
53+
config_path = File.expand_path("~/.rake-compiler/config.yml")
54+
if File.exist?(config_path)
55+
# obtains platforms from rake-compiler's config.yml
56+
config_file = YAML.load_file(config_path)
57+
58+
Array(RUBY_EXTENSION.cross_platform).each do |platform|
59+
# obtain platform from rbconfig file
60+
config_key = config_file.keys.sort.find { |key|
61+
key.start_with?("rbconfig-#{platform}-")
62+
}
63+
rbfile = config_file[config_key]
64+
65+
# skip if rbconfig cannot be read
66+
next unless File.exist?(rbfile)
67+
68+
host = IO.read(rbfile).match(/CONFIG\["CC"\] = "(.*)"/)[1].sub(/\-gcc/, '')
69+
recipe = define_sqlite_task(platform, host)
70+
71+
RUBY_EXTENSION.cross_config_options << {
72+
platform => "--with-opt-dir=#{recipe.path}"
73+
}
74+
75+
# pre-compile sqlite3 port when cross-compiling
76+
task :cross => "ports:sqlite3:#{platform}"
77+
end
78+
else
79+
warn "rake-compiler configuration doesn't exist, but is required for ports"
80+
end
3681
end
3782

3883
task :cross do
3984
["CC", "CXX", "LDFLAGS", "CPPFLAGS", "RUBYOPT"].each do |var|
4085
ENV.delete(var)
4186
end
42-
host = ENV.fetch("HOST", Rake::ExtensionCompiler.mingw_host)
43-
$recipes.each do |_, recipe|
44-
recipe.host = host
45-
end
46-
47-
# hook compile task with dependencies
48-
Rake::Task["compile"].prerequisites.unshift "ports:sqlite3"
4987
end
50-
51-
CLOBBER.include("ports")

0 commit comments

Comments
 (0)