Skip to content

Commit b5dabd8

Browse files
committed
[GR-19855] Build built-in C extensions faster.
PullRequest: truffleruby/1172
2 parents af36a87 + 905d38c commit b5dabd8

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/main/c/Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ SPAWN_HELPER := spawn-helper/spawn-helper
2626
RUBY_HEADERS := $(wildcard $(ROOT)/lib/cext/include/*.h) $(wildcard $(ROOT)/lib/cext/include/*/*.h) $(wildcard $(ROOT)/lib/cext/include/*/*/*.h)
2727
RBCONFIG := $(ROOT)/lib/truffle/rbconfig.rb
2828
RBCONFIG_MKMF := $(ROOT)/lib/truffle/rbconfig-for-mkmf.rb
29-
PREPROCESS := $(ROOT)/lib/cext/preprocess.rb
3029
MKMF := $(ROOT)/lib/mri/mkmf.rb
31-
BASIC_EXTCONF_DEPS := $(SPAWN_HELPER) $(TRUFFLE_POSIX) $(RUBY_HEADERS) $(RBCONFIG) $(RBCONFIG_MKMF) $(PREPROCESS) $(MKMF)
32-
# These libraries are needed for try_link() in extconf.rb
33-
EXTCONF_DEPS := $(BASIC_EXTCONF_DEPS) cext/libtruffleruby.$(DLEXT)
30+
LIBTRUFFLERUBY = cext/libtruffleruby.$(DLEXT)
31+
BASIC_EXTCONF_DEPS := $(SPAWN_HELPER) $(TRUFFLE_POSIX) $(RUBY_HEADERS) $(RBCONFIG) $(RBCONFIG_MKMF) $(MKMF)
32+
# C extensions link against libtruffleruby (and might do have_func() checks against it), so it needs to be there before.
33+
# However, if libtruffleruby is recompiled, there is no need to rebuild C extensions, so it's a order-only-prerequisite.
34+
EXTCONF_DEPS := $(BASIC_EXTCONF_DEPS) | $(LIBTRUFFLERUBY)
3435

3536
IF_EXTCONF_FAIL := ( echo "`pwd`/extconf.rb failed:" 1>&2 && cat mkmf.log && false )
3637

37-
all: cext/libtruffleruby.$(DLEXT) openssl/openssl.$(DLEXT) zlib/zlib.$(DLEXT) \
38+
all: $(LIBTRUFFLERUBY) openssl/openssl.$(DLEXT) zlib/zlib.$(DLEXT) \
3839
psych/psych.$(DLEXT) syslog/syslog.$(DLEXT) nkf/nkf.$(DLEXT) \
3940
etc/etc.$(DLEXT) rbconfig-sizeof/sizeof.$(DLEXT)
4041

@@ -44,7 +45,7 @@ clean_truffleposix:
4445
$(Q) rm -f $(TRUFFLE_POSIX) truffleposix/*.o
4546

4647
clean_cexts:
47-
$(Q) rm -f cext/Makefile cext/*.o cext/libtruffleruby.$(DLEXT)
48+
$(Q) rm -f cext/Makefile cext/*.o $(LIBTRUFFLERUBY)
4849
$(Q) rm -f openssl/Makefile openssl/*.o openssl/openssl.$(DLEXT)
4950
$(Q) rm -f zlib/Makefile zlib/*.o zlib/zlib.$(DLEXT)
5051
$(Q) rm -f psych/Makefile psych/*.o psych/yaml/*.o psych/psych.$(DLEXT)
@@ -65,7 +66,7 @@ $(TRUFFLE_POSIX): truffleposix/Makefile truffleposix/truffleposix.c
6566
cext/Makefile: cext/extconf.rb $(BASIC_EXTCONF_DEPS)
6667
$(Q) cd cext && $(RUBY) extconf.rb || $(IF_EXTCONF_FAIL)
6768

68-
cext/libtruffleruby.$(DLEXT): cext/Makefile cext/*.c
69+
$(LIBTRUFFLERUBY): cext/Makefile cext/*.c
6970
$(Q) cd cext && $(MAKE)
7071

7172
# openssl

src/main/c/openssl/extconf.rb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525

2626
Logging::message "=== OpenSSL for Ruby configurator ===\n"
2727

28-
# Add -Werror=deprecated-declarations to $warnflags if available
29-
OpenSSL.deprecated_warning_flag
28+
unless defined?(::TruffleRuby) # Let it be lazily computed only if needed
29+
# Add -Werror=deprecated-declarations to $warnflags if available
30+
OpenSSL.deprecated_warning_flag
31+
end
3032

3133
##
3234
# Adds -DOSSL_DEBUG for compilation and some more targets when GCC is used
@@ -37,8 +39,10 @@
3739
end
3840

3941
Logging::message "=== Checking for system dependent stuff... ===\n"
40-
have_library("nsl", "t_open")
41-
have_library("socket", "socket")
42+
unless defined?(::TruffleRuby) # These do not exist on any of our supported platforms
43+
have_library("nsl", "t_open")
44+
have_library("socket", "socket")
45+
end
4246
if $mswin || $mingw
4347
have_library("ws2_32")
4448
end
@@ -106,6 +110,13 @@ def find_openssl_library
106110
end
107111
end
108112

113+
# TruffleRuby: do not perform all checks again if extconf.h already exists
114+
extconf_h = "#{__dir__}/extconf.h"
115+
if File.exist?(extconf_h) && File.mtime(extconf_h) >= File.mtime(__FILE__ )
116+
$extconf_h = extconf_h
117+
else
118+
### START of checks
119+
109120
unless checking_for("OpenSSL version is 1.0.1 or later") {
110121
try_static_assert("OPENSSL_VERSION_NUMBER >= 0x10001000L", "openssl/opensslv.h") }
111122
raise "OpenSSL >= 1.0.1 or LibreSSL is required"
@@ -175,5 +186,9 @@ def find_openssl_library
175186
Logging::message "=== Checking done. ===\n"
176187

177188
create_header
189+
190+
### END of checks
191+
end
192+
178193
create_makefile("openssl")
179194
Logging::message "Done.\n"

0 commit comments

Comments
 (0)