Skip to content

Commit cbf2af5

Browse files
committed
WiP: attempt to cross-compile everything
Compiling sqlite3 is becoming a challenge using mini_portile and rake-compiler. Testing this inside a Ubuntu VM is resulting into errors about GCC not been able to find the header files or the library files. This requires further exploration to work properly. Most likely: mini_portile will be removed and usage of knapsack packages will be enforced instead.
1 parent d7bc3dd commit cbf2af5

File tree

1 file changed

+46
-34
lines changed

1 file changed

+46
-34
lines changed

tasks/vendor_sqlite3.rake

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

5+
CLOBBER.include("ports")
6+
7+
directory "ports"
8+
59
def define_sqlite_task(platform, host)
6-
task "sqlite3:#{platform}" => ["ports"] do |t|
10+
desc "Compile sqlite3 for #{platform} (#{host})"
11+
task "ports:sqlite3:#{platform}" => ["ports"] do |t|
712
recipe = MiniPortile.new "sqlite3", BINARY_VERSION
813
recipe.files << "http://sqlite.org/sqlite-autoconf-#{URL_VERSION}.tar.gz"
914
recipe.host = host
@@ -20,54 +25,61 @@ def define_sqlite_task(platform, host)
2025

2126
recipe.activate
2227
end
23-
24-
task :sqlite3 => ["sqlite3:#{platform}"]
2528
end
2629

30+
# native sqlite3 compilation
31+
define_sqlite_task RUBY_PLATFORM, RbConfig::CONFIG["host"]
2732

28-
# HACK: Use rake-compilers config.yml to determine the toolchain that was used
29-
# to build Ruby for this platform.
30-
# This is probably something that could be provided by rake-compiler.gem.
31-
def host_for_platform(for_platform)
32-
begin
33-
config_file = YAML.load_file(File.expand_path("~/.rake-compiler/config.yml"))
34-
_, rbfile = config_file.find{|key, fname| key.start_with?("rbconfig-#{for_platform}-") }
35-
IO.read(rbfile).match(/CONFIG\["host"\] = "(.*)"/)[1]
36-
rescue
37-
nil
38-
end
39-
end
40-
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"]
4138

42-
namespace :ports do
43-
directory "ports"
39+
RUBY_EXTENSION.config_options << "--enable-local --with-sqlite3-dir=#{recipe.path}"
4440

45-
desc "Install port sqlite3"
46-
define_sqlite_task(RUBY_PLATFORM, RbConfig::CONFIG['host'])
41+
# compile sqlite3 first
42+
Rake::Task["compile"].prerequisites.unshift "ports:sqlite3:#{RUBY_PLATFORM}"
4743
end
4844

45+
# force compilation of sqlite3 when working natively under MinGW
4946
if RUBY_PLATFORM =~ /mingw/
50-
Rake::Task['compile'].prerequisites.unshift "ports:sqlite3"
47+
Rake::Task['compile'].prerequisites.unshift "ports:sqlite3:#{RUBY_PLATFORM}"
5148
end
5249

53-
if ENV["USE_MINI_PORTILE"] == "true"
54-
Rake::Task["compile"].prerequisites.unshift "ports:sqlite3"
55-
end
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)
5657

57-
task :cross do
58-
namespace :ports do
59-
["CC", "CXX", "LDFLAGS", "CPPFLAGS", "RUBYOPT"].each do |var|
60-
ENV.delete(var)
61-
end
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\["host"\] = "(.*)"/)[1]
69+
puts "platform: #{platform}, host: #{host}"
6270

63-
# TODO: Use ExtensionTask#cross_platform array
64-
['i386-mswin32-60', 'i386-mingw32', 'x64-mingw32'].each do |platform|
65-
define_sqlite_task(platform, host_for_platform(platform))
71+
define_sqlite_task platform, host
6672

67-
# hook compile task with dependencies
73+
# hook compile task for the right platform
6874
Rake::Task["compile:#{platform}"].prerequisites.unshift "ports:sqlite3:#{platform}"
6975
end
76+
else
77+
warn "rake-compiler configuration doesn't exist, but is required for ports"
7078
end
7179
end
7280

73-
CLOBBER.include("ports")
81+
task :cross do
82+
["CC", "CXX", "LDFLAGS", "CPPFLAGS", "RUBYOPT"].each do |var|
83+
ENV.delete(var)
84+
end
85+
end

0 commit comments

Comments
 (0)