Skip to content

Commit

Permalink
Merge pull request #2193 from eregon/flexible-config-truffleruby
Browse files Browse the repository at this point in the history
On TruffleRuby, allow overriding env var with --disable-system-libraries; and default to --disable-static.
  • Loading branch information
flavorjones committed Mar 11, 2021
2 parents 4830749 + 4a3836e commit 13c1e88
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 36 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,8 @@ Nokogiri follows [Semantic Versioning](https://semver.org/), please see the [REA

* Reduce the number of object allocations needed when parsing an HTML::DocumentFragment. [[#2087](https://github.com/sparklemotion/nokogiri/issues/2087)] (Thanks, [@ashmaroli](https://github.com/ashmaroli)!)
* [JRuby] Update the algorithm used to calculate `Node#line` to be wrong less-often. The underlying parser, Xerces, does not track line numbers, and so we've always used a hacky solution for this method. [[#1223](https://github.com/sparklemotion/nokogiri/issues/1223)]
* Introduce `--enable-system-libraries` and `--disable-system-libraries` flags to `extconf.rb`. These flags provide the same functionality as `--use-system-libraries` and the `NOKOGIRI_USE_SYSTEM_LIBRARIES` environment variable, but are more idiomatic. [[#2193](https://github.com/sparklemotion/nokogiri/issues/2193)] (Thanks, [@eregon](https://github.com/eregon)!)
* [TruffleRuby] `--disable-static` is used by default on TruffleRuby, when `--disable-system-libraries` is set, which is more flexible and compiles faster, see [#2191](https://github.com/sparklemotion/nokogiri/issues/2191#issuecomment-780724627). [[#2193](https://github.com/sparklemotion/nokogiri/issues/2193)] (Thanks, [@eregon](https://github.com/eregon)!)


## 1.11.1 / 2021-01-06
Expand Down
95 changes: 59 additions & 36 deletions ext/nokogiri/extconf.rb
Expand Up @@ -26,10 +26,16 @@
Flags that are always valid:
--use-system-libraries
Use system libraries instead of building and using the packaged libraries
--enable-system-libraries
Use system libraries instead of building and using the packaged libraries.
--disable-system-libraries
Use the packaged libraries, and ignore the system libraries. This is the default on most
platforms, and overrides `--use-system-libraries` and the environment variable
`NOKOGIRI_USE_SYSTEM_LIBRARIES`.
--disable-clean
Do not clean out intermediate files after successful build
Do not clean out intermediate files after successful build.
--prevent-strip
Take steps to prevent stripping the symbol table and debugging info from the shared
Expand All @@ -41,79 +47,79 @@
General:
--with-opt-dir=DIRECTORY
Look for headers and libraries in DIRECTORY
Look for headers and libraries in DIRECTORY.
--with-opt-lib=DIRECTORY
Look for libraries in DIRECTORY
Look for libraries in DIRECTORY.
--with-opt-include=DIRECTORY
Look for headers in DIRECTORY
Look for headers in DIRECTORY.
Related to zlib:
--with-zlib-dir=DIRECTORY
Look for zlib headers and library in DIRECTORY
Look for zlib headers and library in DIRECTORY.
--with-zlib-lib=DIRECTORY
Look for zlib library in DIRECTORY
Look for zlib library in DIRECTORY.
--with-zlib-include=DIRECTORY
Look for zlib headers in DIRECTORY
Look for zlib headers in DIRECTORY.
Related to iconv:
--with-iconv-dir=DIRECTORY
Look for iconv headers and library in DIRECTORY
Look for iconv headers and library in DIRECTORY.
--with-iconv-lib=DIRECTORY
Look for iconv library in DIRECTORY
Look for iconv library in DIRECTORY.
--with-iconv-include=DIRECTORY
Look for iconv headers in DIRECTORY
Look for iconv headers in DIRECTORY.
Related to libxml2:
--with-xml2-dir=DIRECTORY
Look for xml2 headers and library in DIRECTORY
Look for xml2 headers and library in DIRECTORY.
--with-xml2-lib=DIRECTORY
Look for xml2 library in DIRECTORY
Look for xml2 library in DIRECTORY.
--with-xml2-include=DIRECTORY
Look for xml2 headers in DIRECTORY
Look for xml2 headers in DIRECTORY.
Related to libxslt:
--with-xslt-dir=DIRECTORY
Look for xslt headers and library in DIRECTORY
Look for xslt headers and library in DIRECTORY.
--with-xslt-lib=DIRECTORY
Look for xslt library in DIRECTORY
Look for xslt library in DIRECTORY.
--with-xslt-include=DIRECTORY
Look for xslt headers in DIRECTORY
Look for xslt headers in DIRECTORY.
Related to libexslt:
--with-exslt-dir=DIRECTORY
Look for exslt headers and library in DIRECTORY
Look for exslt headers and library in DIRECTORY.
--with-exslt-lib=DIRECTORY
Look for exslt library in DIRECTORY
Look for exslt library in DIRECTORY.
--with-exslt-include=DIRECTORY
Look for exslt headers in DIRECTORY
Look for exslt headers in DIRECTORY.
Flags only used when building and using the packaged libraries:
--disable-static
Do not statically link packaged libraries, instead use shared libraries
Do not statically link packaged libraries, instead use shared libraries.
--enable-cross-build
Enable cross-build mode. (You probably do not want to set this manually.)
Expand All @@ -122,8 +128,7 @@
Environment variables used:
NOKOGIRI_USE_SYSTEM_LIBRARIES
When set, even if nil or blank, use system libraries instead of building and using the
packaged libraries. Equivalent to `--use-system-libraries`.
Equivalent to `--enable-system-libraries` when set, even if nil or blank.
CC
Use this path to invoke the compiler instead of `RbConfig::CONFIG['CC']`
Expand All @@ -144,6 +149,25 @@
#
# utility functions
#
def config_clean?
enable_config('clean', true)
end

def config_static?
default_static = !truffle?
enable_config("static", default_static)
end

def config_cross_build?
enable_config("cross-build")
end

def config_system_libraries?
enable_config("system-libraries", ENV.key?("NOKOGIRI_USE_SYSTEM_LIBRARIES")) do |_, default|
arg_config('--use-system-libraries', default)
end
end

def windows?
RbConfig::CONFIG['target_os'] =~ /mingw32|mswin/
end
Expand All @@ -168,6 +192,10 @@ def nix?
!(windows? || solaris? || darwin?)
end

def truffle?
::RUBY_ENGINE == 'truffleruby'
end

def concat_flags(*args)
args.compact.join(" ")
end
Expand Down Expand Up @@ -292,11 +320,6 @@ def libflag_to_filename(ldflag)
end
end

def using_system_libraries?
# NOTE: TruffleRuby uses this env var as it does not support using static libraries yet.
arg_config('--use-system-libraries', ENV.key?("NOKOGIRI_USE_SYSTEM_LIBRARIES"))
end

def have_libxml_headers?(version = nil)
source = if version.nil?
<<~SRC
Expand Down Expand Up @@ -518,7 +541,7 @@ def do_clean
FileUtils.rm_rf(dir, verbose: true)
end

if enable_config('static')
if config_static?
# ports installation can be safely removed if statically linked.
FileUtils.rm_rf(root + 'ports', verbose: true)
else
Expand All @@ -535,7 +558,7 @@ def do_clean
do_help if arg_config('--help')
do_clean if arg_config('--clean')

if openbsd? && !using_system_libraries?
if openbsd? && !config_system_libraries?
if %x(#{ENV['CC'] || '/usr/bin/cc'} -v 2>&1) !~ /clang/
(ENV['CC'] ||= find_executable('egcc')) ||
abort("Please install gcc 4.9+ from ports using `pkg_add -v gcc`")
Expand Down Expand Up @@ -585,15 +608,15 @@ def do_clean

# Add SDK-specific include path for macOS and brew versions before v2.2.12 (2020-04-08) [#1851, #1801]
macos_mojave_sdk_include_path = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/libxml2"
if using_system_libraries? && darwin? && Dir.exist?(macos_mojave_sdk_include_path)
if config_system_libraries? && darwin? && Dir.exist?(macos_mojave_sdk_include_path)
append_cppflags("-I#{macos_mojave_sdk_include_path}")
end

# Work around a character escaping bug in MSYS by passing an arbitrary double-quoted parameter to gcc.
# See https://sourceforge.net/p/mingw/bugs/2142
append_cppflags(' "-Idummypath"') if windows?

if using_system_libraries?
if config_system_libraries?
message "Building nokogiri using system libraries.\n"
ensure_package_configuration(opt: "zlib", pc: "zlib", lib: "z",
headers: "zlib.h", func: "gzdopen")
Expand All @@ -612,10 +635,10 @@ def do_clean
else
message "Building nokogiri using packaged libraries.\n"

static_p = enable_config("static", true)
static_p = config_static?
message "Static linking is #{static_p ? 'enabled' : 'disabled'}.\n"

cross_build_p = enable_config("cross-build")
cross_build_p = config_cross_build?
message "Cross build is #{cross_build_p ? 'enabled' : 'disabled'}.\n"

require 'yaml'
Expand Down Expand Up @@ -854,7 +877,7 @@ def compile
other_library_versions_string = OTHER_LIBRARY_VERSIONS.map { |k, v| [k, v].join(":") }.join(",")
append_cppflags(%[-DNOKOGIRI_OTHER_LIBRARY_VERSIONS="\\\"#{other_library_versions_string}\\\""])

unless using_system_libraries?
unless config_system_libraries?
if cross_build_p
# When precompiling native gems, copy packaged libraries' headers to ext/nokogiri/include
# These are packaged up by the cross-compiling callback in the ExtensionTask
Expand All @@ -870,7 +893,7 @@ def compile

create_makefile('nokogiri/nokogiri')

if enable_config('clean', true)
if config_clean?
# Do not clean if run in a development work tree.
File.open('Makefile', 'at') do |mk|
mk.print(<<~EOF)
Expand Down

0 comments on commit 13c1e88

Please sign in to comment.