@@ -85,36 +85,34 @@ def _rb_download_impl(repository_ctx):
8585 else :
8686 fail ("missing value for one of mandatory attributes 'version' or 'version_file'" )
8787
88+ engine = "ruby"
89+ env = {}
90+ ruby_binary_name = "ruby"
91+ gem_binary_name = "gem"
8892 if version .startswith ("jruby" ):
8993 _install_jruby (repository_ctx , version )
90- elif version == "system" :
91- _symlink_system_ruby (repository_ctx )
92- elif repository_ctx .os .name .startswith ("windows" ):
93- _install_via_rubyinstaller (repository_ctx , version )
94- else :
95- _install_via_ruby_build (repository_ctx , version )
9694
97- if version . startswith ( "jruby" ):
95+ engine = "jruby"
9896 ruby_binary_name = "jruby"
9997 gem_binary_name = "jgem"
100- else :
101- ruby_binary_name = "ruby"
102- gem_binary_name = "gem"
103-
104- env = {}
105- engine = "ruby"
106- if version .startswith ("jruby" ):
107- engine = "jruby"
10898
10999 # JRuby might fail with "Errno::EACCES: Permission denied - NUL" on Windows:
110100 # https://github.com/jruby/jruby/issues/7182#issuecomment-1112953015
111101 env .update ({"JAVA_OPTS" : "-Djdk.io.File.enableADS=true" })
112102 elif version .startswith ("truffleruby" ):
103+ _install_via_ruby_build (repository_ctx , version )
104+
113105 engine = "truffleruby"
114106
115107 # TruffleRuby needs explicit locale
116108 # https://www.graalvm.org/dev/reference-manual/ruby/UTF8Locale/
117109 env .update ({"LANG" : "en_US.UTF-8" })
110+ elif version == "system" :
111+ engine = _symlink_system_ruby (repository_ctx )
112+ elif repository_ctx .os .name .startswith ("windows" ):
113+ _install_via_rubyinstaller (repository_ctx , version )
114+ else :
115+ _install_via_ruby_build (repository_ctx , version )
118116
119117 includes = []
120118 if repository_ctx .path ("dist/include" ).exists :
@@ -262,11 +260,22 @@ def _symlink_system_ruby(repository_ctx):
262260 result = repository_ctx .execute (["ruby" , "-e" , "puts RbConfig.ruby" ])
263261 if result .return_code != 0 :
264262 fail ("Failed to determine the system Ruby path:\n %s\n %s" % (result .stdout , result .stderr ))
265- ruby_path = result .stdout .strip ()
266- ruby_dir = repository_ctx .path (ruby_path ).dirname
267- repository_ctx .symlink (ruby_dir , "dist/bin" )
268- if repository_ctx .os .name .startswith ("windows" ):
269- repository_ctx .symlink (ruby_dir .dirname .get_child ("lib" ), "dist/lib" )
263+
264+ _symlink_system_ruby_dir ("bindir" , repository_ctx )
265+ _symlink_system_ruby_dir ("libdir" , repository_ctx )
266+ _symlink_system_ruby_dir ("rubyhdrdir" , repository_ctx )
267+
268+ engine = repository_ctx .execute (["ruby" , "-e" , "puts RbConfig::CONFIG['RUBY_BASE_NAME']" ]).stdout .strip ()
269+ return engine
270+
271+ def _symlink_system_ruby_dir (dirname , repository_ctx ):
272+ prefix = repository_ctx .execute (["ruby" , "-e" , "puts RbConfig::CONFIG['prefix']" ]).stdout .strip ()
273+ path = repository_ctx .execute (["ruby" , "-e" , "puts RbConfig::CONFIG['{dirname}']" .format (dirname = dirname )]).stdout .strip ()
274+ src = repository_ctx .path (path )
275+ dirname = path .removeprefix (prefix ).removeprefix ("/" )
276+ dst = repository_ctx .path ("dist/{dirname}" .format (dirname = dirname ))
277+ if not dst .exists :
278+ repository_ctx .symlink (src , dst )
270279
271280rb_download = repository_rule (
272281 implementation = _rb_download_impl ,
0 commit comments