Skip to content

Commit b97777e

Browse files
committed
[GR-18163] Fix mkmf check_sizeof and run CRuby mkmf tests
PullRequest: truffleruby/2471
2 parents 77a144d + 371df0f commit b97777e

File tree

9 files changed

+43
-27
lines changed

9 files changed

+43
-27
lines changed

lib/mri/mkmf.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,7 @@ def depend_rules(depend)
23082308
def create_makefile(target, srcprefix = nil)
23092309
if defined?(::TruffleRuby) and $LIBRUBYARG.to_s.strip.empty?
23102310
# $LIBRUBYARG was explicitly unset, the built library is not a C extension but used with FFI (e.g., sassc does).
2311-
# Since $LIBRUBYARG is unset we won't link to libgraalvm-llvm.so, which is wanted.
2311+
# Since $LIBRUBYARG is unset we won't link to libgraalvm-llvm.so, which is expected.
23122312
# In the case the library uses C++ code, libc++.so/libc++abi.so will be linked and needs to be found by NFI.
23132313
# The toolchain does not pass -rpath automatically for libc++.so/libc++abi.so, so we do it.
23142314
libcxx_dir = ::Truffle::Boot.toolchain_paths(:LD_LIBRARY_PATH)
@@ -2837,9 +2837,13 @@ def MAIN_DOES_NOTHING(*refs)
28372837
"$(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)"
28382838

28392839
if defined?(::TruffleRuby)
2840-
# We need to link to libtruffleruby for MakeMakefile#try_link to succeed
2840+
# We need to link to libtruffleruby for MakeMakefile#try_link to succeed.
2841+
# The created executable will link against both libgraalvm-llvm.so and libtruffleruby and
2842+
# might be executed for #try_constant and #try_run so we also need -rpath for both.
28412843
libtruffleruby_dir = File.dirname(RbConfig::CONFIG['libtruffleruby'])
2842-
TRY_LINK << " -L#{libtruffleruby_dir} -ltruffleruby"
2844+
TRY_LINK << " -L#{libtruffleruby_dir} -rpath #{libtruffleruby_dir} -ltruffleruby"
2845+
libgraalvm_llvm_dir = ::Truffle::Boot.toolchain_paths(:LD_LIBRARY_PATH)
2846+
TRY_LINK << " -rpath #{libgraalvm_llvm_dir}"
28432847
end
28442848

28452849
##

lib/truffle/rbconfig.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ module RbConfig
149149
'EXECUTABLE_EXTS' => '',
150150
'exeext' => '',
151151
'EXEEXT' => '',
152+
'EXTOUT' => '.ext',
152153
'extra_bindirs' => extra_bindirs.join(File::PATH_SEPARATOR),
153154
'host_alias' => '',
154155
'host_cpu' => host_cpu,

spec/ruby/library/socket/socket/udp_server_loop_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
it 'yields the message and a Socket::UDPSource' do
2222
msg, src = nil
2323

24-
Thread.new do
24+
thread = Thread.new do
2525
SocketSpecs::ServerLoopPortFinder.udp_server_loop('127.0.0.1', 0) do |message, source|
2626
msg = message
2727
src = source
@@ -52,6 +52,8 @@
5252

5353
msg.should == 'hello'
5454
src.should be_an_instance_of(Socket::UDPSource)
55+
56+
thread.join
5557
end
5658
end
5759
end

src/main/c/cext/extconf.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ module Truffle::Platform
2323
# -DRUBY_EXPORT is added in MRI's configure.in.
2424
$CFLAGS << " -DRUBY_EXPORT"
2525

26+
if Truffle::Platform.darwin?
27+
# Set the install_name of libtruffleruby on macOS, so mkmf executables linking to it
28+
# will know they need to look at the rpath to find it.
29+
$LIBRUBYARG = "-Wl,-install_name,@rpath/libtruffleruby.dylib #{$LIBRUBYARG}"
30+
end
31+
2632
create_makefile('libtruffleruby')

src/main/ruby/truffleruby/core/kernel.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,13 @@ def putc(int)
478478
end
479479
module_function :putc
480480

481-
def puts(*a)
482-
$stdout.puts(*a)
481+
def puts(*args)
482+
stdout = $stdout
483+
if Primitive.object_equal(self, stdout)
484+
Truffle::IOOperations.puts(stdout, *args)
485+
else
486+
stdout.__send__(:puts, *args)
487+
end
483488
nil
484489
end
485490
module_function :puts

test/mri/failing.exclude

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,7 @@ minitest/test_minitest_mock.rb
125125
minitest/test_minitest_spec.rb
126126
minitest/test_minitest_unit.rb
127127
misc/test_ruby_mode.rb
128-
mkmf/test_config.rb
129-
mkmf/test_constant.rb
130-
mkmf/test_convertible.rb
131-
mkmf/test_find_executable.rb
132-
mkmf/test_flags.rb
133-
mkmf/test_framework.rb
134-
mkmf/test_have_func.rb
135128
mkmf/test_have_library.rb
136-
mkmf/test_have_macro.rb
137-
mkmf/test_libs.rb
138-
mkmf/test_signedness.rb
139-
mkmf/test_sizeof.rb
140129
net/http/test_https.rb
141130
net/imap/test_imap.rb
142131
net/imap/test_imap_response_parser.rb

test/mri/tests/mkmf/base.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# frozen_string_literal: false
22
$extmk = true
33
require 'rbconfig'
4-
RbConfig.fire_update!("top_srcdir", File.expand_path("../..", __dir__))
5-
File.foreach(RbConfig::CONFIG["topdir"]+"/Makefile") do |line|
6-
if /^CC_WRAPPER\s*=\s*/ =~ line
7-
RbConfig.fire_update!('CC_WRAPPER', $'.strip)
8-
break
4+
if RbConfig.respond_to?(:fire_update!)
5+
RbConfig.fire_update!("top_srcdir", File.expand_path("../..", __dir__))
6+
File.foreach(RbConfig::CONFIG["topdir"]+"/Makefile") do |line|
7+
if /^CC_WRAPPER\s*=\s*/ =~ line
8+
RbConfig.fire_update!('CC_WRAPPER', $'.strip)
9+
break
10+
end
911
end
1012
end
1113

@@ -122,6 +124,7 @@ def teardown
122124
}
123125
Logging.quiet = @quiet
124126
Logging.log_close
127+
# puts nil, MKMFLOG[], nil # TruffleRuby: useful to debug if a test fails
125128
FileUtils.rm_f("mkmf.log")
126129
Dir.chdir(@curdir)
127130
FileUtils.rm_rf(@tmpdir)

test/mri/tests/mkmf/test_have_func.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
class TestMkmf
66
class TestHaveFunc < TestMkmf
77
def test_have_func
8-
assert_equal(true, have_func("ruby_init"), MKMFLOG)
9-
assert_include($defs, '-DHAVE_RUBY_INIT')
8+
assert_equal(true, have_func("rb_intern"), MKMFLOG)
9+
assert_include($defs, '-DHAVE_RB_INTERN')
1010
end
1111

1212
def test_not_have_func
13-
assert_equal(false, have_func("no_ruby_init"), MKMFLOG)
14-
assert_not_include($defs, '-DHAVE_RUBY_INIT')
13+
assert_equal(false, have_func("no_rb_intern"), MKMFLOG)
14+
assert_not_include($defs, '-DHAVE_RB_INTERN')
1515
end
1616
end
1717
end

tool/jt.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,13 @@ def test(*args)
10941094
elsif !pattern.start_with?(MRI_TEST_PREFIX)
10951095
pattern = "#{MRI_TEST_PREFIX}/#{pattern}"
10961096
end
1097-
glob = Dir.glob(pattern)
1097+
glob = Dir.glob(pattern).flat_map do |path|
1098+
if File.directory?(path)
1099+
Dir.glob("#{path}/**/test_*.rb")
1100+
else
1101+
path
1102+
end
1103+
end
10981104
abort "pattern #{pattern} matched no files" if glob.empty?
10991105
glob.map { |path| mri_test_name(path) }
11001106
end.sort

0 commit comments

Comments
 (0)