Skip to content

Commit

Permalink
Merge branch 'use-packaged-libxml'
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Apr 14, 2013
2 parents 4563e8c + e811c08 commit f897a2e
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 63 deletions.
24 changes: 23 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,23 @@ HOE = Hoe.spec 'nokogiri' do
["hoe-debugging", ">= 1.0.3"],
["hoe-gemspec", ">= 1.0"],
["hoe-git", ">= 1.4"],
["mini_portile", ">= 0.2.2"],
["minitest", "~> 2.2.2"],
["rake", ">= 0.9"],
["rake-compiler", "~> 0.8.0"],
["racc", ">= 1.4.6"],
["rexical", ">= 1.0.5"]
]

if ENV['BUILD_LIBXML2']
self.extra_deps += [
["mini_portile", "~> 0.5.0"],
]
else
self.extra_dev_deps += [
["mini_portile", "~> 0.5.0"],
]
end

if java?
self.spec_extras = { :platform => 'java' }
else
Expand Down Expand Up @@ -106,6 +115,19 @@ else

HOE.spec.files.reject! { |f| f =~ %r{\.(java|jar)$} }

if ENV['BUILD_LIBXML2']
task gem_build_path do
add_file_to_gem "dependencies.yml"

dependencies = YAML.load_file("dependencies.yml")
%w[libxml2 libxslt].each do |lib|
version = dependencies[lib]
archive = File.join("ports", "archives", "#{lib}-#{version}.tar.gz")
add_file_to_gem archive
end
end
end

Rake::ExtensionTask.new("nokogiri", HOE.spec) do |ext|
ext.lib_dir = File.join(*['lib', 'nokogiri', ENV['FAT_DIR']].compact)
ext.config_options << ENV['EXTOPTS']
Expand Down
4 changes: 4 additions & 0 deletions dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
libxml2: "2.8.0"
libxslt: "1.1.26"
zlib: "1.2.7"
libiconv: "1.13.1"
135 changes: 95 additions & 40 deletions ext/nokogiri/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,46 +49,100 @@
else
lib_prefix = ''

HEADER_DIRS = [
# First search /opt/local for macports
'/opt/local/include',

# Then search /usr/local for people that installed from source
'/usr/local/include',

# Check the ruby install locations
INCLUDEDIR,

# Finally fall back to /usr
'/usr/include',
'/usr/include/libxml2',
]

LIB_DIRS = [
# First search /opt/local for macports
'/opt/local/lib',

# Then search /usr/local for people that installed from source
'/usr/local/lib',

# Check the ruby install locations
LIBDIR,

# Finally fall back to /usr
'/usr/lib',
]

XML2_HEADER_DIRS = [
'/opt/local/include/libxml2',
'/usr/local/include/libxml2',
File.join(INCLUDEDIR, "libxml2")
] + HEADER_DIRS

# If the user has homebrew installed, use the libxml2 inside homebrew
brew_prefix = `brew --prefix libxml2 2> /dev/null`.chomp
unless brew_prefix.empty?
LIB_DIRS.unshift File.join(brew_prefix, 'lib')
XML2_HEADER_DIRS.unshift File.join(brew_prefix, 'include/libxml2')
if ENV['NOKOGIRI_USE_SYSTEM_LIBRARIES']
HEADER_DIRS = [
# First search /opt/local for macports
'/opt/local/include',

# Then search /usr/local for people that installed from source
'/usr/local/include',

# Check the ruby install locations
INCLUDEDIR,

# Finally fall back to /usr
'/usr/include',
'/usr/include/libxml2',
]

LIB_DIRS = [
# First search /opt/local for macports
'/opt/local/lib',

# Then search /usr/local for people that installed from source
'/usr/local/lib',

# Check the ruby install locations
LIBDIR,

# Finally fall back to /usr
'/usr/lib',
]

XML2_HEADER_DIRS = [
'/opt/local/include/libxml2',
'/usr/local/include/libxml2',
File.join(INCLUDEDIR, "libxml2")
] + HEADER_DIRS

# If the user has homebrew installed, use the libxml2 inside homebrew
brew_prefix = `brew --prefix libxml2 2> /dev/null`.chomp
unless brew_prefix.empty?
LIB_DIRS.unshift File.join(brew_prefix, 'lib')
XML2_HEADER_DIRS.unshift File.join(brew_prefix, 'include/libxml2')
end

else
require 'mini_portile'
require 'yaml'

common_recipe = lambda do |recipe|
recipe.target = File.join(ROOT, "ports")
recipe.files = ["ftp://ftp.xmlsoft.org/libxml2/#{recipe.name}-#{recipe.version}.tar.gz"]

checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
unless File.exist?(checkpoint)
recipe.cook
FileUtils.touch checkpoint
end
recipe.activate
end

dependencies = YAML.load_file(File.join(ROOT, "dependencies.yml"))

libxml2_recipe = MiniPortile.new("libxml2", dependencies["libxml2"]).tap do |recipe|
recipe.configure_options = [
"--enable-shared",
"--disable-static",
"--without-python",
"--without-readline",
"--with-c14n",
"--with-debug",
"--with-threads"
]
common_recipe.call recipe
end

libxslt_recipe = MiniPortile.new("libxslt", dependencies["libxslt"]).tap do |recipe|
recipe.configure_options = [
"--enable-shared",
"--disable-static",
"--without-python",
"--without-crypto",
"--with-debug",
"--with-libxml-prefix=#{libxml2_recipe.path}"
]
common_recipe.call recipe
end

$LDFLAGS << " -Wl,-rpath,#{libxml2_recipe.path}/lib"
$LDFLAGS << " -Wl,-rpath,#{libxslt_recipe.path}/lib"

$CFLAGS << " -DNOKOGIRI_USE_PACKAGED_LIBRARIES"

HEADER_DIRS = [libxml2_recipe, libxslt_recipe].map { |_| File.join(_.path, "include") }
LIB_DIRS = [libxml2_recipe, libxslt_recipe].map { |_| File.join(_.path, "lib") }
XML2_HEADER_DIRS = HEADER_DIRS + [File.join(libxml2_recipe.path, "include", "libxml2")]
end
end

Expand Down Expand Up @@ -141,4 +195,5 @@ def have_iconv?
end

create_makefile('nokogiri/nokogiri')

# :startdoc:
6 changes: 6 additions & 0 deletions ext/nokogiri/nokogiri.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ void Init_nokogiri()
NOKOGIRI_STR_NEW2(xmlParserVersion)
);

#ifdef NOKOGIRI_USE_PACKAGED_LIBRARIES
rb_const_set(mNokogiri, rb_intern("NOKOGIRI_USE_PACKAGED_LIBRARIES"), Qtrue);
#else
rb_const_set(mNokogiri, rb_intern("NOKOGIRI_USE_PACKAGED_LIBRARIES"), Qfalse);
#endif

#ifdef LIBXML_ICONV_ENABLED
rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qtrue);
#else
Expand Down
9 changes: 9 additions & 0 deletions lib/nokogiri/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def libxml2?
defined?(LIBXML_VERSION)
end

def libxml2_using_system?
! libxml2_using_packaged?
end

def libxml2_using_packaged?
NOKOGIRI_USE_PACKAGED_LIBRARIES
end

def warnings
return [] unless libxml2?

Expand All @@ -49,6 +57,7 @@ def to_hash
if libxml2?
hash_info['libxml'] = {}
hash_info['libxml']['binding'] = 'extension'
hash_info['libxml']['source'] = libxml2_using_packaged? ? "packaged" : "system"
hash_info['libxml']['compiled'] = compiled_parser_version
hash_info['libxml']['loaded'] = loaded_parser_version
hash_info['warnings'] = warnings
Expand Down
26 changes: 4 additions & 22 deletions tasks/cross_compile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
HOST = Rake::ExtensionCompiler.mingw_host

require 'mini_portile'
dependencies = YAML.load_file("dependencies.yml")
$recipes = {}
$recipes["zlib"] = MiniPortile.new "zlib", "1.2.7"
$recipes["libiconv"] = MiniPortile.new "libiconv", "1.13.1"
$recipes["libxml2"] = MiniPortile.new "libxml2", "2.7.7"
$recipes["libxslt"] = MiniPortile.new "libxslt", "1.1.26"
%w[zlib libiconv libxml2 libxslt].each do |lib|
$recipes[lib] = MiniPortile.new lib, dependencies[lib]
end
$recipes.each { |_, recipe| recipe.host = HOST }

file "lib/nokogiri/nokogiri.rb" do
Expand Down Expand Up @@ -90,15 +90,6 @@ def install
"--without-readline",
"CFLAGS='-DIN_LIBXML'"
]
class << recipe
def download
Dir.chdir archives_path do
@files.each do |url|
sh "wget #{url} || curl -O #{url}"
end
end
end
end

checkpoint = "#{CROSS_DIR}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
unless File.exist?(checkpoint)
Expand All @@ -120,15 +111,6 @@ def download
"--without-crypto",
"CFLAGS='-DIN_LIBXML'"
]
class << recipe
def download
Dir.chdir archives_path do
@files.each do |url|
sh "wget #{url} || curl -O #{url}"
end
end
end
end

checkpoint = "#{CROSS_DIR}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"
unless File.exist?(checkpoint)
Expand Down

0 comments on commit f897a2e

Please sign in to comment.