Skip to content

Commit

Permalink
feat(build): extconf supports --disable/enable-system-libraries
Browse files Browse the repository at this point in the history
This will be used to override NOKOGIRI_USE_SYSTEM_LIBRARIES and the
--use-system-libraries option (which should eventually be deprecated).

This will allow TruffleRuby users to override the TR default which is
hacked into mkmf.rb.

Co-authored-by: Benoit Daloze <eregontp@gmail.com>
  • Loading branch information
flavorjones and eregon committed Mar 9, 2021
1 parent b3798ca commit 332f74f
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions ext/nokogiri/extconf.rb
Expand Up @@ -26,7 +26,13 @@
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.
Expand Down Expand Up @@ -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,12 @@
#
# utility functions
#
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 Down Expand Up @@ -292,11 +303,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 @@ -535,7 +541,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 +591,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 Down Expand Up @@ -854,7 +860,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 Down

0 comments on commit 332f74f

Please sign in to comment.