Skip to content

Commit

Permalink
feat: support registering system Ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed Nov 28, 2023
1 parent 63fbb9c commit 27bc31d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
fail-fast: false
matrix:
ruby:
- system
- 3.0.6
- 3.1.4
- 3.2.2
Expand All @@ -49,6 +50,8 @@ jobs:
- os: windows
ruby: truffleruby-23.1.1
# https://github.com/p0deje/rules_ruby/issues/23
- mode: bzlmod
ruby: system
- mode: bzlmod
ruby: 3.0.6
- mode: bzlmod
Expand Down
3 changes: 2 additions & 1 deletion docs/repository_rules.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions ruby/private/download.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ _RUBY_INSTALLER_URL = "https://github.com/oneclick/rubyinstaller2/releases/downl
def _rb_download_impl(repository_ctx):
if repository_ctx.attr.version.startswith("jruby"):
_install_jruby(repository_ctx)
elif repository_ctx.attr.version == "system":
_symlink_system_ruby(repository_ctx)
elif repository_ctx.os.name.startswith("windows"):
_install_via_rubyinstaller(repository_ctx)
else:
Expand Down Expand Up @@ -94,6 +96,11 @@ def _install_via_ruby_build(repository_ctx):
if result.return_code != 0:
fail("%s\n%s" % (result.stdout, result.stderr))

def _symlink_system_ruby(repository_ctx):
repository_ctx.symlink(repository_ctx.which("ruby"), "dist/bin/ruby")
repository_ctx.symlink(repository_ctx.which("bundle"), "dist/bin/bundle")
repository_ctx.symlink(repository_ctx.which("gem"), "dist/bin/gem")

rb_download = repository_rule(
implementation = _rb_download_impl,
attrs = {
Expand Down
9 changes: 7 additions & 2 deletions ruby/private/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def rb_register_toolchains(name = DEFAULT_RUBY_REPOSITORY, version = None, regis
* _(For MRI on Windows)_ Installed using [RubyInstaller](https://rubyinstaller.org).
* _(For JRuby on any OS)_ Downloaded and installed directly from [official website](https://www.jruby.org).
* _(For TruffleRuby on Linux and macOS)_ Installed using [ruby-build](https://github.com/rbenv/ruby-build).
* _(For "system") System Ruby is used.
`WORKSPACE`:
```bazel
Expand All @@ -25,14 +26,18 @@ def rb_register_toolchains(name = DEFAULT_RUBY_REPOSITORY, version = None, regis
Args:
name: base name of resulting repositories, by default "rules_ruby"
version: a semver version of Matz Ruby Interpreter, or a string like [interpreter type]-[version]
version: a semver version of Matz Ruby Interpreter, or a string like [interpreter type]-[version], or "system"
register: whether to register the resulting toolchains, should be False under bzlmod
**kwargs: additional parameters to the downloader for this interpreter type
"""
repo_name = name + "_dist"
proxy_repo_name = name + "_toolchains"
if repo_name not in native.existing_rules().values():
_rb_download(name = repo_name, version = version, **kwargs)
_rb_download(
name = repo_name,
version = version,
**kwargs
)
_rb_toolchain_repository_proxy(
name = proxy_repo_name,
toolchain = "@{}//:toolchain".format(repo_name),
Expand Down

0 comments on commit 27bc31d

Please sign in to comment.