Skip to content

Commit cd54643

Browse files
committed
Prepend the GraalVM LLVM Toolchain to PATH when installing gems
* Also add RbConfig::CONFIG['toolchain_path'] for other cases where it might be useful to access the toolchain `bin/` directory explicitly.
1 parent 7847167 commit cd54643

File tree

7 files changed

+36
-10
lines changed

7 files changed

+36
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Bug fixes:
1818

1919
Compatibility:
2020

21+
* Prepend the GraalVM LLVM Toolchain to `PATH` when installing gems (#1974).
2122
* Implemented `$LOAD_PATH.resolve_feature_path`.
2223
* Add `Pathname#/` alias to `Pathname#+` (#2178).
2324
* Fixed issue with large `Integer`s in `Math.log` (#2184).

lib/mri/mkmf.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
ENV['NOKOGIRI_USE_SYSTEM_LIBRARIES'] = 'true'
5656
end
5757

58+
if defined?(::TruffleRuby) and Truffle::Boot.get_option('cexts-prepend-toolchain-to-path')
59+
ENV['PATH'] = "#{RbConfig::CONFIG['toolchain_path']}:#{ENV['PATH']}"
60+
end
61+
5862
class String
5963
# :stopdoc:
6064

lib/truffle/rbconfig.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ module RbConfig
9494
cext_dir = "#{prefix}/lib/cext"
9595
dlext = Truffle::Platform::DLEXT
9696

97+
toolchain_path = Truffle::Boot.toolchain_paths(:PATH)
98+
9799
# Make C extensions use the same libssl as the one used for the openssl C extension
98100
if Truffle::Platform.darwin?
99101
require 'truffle/openssl-prefix'
@@ -187,6 +189,7 @@ module RbConfig
187189
'sysconfdir' => "#{prefix}/etc", # doesn't exist, as in MRI
188190
'target_cpu' => host_cpu,
189191
'target_os' => host_os,
192+
'toolchain_path' => toolchain_path,
190193
'UNICODE_VERSION' => '12.0.0',
191194
'UNICODE_EMOJI_VERSION' => '12.1',
192195
'warnflags' => warnflags,

src/main/java/org/truffleruby/options/Options.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public class Options {
103103
public final boolean CEXTS;
104104
/** --cexts-lock=true */
105105
public final boolean CEXT_LOCK;
106+
/** --cexts-prepend-toolchain-to-path=true */
107+
public final boolean CEXTS_PREPEND_TOOLCHAIN_TO_PATH;
106108
/** --keep-handles-alive=false */
107109
public final boolean CEXTS_KEEP_HANDLES_ALIVE;
108110
/** --options-log=false */
@@ -239,6 +241,7 @@ public Options(Env env, OptionValues options, LanguageOptions languageOptions) {
239241
BACKTRACE_ON_RESCUE = options.get(OptionsCatalog.BACKTRACE_ON_RESCUE_KEY);
240242
CEXTS = options.get(OptionsCatalog.CEXTS_KEY);
241243
CEXT_LOCK = options.get(OptionsCatalog.CEXT_LOCK_KEY);
244+
CEXTS_PREPEND_TOOLCHAIN_TO_PATH = options.get(OptionsCatalog.CEXTS_PREPEND_TOOLCHAIN_TO_PATH_KEY);
242245
CEXTS_KEEP_HANDLES_ALIVE = options.get(OptionsCatalog.CEXTS_KEEP_HANDLES_ALIVE_KEY);
243246
OPTIONS_LOG = options.get(OptionsCatalog.OPTIONS_LOG_KEY);
244247
LOG_LOAD = options.get(OptionsCatalog.LOG_LOAD_KEY);
@@ -370,6 +373,8 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
370373
return CEXTS;
371374
case "ruby.cexts-lock":
372375
return CEXT_LOCK;
376+
case "ruby.cexts-prepend-toolchain-to-path":
377+
return CEXTS_PREPEND_TOOLCHAIN_TO_PATH;
373378
case "ruby.keep-handles-alive":
374379
return CEXTS_KEEP_HANDLES_ALIVE;
375380
case "ruby.options-log":

src/options.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ EXPERT:
109109
# C extension options
110110
CEXTS: [cexts, boolean, true, Enable use of C extensions]
111111
CEXT_LOCK: [cexts-lock, boolean, true, Use a Global Lock when running C extensions]
112+
CEXTS_PREPEND_TOOLCHAIN_TO_PATH: [cexts-prepend-toolchain-to-path, boolean, true, Prepend the GraalVM LLVM Toolchain to PATH when installing gems]
112113
CEXTS_KEEP_HANDLES_ALIVE: [keep-handles-alive, boolean, false, Keep handles for value wrappers alive forever]
113114

114115
# Debugging the values of options

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public class OptionsCatalog {
6767
public static final OptionKey<Boolean> BACKTRACE_ON_RESCUE_KEY = new OptionKey<>(false);
6868
public static final OptionKey<Boolean> CEXTS_KEY = new OptionKey<>(true);
6969
public static final OptionKey<Boolean> CEXT_LOCK_KEY = new OptionKey<>(true);
70+
public static final OptionKey<Boolean> CEXTS_PREPEND_TOOLCHAIN_TO_PATH_KEY = new OptionKey<>(true);
7071
public static final OptionKey<Boolean> CEXTS_KEEP_HANDLES_ALIVE_KEY = new OptionKey<>(false);
7172
public static final OptionKey<Boolean> OPTIONS_LOG_KEY = new OptionKey<>(false);
7273
public static final OptionKey<Boolean> LOG_LOAD_KEY = new OptionKey<>(false);
@@ -479,6 +480,13 @@ public class OptionsCatalog {
479480
.stability(OptionStability.EXPERIMENTAL)
480481
.build();
481482

483+
public static final OptionDescriptor CEXTS_PREPEND_TOOLCHAIN_TO_PATH = OptionDescriptor
484+
.newBuilder(CEXTS_PREPEND_TOOLCHAIN_TO_PATH_KEY, "ruby.cexts-prepend-toolchain-to-path")
485+
.help("Prepend the GraalVM LLVM Toolchain to PATH when installing gems")
486+
.category(OptionCategory.EXPERT)
487+
.stability(OptionStability.EXPERIMENTAL)
488+
.build();
489+
482490
public static final OptionDescriptor CEXTS_KEEP_HANDLES_ALIVE = OptionDescriptor
483491
.newBuilder(CEXTS_KEEP_HANDLES_ALIVE_KEY, "ruby.keep-handles-alive")
484492
.help("Keep handles for value wrappers alive forever")
@@ -1149,6 +1157,8 @@ public static OptionDescriptor fromName(String name) {
11491157
return CEXTS;
11501158
case "ruby.cexts-lock":
11511159
return CEXT_LOCK;
1160+
case "ruby.cexts-prepend-toolchain-to-path":
1161+
return CEXTS_PREPEND_TOOLCHAIN_TO_PATH;
11521162
case "ruby.keep-handles-alive":
11531163
return CEXTS_KEEP_HANDLES_ALIVE;
11541164
case "ruby.options-log":
@@ -1367,6 +1377,7 @@ public static OptionDescriptor[] allDescriptors() {
13671377
BACKTRACE_ON_RESCUE,
13681378
CEXTS,
13691379
CEXT_LOCK,
1380+
CEXTS_PREPEND_TOOLCHAIN_TO_PATH,
13701381
CEXTS_KEEP_HANDLES_ALIVE,
13711382
OPTIONS_LOG,
13721383
LOG_LOAD,

test/truffle/cexts/backtraces/ext/backtraces/extconf.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@
33
# Compile a real native library
44
# Commands from src/main/c/truffleposix/Makefile
55

6-
so = RbConfig::CONFIG['SOEXT']
7-
cc = ENV['CC'] || 'cc'
6+
def command(*args)
7+
$stderr.puts args.join(' ')
8+
ret = system(*args)
9+
raise unless ret
10+
end
811

912
dir = File.expand_path('../..', __FILE__)
1013
name = "#{dir}/libnativetest"
14+
so = RbConfig::CONFIG['SOEXT']
15+
16+
original_path = ENV['PATH'].delete_prefix("#{RbConfig::CONFIG['toolchain_path']}:")
17+
system_cc = find_executable('cc', original_path)
1118

1219
cflags = %w[-Wall -Werror -fPIC -std=c99]
1320
ldflags = %w[-m64]
1421

15-
def command(*args)
16-
$stderr.puts args.join(' ')
17-
ret = system(*args)
18-
raise unless ret
19-
end
20-
21-
command cc, '-o', "#{name}.o", '-c', *cflags, *ldflags, "#{name}.c"
22-
command cc, '-shared', *ldflags, '-o', "#{name}.#{so}", "#{name}.o"
22+
command system_cc, '-o', "#{name}.o", '-c', *cflags, *ldflags, "#{name}.c"
23+
command system_cc, '-shared', *ldflags, '-o', "#{name}.#{so}", "#{name}.o"
2324

2425
$LIBS += " #{name}.#{so}"
2526

0 commit comments

Comments
 (0)