Skip to content

Commit

Permalink
[GR-18163] Add option --reuse-precompiled-gems
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4270
  • Loading branch information
andrykonchin committed Jun 5, 2024
2 parents 7a6f722 + edaec88 commit 00dbcfa
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

New features:

* Add `--reuse-precompiled-gems` option (@andrykonchin).

Bug fixes:

* Add missing thread-safe objects write barriers for `TruffleRuby::ConcurrentMap` (#3179, @eregon).
Expand All @@ -26,6 +28,7 @@ Compatibility:
* Support `:buffer` keyword argument to `Array#pack` (#3559, @andrykonchyn).

Performance:

* Fix inline caching for Regexp creation from Strings (#3492, @andrykonchin, @eregon).
* Optimize `Integer#pow` method for small modulus values (#3544, @andrykonchin).

Expand Down
2 changes: 1 addition & 1 deletion lib/truffle/rubygems/defaults/truffleruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ def self.platform_defaults

class Gem::Platform
# The list of gems we want to install precompiled (using the local platform) on TruffleRuby
REUSE_AS_BINARY_ON_TRUFFLERUBY = %w[libv8 libv8-node sass-embedded sorbet-static]
REUSE_AS_BINARY_ON_TRUFFLERUBY = %w[libv8 libv8-node sass-embedded sorbet-static] + Truffle::Boot.get_option('reuse-precompiled-gems')
end
1 change: 1 addition & 0 deletions spec/tags/truffle/options/reuse_precompiled_gems_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
slow:The --reuse-precompiled-gems option adds listed gems into a Gem::Platform::REUSE_AS_BINARY_ON_TRUFFLERUBY list
15 changes: 15 additions & 0 deletions spec/truffle/options/reuse_precompiled_gems_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 2.0, or
# GNU General Public License version 2, or
# GNU Lesser General Public License version 2.1.

require_relative '../../ruby/spec_helper'

describe "The --reuse-precompiled-gems option" do
it "adds listed gems into a Gem::Platform::REUSE_AS_BINARY_ON_TRUFFLERUBY list" do
ruby_exe("p Gem::Platform::REUSE_AS_BINARY_ON_TRUFFLERUBY", options: "--experimental-options --reuse-precompiled-gems=foo,bar").should.include? '"foo", "bar"'
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ private void processArgv() {
value = null;
}

// Switches without values are stored separately in ARGV_GLOBAL_FLAGS. Otherwise it would not be
// possible to determine if the value is suppose to be `true` or `"true"`.
// Switches without values are stored separately in ARGV_GLOBAL_FLAGS. Otherwise, it would not be
// possible to determine if the value is supposed to be `true` or `"true"`.
final OptionDescriptor optionDescription = value != null
? OptionsCatalog.ARGV_GLOBAL_VALUES
: OptionsCatalog.ARGV_GLOBAL_FLAGS;
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 @@ -135,6 +135,8 @@ public final class Options {
public final boolean WARN_TRUFFLE_REGEX_MATCH_FALLBACK;
/** --truffle-regex-ignore-atomic-groups=false */
public final boolean TRUFFLE_REGEX_IGNORE_ATOMIC_GROUPS;
/** --reuse-precompiled-gems=StringArrayOptionType.EMPTY_STRING_ARRAY */
public final String[] REUSE_PRECOMPILED_GEMS;
/** --argv-globals=false */
public final boolean ARGV_GLOBALS;
/** --chomp-loop=false */
Expand Down Expand Up @@ -262,6 +264,7 @@ public Options(Env env, OptionValues options, LanguageOptions languageOptions) {
WARN_TRUFFLE_REGEX_COMPILE_FALLBACK = options.get(OptionsCatalog.WARN_TRUFFLE_REGEX_COMPILE_FALLBACK_KEY);
WARN_TRUFFLE_REGEX_MATCH_FALLBACK = options.get(OptionsCatalog.WARN_TRUFFLE_REGEX_MATCH_FALLBACK_KEY);
TRUFFLE_REGEX_IGNORE_ATOMIC_GROUPS = options.get(OptionsCatalog.TRUFFLE_REGEX_IGNORE_ATOMIC_GROUPS_KEY);
REUSE_PRECOMPILED_GEMS = options.get(OptionsCatalog.REUSE_PRECOMPILED_GEMS_KEY);
ARGV_GLOBALS = options.get(OptionsCatalog.ARGV_GLOBALS_KEY);
CHOMP_LOOP = options.get(OptionsCatalog.CHOMP_LOOP_KEY);
GETS_LOOP = options.get(OptionsCatalog.GETS_LOOP_KEY);
Expand Down Expand Up @@ -411,6 +414,8 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
return WARN_TRUFFLE_REGEX_MATCH_FALLBACK;
case "ruby.truffle-regex-ignore-atomic-groups":
return TRUFFLE_REGEX_IGNORE_ATOMIC_GROUPS;
case "ruby.reuse-precompiled-gems":
return REUSE_PRECOMPILED_GEMS;
case "ruby.argv-globals":
return ARGV_GLOBALS;
case "ruby.chomp-loop":
Expand Down
2 changes: 2 additions & 0 deletions src/options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ EXPERT:
WARN_TRUFFLE_REGEX_MATCH_FALLBACK: [warn-truffle-regex-match-fallback, boolean, false, 'Warn every time Truffle Regex cannot be used for a Regexp match (and instead Joni is used)']
TRUFFLE_REGEX_IGNORE_ATOMIC_GROUPS: [truffle-regex-ignore-atomic-groups, boolean, false, 'Treat atomic groups (?>...) as ordinary groups (?:...) with Truffle Regex.']

REUSE_PRECOMPILED_GEMS: [reuse-precompiled-gems, string-array, '<gem>,<gem>,...', 'A list of gems we want to install precompiled (using the local platform) on TruffleRuby. Can only be used for gem extensions which do not depend on the Ruby C API.']

INTERNAL: # Options for debugging the TruffleRuby implementation
EXPERIMENTAL:
# Options corresponding to MRI options, which are only meaningful when using the TruffleRuby launcher
Expand Down
12 changes: 12 additions & 0 deletions src/shared/java/org/truffleruby/shared/options/OptionsCatalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public final class OptionsCatalog {
public static final OptionKey<Boolean> WARN_TRUFFLE_REGEX_COMPILE_FALLBACK_KEY = new OptionKey<>(false);
public static final OptionKey<Boolean> WARN_TRUFFLE_REGEX_MATCH_FALLBACK_KEY = new OptionKey<>(false);
public static final OptionKey<Boolean> TRUFFLE_REGEX_IGNORE_ATOMIC_GROUPS_KEY = new OptionKey<>(false);
public static final OptionKey<String[]> REUSE_PRECOMPILED_GEMS_KEY = new OptionKey<>(StringArrayOptionType.EMPTY_STRING_ARRAY, StringArrayOptionType.INSTANCE);
public static final OptionKey<Boolean> ARGV_GLOBALS_KEY = new OptionKey<>(false);
public static final OptionKey<Boolean> CHOMP_LOOP_KEY = new OptionKey<>(false);
public static final OptionKey<Boolean> GETS_LOOP_KEY = new OptionKey<>(false);
Expand Down Expand Up @@ -684,6 +685,14 @@ public final class OptionsCatalog {
.usageSyntax("")
.build();

public static final OptionDescriptor REUSE_PRECOMPILED_GEMS = OptionDescriptor
.newBuilder(REUSE_PRECOMPILED_GEMS_KEY, "ruby.reuse-precompiled-gems")
.help("A list of gems we want to install precompiled (using the local platform) on TruffleRuby. Can only be used for gem extensions which do not depend on the Ruby C API.")
.category(OptionCategory.EXPERT)
.stability(OptionStability.EXPERIMENTAL)
.usageSyntax("<gem>,<gem>,...")
.build();

public static final OptionDescriptor ARGV_GLOBALS = OptionDescriptor
.newBuilder(ARGV_GLOBALS_KEY, "ruby.argv-globals")
.help("Parse options in script argv into global variables (configured by the -s Ruby option)")
Expand Down Expand Up @@ -1440,6 +1449,8 @@ public static OptionDescriptor fromName(String name) {
return WARN_TRUFFLE_REGEX_MATCH_FALLBACK;
case "ruby.truffle-regex-ignore-atomic-groups":
return TRUFFLE_REGEX_IGNORE_ATOMIC_GROUPS;
case "ruby.reuse-precompiled-gems":
return REUSE_PRECOMPILED_GEMS;
case "ruby.argv-globals":
return ARGV_GLOBALS;
case "ruby.chomp-loop":
Expand Down Expand Up @@ -1668,6 +1679,7 @@ public static OptionDescriptor[] allDescriptors() {
WARN_TRUFFLE_REGEX_COMPILE_FALLBACK,
WARN_TRUFFLE_REGEX_MATCH_FALLBACK,
TRUFFLE_REGEX_IGNORE_ATOMIC_GROUPS,
REUSE_PRECOMPILED_GEMS,
ARGV_GLOBALS,
CHOMP_LOOP,
GETS_LOOP,
Expand Down

0 comments on commit 00dbcfa

Please sign in to comment.