Skip to content

Commit

Permalink
[GR-29305] Prepend the GraalVM LLVM Toolchain to PATH when installing…
Browse files Browse the repository at this point in the history
… gems (#1974).

PullRequest: truffleruby/2445
  • Loading branch information
eregon committed Feb 26, 2021
2 parents 8afebf0 + cd54643 commit 5f33393
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Bug fixes:

Compatibility:

* Prepend the GraalVM LLVM Toolchain to `PATH` when installing gems (#1974).
* Implemented `$LOAD_PATH.resolve_feature_path`.
* Add `Pathname#/` alias to `Pathname#+` (#2178).
* Fixed issue with large `Integer`s in `Math.log` (#2184).
Expand Down
4 changes: 4 additions & 0 deletions lib/mri/mkmf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
ENV['NOKOGIRI_USE_SYSTEM_LIBRARIES'] = 'true'
end

if defined?(::TruffleRuby) and Truffle::Boot.get_option('cexts-prepend-toolchain-to-path')
ENV['PATH'] = "#{RbConfig::CONFIG['toolchain_path']}:#{ENV['PATH']}"
end

class String
# :stopdoc:

Expand Down
3 changes: 3 additions & 0 deletions lib/truffle/rbconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ module RbConfig
cext_dir = "#{prefix}/lib/cext"
dlext = Truffle::Platform::DLEXT

toolchain_path = Truffle::Boot.toolchain_paths(:PATH)

# Make C extensions use the same libssl as the one used for the openssl C extension
if Truffle::Platform.darwin?
require 'truffle/openssl-prefix'
Expand Down Expand Up @@ -187,6 +189,7 @@ module RbConfig
'sysconfdir' => "#{prefix}/etc", # doesn't exist, as in MRI
'target_cpu' => host_cpu,
'target_os' => host_os,
'toolchain_path' => toolchain_path,
'UNICODE_VERSION' => '12.0.0',
'UNICODE_EMOJI_VERSION' => '12.1',
'warnflags' => warnflags,
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/truffleruby/options/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public class Options {
public final boolean CEXTS;
/** --cexts-lock=true */
public final boolean CEXT_LOCK;
/** --cexts-prepend-toolchain-to-path=true */
public final boolean CEXTS_PREPEND_TOOLCHAIN_TO_PATH;
/** --keep-handles-alive=false */
public final boolean CEXTS_KEEP_HANDLES_ALIVE;
/** --options-log=false */
Expand Down Expand Up @@ -239,6 +241,7 @@ public Options(Env env, OptionValues options, LanguageOptions languageOptions) {
BACKTRACE_ON_RESCUE = options.get(OptionsCatalog.BACKTRACE_ON_RESCUE_KEY);
CEXTS = options.get(OptionsCatalog.CEXTS_KEY);
CEXT_LOCK = options.get(OptionsCatalog.CEXT_LOCK_KEY);
CEXTS_PREPEND_TOOLCHAIN_TO_PATH = options.get(OptionsCatalog.CEXTS_PREPEND_TOOLCHAIN_TO_PATH_KEY);
CEXTS_KEEP_HANDLES_ALIVE = options.get(OptionsCatalog.CEXTS_KEEP_HANDLES_ALIVE_KEY);
OPTIONS_LOG = options.get(OptionsCatalog.OPTIONS_LOG_KEY);
LOG_LOAD = options.get(OptionsCatalog.LOG_LOAD_KEY);
Expand Down Expand Up @@ -370,6 +373,8 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
return CEXTS;
case "ruby.cexts-lock":
return CEXT_LOCK;
case "ruby.cexts-prepend-toolchain-to-path":
return CEXTS_PREPEND_TOOLCHAIN_TO_PATH;
case "ruby.keep-handles-alive":
return CEXTS_KEEP_HANDLES_ALIVE;
case "ruby.options-log":
Expand Down
1 change: 1 addition & 0 deletions src/options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ EXPERT:
# C extension options
CEXTS: [cexts, boolean, true, Enable use of C extensions]
CEXT_LOCK: [cexts-lock, boolean, true, Use a Global Lock when running C extensions]
CEXTS_PREPEND_TOOLCHAIN_TO_PATH: [cexts-prepend-toolchain-to-path, boolean, true, Prepend the GraalVM LLVM Toolchain to PATH when installing gems]
CEXTS_KEEP_HANDLES_ALIVE: [keep-handles-alive, boolean, false, Keep handles for value wrappers alive forever]

# Debugging the values of options
Expand Down
11 changes: 11 additions & 0 deletions src/shared/java/org/truffleruby/shared/options/OptionsCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class OptionsCatalog {
public static final OptionKey<Boolean> BACKTRACE_ON_RESCUE_KEY = new OptionKey<>(false);
public static final OptionKey<Boolean> CEXTS_KEY = new OptionKey<>(true);
public static final OptionKey<Boolean> CEXT_LOCK_KEY = new OptionKey<>(true);
public static final OptionKey<Boolean> CEXTS_PREPEND_TOOLCHAIN_TO_PATH_KEY = new OptionKey<>(true);
public static final OptionKey<Boolean> CEXTS_KEEP_HANDLES_ALIVE_KEY = new OptionKey<>(false);
public static final OptionKey<Boolean> OPTIONS_LOG_KEY = new OptionKey<>(false);
public static final OptionKey<Boolean> LOG_LOAD_KEY = new OptionKey<>(false);
Expand Down Expand Up @@ -479,6 +480,13 @@ public class OptionsCatalog {
.stability(OptionStability.EXPERIMENTAL)
.build();

public static final OptionDescriptor CEXTS_PREPEND_TOOLCHAIN_TO_PATH = OptionDescriptor
.newBuilder(CEXTS_PREPEND_TOOLCHAIN_TO_PATH_KEY, "ruby.cexts-prepend-toolchain-to-path")
.help("Prepend the GraalVM LLVM Toolchain to PATH when installing gems")
.category(OptionCategory.EXPERT)
.stability(OptionStability.EXPERIMENTAL)
.build();

public static final OptionDescriptor CEXTS_KEEP_HANDLES_ALIVE = OptionDescriptor
.newBuilder(CEXTS_KEEP_HANDLES_ALIVE_KEY, "ruby.keep-handles-alive")
.help("Keep handles for value wrappers alive forever")
Expand Down Expand Up @@ -1149,6 +1157,8 @@ public static OptionDescriptor fromName(String name) {
return CEXTS;
case "ruby.cexts-lock":
return CEXT_LOCK;
case "ruby.cexts-prepend-toolchain-to-path":
return CEXTS_PREPEND_TOOLCHAIN_TO_PATH;
case "ruby.keep-handles-alive":
return CEXTS_KEEP_HANDLES_ALIVE;
case "ruby.options-log":
Expand Down Expand Up @@ -1367,6 +1377,7 @@ public static OptionDescriptor[] allDescriptors() {
BACKTRACE_ON_RESCUE,
CEXTS,
CEXT_LOCK,
CEXTS_PREPEND_TOOLCHAIN_TO_PATH,
CEXTS_KEEP_HANDLES_ALIVE,
OPTIONS_LOG,
LOG_LOAD,
Expand Down
21 changes: 11 additions & 10 deletions test/truffle/cexts/backtraces/ext/backtraces/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
# Compile a real native library
# Commands from src/main/c/truffleposix/Makefile

so = RbConfig::CONFIG['SOEXT']
cc = ENV['CC'] || 'cc'
def command(*args)
$stderr.puts args.join(' ')
ret = system(*args)
raise unless ret
end

dir = File.expand_path('../..', __FILE__)
name = "#{dir}/libnativetest"
so = RbConfig::CONFIG['SOEXT']

original_path = ENV['PATH'].delete_prefix("#{RbConfig::CONFIG['toolchain_path']}:")
system_cc = find_executable('cc', original_path)

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

def command(*args)
$stderr.puts args.join(' ')
ret = system(*args)
raise unless ret
end

command cc, '-o', "#{name}.o", '-c', *cflags, *ldflags, "#{name}.c"
command cc, '-shared', *ldflags, '-o', "#{name}.#{so}", "#{name}.o"
command system_cc, '-o', "#{name}.o", '-c', *cflags, *ldflags, "#{name}.c"
command system_cc, '-shared', *ldflags, '-o', "#{name}.#{so}", "#{name}.o"

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

Expand Down

0 comments on commit 5f33393

Please sign in to comment.