Skip to content

Commit b2a4dc6

Browse files
committed
Give its own home for the bootstrap truffleruby launcher
* Much cleaner than passing a bunch of properties and using the repository as a home.
1 parent 36ade7c commit b2a4dc6

File tree

11 files changed

+66
-32
lines changed

11 files changed

+66
-32
lines changed

lib/cext/ABI_check.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
15
1+
16

lib/truffle/rbconfig.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ module RbConfig
135135

136136
# Set extra flags needed for --building-core-cexts
137137
if Truffle::Boot.get_option 'building-core-cexts'
138-
libtruffleruby = "#{ruby_home}/src/main/c/cext/libtruffleruby.#{soext}"
139-
libtrufflerubytrampoline = "#{ruby_home}/src/main/c/cext-trampoline/libtrufflerubytrampoline.#{soext}"
138+
repo = Truffle::System.get_java_property 'truffleruby.repository'
139+
libtruffleruby = "#{repo}/src/main/c/cext/libtruffleruby.#{soext}"
140+
libtrufflerubytrampoline = "#{repo}/src/main/c/cext-trampoline/libtrufflerubytrampoline.#{soext}"
140141

141-
relative_debug_paths = " -fdebug-prefix-map=#{ruby_home}=."
142+
relative_debug_paths = " -fdebug-prefix-map=#{repo}=."
142143
cppflags << relative_debug_paths
143144

144145
warnflags << '-Wundef' # Warn for undefined preprocessor macros for core C extensions

mx.truffleruby/mx_truffleruby.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
import pipes
1313
from os.path import join, exists, basename
14+
import re
1415
import shutil
1516
import sys
1617

@@ -48,6 +49,27 @@ def add_ext_suffix(name):
4849

4950
mx_subst.results_substitutions.register_with_arg('extsuffix', add_ext_suffix)
5051

52+
# From org.truffleruby.shared.Platform
53+
def get_cruby_arch():
54+
arch = mx.get_arch()
55+
if arch == 'amd64':
56+
return 'x86_64'
57+
elif arch == 'aarch64':
58+
return 'aarch64'
59+
else:
60+
raise Exception("Unknown platform " + arch)
61+
62+
mx_subst.results_substitutions.register_no_arg('cruby_arch', get_cruby_arch)
63+
64+
def get_truffleruby_abi_version():
65+
path = join(root, 'lib/cext/include/truffleruby/truffleruby-abi-version.h')
66+
with open(path, "r") as f:
67+
contents = f.read()
68+
m = re.search('"(.+)"', contents)
69+
return m.group(1)
70+
71+
mx_subst.results_substitutions.register_no_arg('truffleruby_abi_version', get_truffleruby_abi_version)
72+
5173
# Utilities
5274

5375
class VerboseMx:
@@ -118,10 +140,10 @@ def contents(self, result):
118140
if debug_args:
119141
jvm_args.extend(['-ea', '-esa'])
120142

121-
jvm_args.append('-Dorg.graalvm.language.ruby.home=' + root)
143+
bootstrap_home = mx.distribution('TRUFFLERUBY_BOOTSTRAP_HOME').get_output()
144+
jvm_args.append('-Dorg.graalvm.language.ruby.home=' + bootstrap_home)
122145

123-
libyarpbindings = list(mx.project('org.truffleruby.yarp.bindings').getArchivableResults())[0][0]
124-
jvm_args.append('-Dtruffleruby.libyarpbindings=' + libyarpbindings)
146+
jvm_args.append('-Dtruffleruby.repository=' + root)
125147

126148
main_class = 'org.truffleruby.launcher.RubyLauncher'
127149
ruby_options = [

mx.truffleruby/suite.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@
368368
"TRUFFLERUBY", # We need this jar to run extconf.rb
369369
"TRUFFLERUBY-LAUNCHER", # We need this jar to run extconf.rb
370370
"sulong:SULONG_NATIVE", # We need this jar to find the toolchain with Toolchain#getToolPath
371-
"org.truffleruby.yarp.bindings", # libyarpbindings.so
371+
"TRUFFLERUBY_BOOTSTRAP_HOME", # libyarpbindings.so, librubysignal.so
372372
],
373373
"license": ["EPL-2.0"],
374374
},
@@ -667,6 +667,30 @@
667667
"maven": False,
668668
},
669669

670+
"TRUFFLERUBY_BOOTSTRAP_HOME": {
671+
"description": "TruffleRuby bootstrap home used by a minimal TruffleRuby to run extconf.rb of default & bundled gems C extensions",
672+
"native": True,
673+
"platformDependent": True,
674+
"layout": {
675+
"lib/": [
676+
"file:lib/json",
677+
"file:lib/mri",
678+
"file:lib/patches",
679+
"file:lib/truffle",
680+
"dependency:org.truffleruby.yarp.bindings",
681+
],
682+
"lib/cext/": [
683+
"file:lib/cext/*.rb",
684+
# libtruffleposix is handled specially in posix.rb to avoid a cyclic dependency between org.truffleruby.cext and TRUFFLERUBY-BOOTSTRAP-LAUNCHER
685+
"dependency:org.truffleruby.librubysignal",
686+
],
687+
"lib/cext/include/": [
688+
"file:lib/cext/include/*",
689+
],
690+
},
691+
"maven": False,
692+
},
693+
670694
"TRUFFLERUBY_GRAALVM_SUPPORT_PLATFORM_AGNOSTIC": {
671695
"description": "Platform-agnostic TruffleRuby home files",
672696
"fileListPurpose": 'native-image-resources',
@@ -732,8 +756,10 @@
732756
"dependency:org.truffleruby.cext/src/main/c/cext-trampoline/<lib:trufflerubytrampoline>",
733757
"dependency:org.truffleruby.librubysignal",
734758
],
759+
# Create the complete files to let RubyGems know the gems are fully built
760+
"lib/gems/extensions/<cruby_arch>-<os>/<truffleruby_abi_version>/debug-1.7.1/gem.build_complete": "string:",
761+
"lib/gems/extensions/<cruby_arch>-<os>/<truffleruby_abi_version>/rbs-2.8.2/gem.build_complete": "string:",
735762
# The platform-specific files from debug and rbs, see comment above
736-
"lib/gems/": "file:lib/gems/extensions",
737763
"lib/gems/gems/debug-1.7.1/lib/debug/": "dependency:org.truffleruby.cext/lib/gems/gems/debug-1.7.1/lib/debug/<extsuffix:debug>",
738764
"lib/gems/gems/rbs-2.8.2/lib/": "dependency:org.truffleruby.cext/lib/gems/gems/rbs-2.8.2/lib/<extsuffix:rbs_extension>",
739765
"lib/mri/": [
@@ -764,9 +790,9 @@
764790
},
765791

766792
"TRUFFLERUBY_GRAALVM_SUPPORT_NO_NI_RESOURCES": {
793+
"description": "TruffleRuby support distribution for the GraalVM, the contents is not included as native image resources.",
767794
"native": True,
768795
"platformDependent": True,
769-
"description": "TruffleRuby support distribution for the GraalVM, the contents is not included as native image resources.",
770796
"layout": {
771797
"./": [
772798
"file:CHANGELOG.md",

src/main/c/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ $(DEBUG_GEM_EXT_SO): $(DEBUG_GEM_EXT)/Makefile $(DEBUG_GEM_EXT)/*.c
186186

187187
$(DEBUG_GEM_LIB_SO): $(DEBUG_GEM_EXT_SO)
188188
$(Q) cp $< $@
189-
$(Q) $(RUBY) $(ROOT)/tool/mark-gem-extension-as-built.rb debug
190189

191190
# rbs bundled gem
192191
$(RBS_GEM_EXT)/Makefile: $(RBS_GEM_EXT)/extconf.rb $(EXTCONF_DEPS)
@@ -197,4 +196,3 @@ $(RBS_GEM_EXT_SO): $(RBS_GEM_EXT)/Makefile $(RBS_GEM_EXT)/*.c $(RBS_GEM_EXT)/*.h
197196

198197
$(RBS_GEM_LIB_SO): $(RBS_GEM_EXT_SO)
199198
$(Q) cp $< $@
200-
$(Q) $(RUBY) $(ROOT)/tool/mark-gem-extension-as-built.rb rbs

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -816,17 +816,12 @@ private TruffleFile searchRubyHome(Env env) {
816816
private boolean isRubyHome(TruffleFile path) {
817817
var lib = path.resolve("lib");
818818
return lib.resolve("truffle").isDirectory() &&
819-
lib.resolve("gems").isDirectory() &&
819+
(options.BUILDING_CORE_CEXTS || lib.resolve("gems").isDirectory()) &&
820820
lib.resolve("patches").isDirectory();
821821
}
822822

823823
private void loadLibYARPBindings() {
824-
String libyarpbindings;
825-
if (options.BUILDING_CORE_CEXTS) {
826-
libyarpbindings = System.getProperty("truffleruby.libyarpbindings");
827-
} else {
828-
libyarpbindings = getRubyHome() + "/lib/libyarpbindings" + Platform.LIB_SUFFIX;
829-
}
824+
String libyarpbindings = getRubyHome() + "/lib/libyarpbindings" + Platform.LIB_SUFFIX;
830825
Parser.loadLibrary(libyarpbindings);
831826
}
832827

src/main/java/org/truffleruby/core/thread/ThreadManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public ThreadManager(RubyContext context, RubyLanguage language) {
9999
}
100100

101101
public void initialize() {
102-
useLibRubySignal = context.getOptions().NATIVE_PLATFORM && !language.options.BUILDING_CORE_CEXTS;
102+
useLibRubySignal = context.getOptions().NATIVE_PLATFORM;
103103
nativeInterrupt = context.getOptions().NATIVE_INTERRUPT && useLibRubySignal;
104104
if (useLibRubySignal) {
105105
LibRubySignal.loadLibrary(language.getRubyHome(), Platform.LIB_SUFFIX);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def resolve
4141
LIBTRUFFLEPOSIX = LazyLibrary.new do
4242
home = Truffle::Boot.ruby_home
4343
if Truffle::Boot.get_option 'building-core-cexts'
44-
libtruffleposix = "#{home}/src/main/c/truffleposix/libtruffleposix.#{Truffle::Platform::SOEXT}"
44+
repo = Truffle::System.get_java_property 'truffleruby.repository'
45+
libtruffleposix = "#{repo}/src/main/c/truffleposix/libtruffleposix.#{Truffle::Platform::SOEXT}"
4546
else
4647
libtruffleposix = "#{home}/lib/cext/libtruffleposix.#{Truffle::Platform::SOEXT}"
4748
end

src/options.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ INTERNAL: # Options for debugging the TruffleRuby implementation
167167
# Used internally for the launcher to communicate with the RubyContext
168168
ARGV_GLOBAL_VALUES: [argv-global-values, string-array, '<key>,<value>,...', Parsed options from script argv with a value]
169169
ARGV_GLOBAL_FLAGS: [argv-global-flags, string-array, '<flag>,<flag>,...', Parsed options from script argv acting as flags (no value)]
170-
BUILDING_CORE_CEXTS: [building-core-cexts, boolean, false, 'Used while building TruffleRuby to build core C extensions']
170+
BUILDING_CORE_CEXTS: [building-core-cexts, boolean, false, 'Used while building TruffleRuby to build default & bundled gems C extensions']
171171

172172
# Low-level logging of implementation details
173173
LAZY_TRANSLATION_LOG: [lazy-translation-log, boolean, false, Log lazy translations from the parser AST to the Truffle AST]

src/shared/java/org/truffleruby/shared/options/OptionsCatalog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ public final class OptionsCatalog {
759759

760760
public static final OptionDescriptor BUILDING_CORE_CEXTS = OptionDescriptor
761761
.newBuilder(BUILDING_CORE_CEXTS_KEY, "ruby.building-core-cexts")
762-
.help("Used while building TruffleRuby to build core C extensions")
762+
.help("Used while building TruffleRuby to build default & bundled gems C extensions")
763763
.category(OptionCategory.INTERNAL)
764764
.stability(OptionStability.EXPERIMENTAL)
765765
.usageSyntax("")

0 commit comments

Comments
 (0)