Skip to content

Commit 28d6f91

Browse files
committed
[GR-59808] Build libtruffleposix and spawn-helper in their own project so they can be used by bootstrap ruby, used for building core extensions
PullRequest: truffleruby/4560
2 parents 74b4b43 + 31bcf3f commit 28d6f91

File tree

8 files changed

+37
-66
lines changed

8 files changed

+37
-66
lines changed

mx.truffleruby/suite.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,31 @@
220220
"ldflags": ["-pthread"],
221221
},
222222

223+
"org.truffleruby.libtruffleposix": {
224+
"dir": "src/main/c/truffleposix",
225+
"native": "shared_lib",
226+
"deliverable": "truffleposix",
227+
"buildDependencies": [
228+
"TRUFFLERUBY_GRAALVM_SUPPORT_PLATFORM_AGNOSTIC",
229+
],
230+
"cflags": ["-g", "-O3", "-std=c99", "-Wall", "-Werror", "-pthread", "-I<path:TRUFFLERUBY_GRAALVM_SUPPORT_PLATFORM_AGNOSTIC>/lib/cext/include"],
231+
"ldflags": ["-pthread"],
232+
"os": {
233+
"linux": {
234+
"ldlibs": ["-lrt"],
235+
},
236+
"<others>": {
237+
},
238+
},
239+
},
240+
241+
"org.truffleruby.spawnhelper": {
242+
"dir": "src/main/c/spawn-helper",
243+
"native": "executable",
244+
"deliverable": "spawn-helper",
245+
"cflags": ["-g", "-O3", "-std=c99", "-Wall", "-Werror"],
246+
},
247+
223248
"org.prism.libprism": {
224249
"class": "YARPNativeProject",
225250
"dir": "src/main/c/yarp",
@@ -404,8 +429,6 @@
404429
},
405430
"output": ".",
406431
"results": [
407-
"src/main/c/spawn-helper/spawn-helper",
408-
"src/main/c/truffleposix/<lib:truffleposix>",
409432
"src/main/c/cext/<lib:truffleruby>",
410433
"src/main/c/cext-trampoline/<lib:trufflerubytrampoline>",
411434
"src/main/c/bigdecimal/<extsuffix:bigdecimal>",
@@ -750,12 +773,15 @@
750773
],
751774
"lib/cext/": [
752775
"file:lib/cext/*.rb",
753-
# libtruffleposix is handled specially in posix.rb to avoid a cyclic dependency between org.truffleruby.cext and TRUFFLERUBY-BOOTSTRAP-LAUNCHER
754776
"dependency:org.truffleruby.librubysignal",
777+
"dependency:org.truffleruby.libtruffleposix",
755778
],
756779
"lib/cext/include/": [
757780
"file:lib/cext/include/*",
758781
],
782+
"lib/truffle/": [
783+
"dependency:org.truffleruby.spawnhelper",
784+
],
759785
},
760786
"maven": False,
761787
},
@@ -805,10 +831,10 @@
805831
"dependency:org.prism.libprism.for.gem/build/<lib:prism>",
806832
],
807833
"lib/cext/": [
808-
"dependency:org.truffleruby.cext/src/main/c/truffleposix/<lib:truffleposix>",
834+
"dependency:org.truffleruby.librubysignal",
835+
"dependency:org.truffleruby.libtruffleposix",
809836
"dependency:org.truffleruby.cext/src/main/c/cext/<lib:truffleruby>",
810837
"dependency:org.truffleruby.cext/src/main/c/cext-trampoline/<lib:trufflerubytrampoline>",
811-
"dependency:org.truffleruby.librubysignal",
812838
],
813839
# Create the complete files to let RubyGems know the gems are fully built and can be activated
814840
"lib/gems/extensions/<cruby_arch>-<os>/<truffleruby_abi_version>/debug-1.9.2/gem.build_complete": "string:",
@@ -838,7 +864,7 @@
838864
"dependency:org.truffleruby.cext/src/main/c/rbconfig-sizeof/<extsuffix:sizeof>",
839865
],
840866
"lib/truffle/": [
841-
"dependency:org.truffleruby.cext/src/main/c/spawn-helper/spawn-helper",
867+
"dependency:org.truffleruby.spawnhelper",
842868
],
843869
},
844870
"license": [
@@ -1073,7 +1099,7 @@
10731099
"TRUFFLERUBY",
10741100
"TRUFFLERUBY-RESOURCES",
10751101
],
1076-
"description" : "Truffle TCK provider for Ruby language.",
1102+
"description": "Truffle TCK provider for Ruby language.",
10771103
"license": ["EPL-2.0"],
10781104
"maven": {
10791105
"artifactId": "ruby-truffle-tck",

src/main/c/Makefile

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@ endif
1717
ROOT := $(realpath ../../..)
1818
RUBY := $(TRUFFLERUBY_BOOTSTRAP_LAUNCHER)
1919

20-
TRUFFLE_POSIX := truffleposix/libtruffleposix.$(SOEXT)
21-
SPAWN_HELPER := spawn-helper/spawn-helper
2220
TRAMPOLINE := cext-trampoline/libtrufflerubytrampoline.$(SOEXT)
2321

2422
RUBY_HEADERS := $(shell find $(ROOT)/lib/cext/include -name '*.h')
2523
CEXT_C_FILES := $(shell find cext -name '*.c')
2624
RBCONFIG := $(ROOT)/lib/truffle/rbconfig.rb
2725
MKMF := $(ROOT)/lib/mri/mkmf.rb
2826
LIBTRUFFLERUBY = cext/libtruffleruby.$(SOEXT)
29-
BASIC_DEPS := Makefile $(SPAWN_HELPER) $(TRUFFLE_POSIX) $(RUBY_HEADERS)
27+
BASIC_DEPS := Makefile $(RUBY_HEADERS)
3028
BASIC_EXTCONF_DEPS := $(BASIC_DEPS) $(RBCONFIG) $(MKMF)
3129
# C extensions link against libtruffleruby (and might do have_func() checks against it), so it needs to be there before.
3230
# However, if libtruffleruby is recompiled, there is no need to rebuild C extensions, so it's a order-only-prerequisite.
@@ -42,10 +40,7 @@ all: $(TRAMPOLINE) $(LIBTRUFFLERUBY) openssl/openssl.$(DLEXT) zlib/zlib.$(DLEXT)
4240
bigdecimal/bigdecimal.$(DLEXT) date/date_core.$(DLEXT) io-console/console.$(DLEXT) etc/etc.$(DLEXT) \
4341
rbconfig-sizeof/sizeof.$(DLEXT) debug/debug.$(DLEXT) rbs/rbs_extension.$(DLEXT)
4442

45-
clean: clean_cexts clean_truffleposix clean_trampoline
46-
47-
clean_truffleposix:
48-
$(Q) rm -f $(TRUFFLE_POSIX) truffleposix/*.o
43+
clean: clean_cexts clean_trampoline
4944

5045
clean_trampoline:
5146
$(Q) rm -f $(TRAMPOLINE) cext-trampoline/trampoline.c cext/wrappers.c cext-trampoline/*.o
@@ -66,14 +61,6 @@ clean_cexts:
6661
$(Q) rm -f debug/Makefile debug/*.o debug/debug.$(DLEXT)
6762
$(Q) rm -f rbs/Makefile rbs/*.o rbs/rbs_extension.$(DLEXT)
6863

69-
# spawn-helper
70-
$(SPAWN_HELPER): spawn-helper/Makefile spawn-helper/spawn-helper.c
71-
$(Q) cd spawn-helper && $(MAKE)
72-
73-
# truffleposix
74-
$(TRUFFLE_POSIX): truffleposix/Makefile truffleposix/truffleposix.c
75-
$(Q) cd truffleposix && $(MAKE)
76-
7764
# cext-trampoline
7865
cext-trampoline/trampoline.c: $(CEXT_C_FILES) $(BASIC_DEPS) $(ROOT)/tool/generate-cext-trampoline.rb
7966
$(Q) cd $(ROOT) && $(RUBY) tool/generate-cext-trampoline.rb

src/main/c/spawn-helper/Makefile

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/main/c/truffleposix/Makefile

Lines changed: 0 additions & 29 deletions
This file was deleted.

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ def resolve
3939
end
4040

4141
LIBTRUFFLEPOSIX = LazyLibrary.new do
42-
home = Truffle::Boot.ruby_home
43-
if Truffle::Boot.get_option 'building-core-cexts'
44-
repo = Truffle::System.get_java_property 'truffleruby.repository'
45-
libtruffleposix = "#{repo}/src/main/c/truffleposix/libtruffleposix.#{Truffle::Platform::SOEXT}"
46-
else
47-
libtruffleposix = "#{home}/lib/cext/libtruffleposix.#{Truffle::Platform::SOEXT}"
48-
end
42+
libtruffleposix = "#{Truffle::Boot.ruby_home}/lib/cext/libtruffleposix.#{Truffle::Platform::SOEXT}"
4943
Primitive.interop_eval_nfi "load '#{libtruffleposix}'"
5044
end
5145

src/main/ruby/truffleruby/core/truffle/process_operations.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ def posix_spawnp(command, args, env_array, options)
570570
if use_helper
571571
# Go through spawn-helper to change the working dir and then execve()
572572
spawn_helper = "#{Truffle::Boot.ruby_home}/lib/truffle/spawn-helper"
573+
raise "#{spawn_helper} does not exist!" unless File.exist?(spawn_helper)
573574
cwd = chdir || Dir.pwd
574575
args = [spawn_helper, cwd, command, *args]
575576
command = spawn_helper

0 commit comments

Comments
 (0)