Skip to content

Commit

Permalink
Make --disable-system-libraries the default parameter
Browse files Browse the repository at this point in the history
This commit also adds an environment variable,
`RE2_USE_SYSTEM_LIBRARIES`, to enable system libraries.

Add some documentation about mini_portile2 workarounds and improve
CMake cross-compilation usage.
  • Loading branch information
stanhu committed Jul 14, 2023
1 parent 8f85df0 commit ed95b46
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
with:
ruby-version: "${{ matrix.ruby }}"
bundler-cache: true
- run: bundle exec rake compile -- --enable-system-libraries
- run: bundle exec rake

vendor:
Expand Down
47 changes: 35 additions & 12 deletions ext/re2/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
Flags that are always valid:
--use-system-libraries
--enable-system-libraries
Use system libraries instead of building and using the packaged libraries. This is the default.
Use system libraries instead of building and using the packaged libraries.
--disable-system-libraries
Use the packaged libraries, and ignore the system libraries. This overrides `--use-system-libraries`.
Use the packaged libraries, and ignore the system libraries. This is the default.
Flags only used when using system libraries:
Expand Down Expand Up @@ -51,9 +51,7 @@
# utility functions
#
def config_system_libraries?
enable_config("system-libraries", true) do |_, default|
arg_config("--use-system-libraries", default)
end
enable_config("system-libraries", ENV.key?('RE2_USE_SYSTEM_LIBRARIES'))
end

def concat_flags(*args)
Expand All @@ -69,6 +67,15 @@ def darwin?
RbConfig::CONFIG["target_os"].include?("darwin")
end

def windows?
# Use =~ instead of match? to preserve Ruby 2.3 compatibility
RbConfig::CONFIG["target_os"] =~ /mingw|mswin/
end

def freebsd?
RbConfig::CONFIG["target_os"].include?("freebsd")
end

def target_host
# We use 'host' to set compiler prefix for cross-compiling. Prefer host_alias over host. And
# prefer i686 (what external dev tools use) to i386 (what ruby's configure.ac emits).
Expand All @@ -84,13 +91,17 @@ def find_compiler(compilers)
# `--host` parameter. However, we don't have that feature with
# cmake. Search for the right compiler for the target architecture using
# some basic heruistics.
# See https://github.com/flavorjones/mini_portile/issues/128.
def find_c_and_cxx_compilers(host)
c_compiler = ENV["CC"]
cxx_compiler = ENV["CXX"]

if darwin?
c_compiler = 'clang'
cxx_compiler = 'clang++'
c_compiler ||= 'clang'
cxx_compiler ||='clang++'
else
c_compiler = 'gcc'
cxx_compiler = 'g++'
c_compiler ||= 'gcc'
cxx_compiler ||= 'g++'
end

c_platform_compiler = "#{host}-#{c_compiler}"
Expand All @@ -101,21 +112,33 @@ def find_c_and_cxx_compilers(host)
[c_compiler, cxx_compiler]
end

def cmake_system_name
if darwin?
'Darwin'
elsif windows?
'Windows'
elsif freebsd?
'FreeBSD'
else
'Linux'
end
end

def cmake_compile_flags(host)
system_name = darwin? ? 'Darwin' : 'Linux'
c_compiler, cxx_compiler = find_c_and_cxx_compilers(host)

# needed to ensure cross-compilation with CMake targets the right CPU and compilers
[
"-DCMAKE_SYSTEM_PROCESSOR=#{RbConfig::CONFIG['target_cpu']}",
"-DCMAKE_SYSTEM_NAME=#{system_name}",
"-DCMAKE_SYSTEM_NAME=#{cmake_system_name}",
"-DCMAKE_C_COMPILER=#{c_compiler}",
"-DCMAKE_CXX_COMPILER=#{cxx_compiler}"
]
end

# By default, mini_portile2 might add an unnecessary option:
# https://github.com/flavorjones/mini_portile/blob/5084a2aeab12076f534cf0cabc81a4d5f84b5c25/lib/mini_portile2/mini_portile_cmake.rb#L17
# See https://github.com/flavorjones/mini_portile/issues/127.
def delete_cmake_generator_option!(options)
indices = []

Expand Down

0 comments on commit ed95b46

Please sign in to comment.