Skip to content

Commit

Permalink
deps: migrate rules_ruby to bzlmod
Browse files Browse the repository at this point in the history
  • Loading branch information
satreix committed Jul 12, 2024
1 parent c44b05e commit 33d865b
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 86 deletions.
18 changes: 18 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_cue", version = "0.7.0")
bazel_dep(name = "rules_foreign_cc", version = "0.11.1")
bazel_dep(name = "rules_go", version = "0.48.1", repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_ruby", version = "0.11.0")

ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")
ruby.toolchain(
name = "ruby",
ruby_build_version = "20240612",
version_file = "//:.ruby-version",
)
use_repo(ruby, "ruby")
ruby.bundle_fetch(
name = "bundle",
gemfile = "//:Gemfile",
gemfile_lock = "//:Gemfile.lock",
)
use_repo(ruby, "bundle", "ruby_toolchains")

register_toolchains("@ruby_toolchains//:all")

bazel_dep(name = "rules_rust", version = "0.46.0")

# rules_rust 0.45.1 does not work with protobuf 23.1 and this breaks `bazel test src/rust/...`
Expand Down
27 changes: 0 additions & 27 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ workspace(name = "everest")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazelruby_rules_ruby",
patch_args = ["-p1"],
patches = [
# A fix for https://github.com/bazelruby/rules_ruby/issues/79
"//third_party/bazelruby_rules_ruby:0001-fix-rspec.patch",
],
sha256 = "33217f27c7cc44355dc82bbe172d0ace09c6a73da387bbbcd66cff013d35e498",
strip_prefix = "rules_ruby-8a03f6c54f1bb3ecbbb82c8e2fdbf40e049a8115",
url = "https://github.com/bazelruby/rules_ruby/archive/8a03f6c54f1bb3ecbbb82c8e2fdbf40e049a8115.tar.gz",
)

http_archive(
name = "com_github_antlr_grammars_v4",
build_file_content = """exports_files(glob(["**/*.g4"]), visibility = ["//visibility:public"])""",
Expand Down Expand Up @@ -87,18 +75,3 @@ openapi_tools_generator_bazel_repositories(
openapi_generator_cli_version = "5.4.0",
sha256 = "f3ed312310e390324b33ba2ffff290ce812935207a1493ec5c098d0a441be51c",
)

load("@bazelruby_rules_ruby//ruby:deps.bzl", "rules_ruby_dependencies", "rules_ruby_select_sdk")

rules_ruby_dependencies()

rules_ruby_select_sdk()

load("@bazelruby_rules_ruby//ruby:defs.bzl", "ruby_bundle")

ruby_bundle(
name = "bundle",
bundler_version = "2.5.3",
gemfile = "//:Gemfile",
gemfile_lock = "//:Gemfile.lock",
)
25 changes: 19 additions & 6 deletions src/ruby/hello_world/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
load("@bazelruby_rules_ruby//ruby:defs.bzl", "ruby_binary", "ruby_rspec")
load("@rules_ruby//ruby:defs.bzl", "rb_binary", "rb_test")
load("//tools/test/binary:binary.bzl", "binary_test")

ruby_binary(
rb_binary(
name = "hello_world",
srcs = ["hello_world.rb"],
main = "hello_world.rb",
deps = [
"//src/ruby/hello_world/lib:hello",
],
)

ruby_rspec(
name = "hello_spec_test",
specs = ["//src/ruby/hello_world:spec/hello_spec.rb"],
deps = ["//src/ruby/hello_world/lib:hello"],
rb_test(
name = "rubocop_test",
timeout = "short",
args = [
"src/ruby/hello_world/",
"src/ruby/hello_world/lib/",
"src/ruby/hello_world/spec/",
],
main = "@bundle//bin:rubocop",
tags = ["no-sandbox"],
deps = [
":hello_world",
"//src/ruby/hello_world/lib:hello",
"//src/ruby/hello_world/spec:hello_test",
"@bundle",
],
)

binary_test(
Expand Down
4 changes: 2 additions & 2 deletions src/ruby/hello_world/lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@bazelruby_rules_ruby//ruby:defs.bzl", "ruby_library")
load("@rules_ruby//ruby:defs.bzl", "rb_library")

ruby_library(
rb_library(
name = "hello",
srcs = ["hello.rb"],
visibility = ["//src/ruby/hello_world:__subpackages__"],
Expand Down
14 changes: 14 additions & 0 deletions src/ruby/hello_world/spec/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@rules_ruby//ruby:defs.bzl", "rb_test")

rb_test(
name = "hello_test",
timeout = "short",
srcs = ["hello_spec.rb"],
args = ["src/ruby/hello_world/spec/"],
main = "@bundle//bin:rspec",
visibility = ["//src/ruby/hello_world:__subpackages__"],
deps = [
"//src/ruby/hello_world/lib:hello",
"@bundle",
],
)
34 changes: 19 additions & 15 deletions src/ruby/template/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
load("@bazelruby_rules_ruby//ruby:defs.bzl", "ruby_binary", "ruby_library", "ruby_rspec")
load("@rules_ruby//ruby:defs.bzl", "rb_binary", "rb_test")

ruby_binary(
rb_binary(
name = "template",
srcs = ["template.rb"],
data = glob(["templates/**"]),
main = "template.rb",
visibility = ["//src/ruby/template/spec:__pkg__"],
deps = [
"@bundle//:erb",
"@bundle//:haml",
"@bundle//:slim",
"@bundle",
],
)

ruby_library(
name = "empty",
srcs = ["empty.rb"],
)

ruby_rspec(
name = "template_spec_test",
data = [":template"],
specs = ["//src/ruby/template:spec/template_spec.rb"],
deps = [":empty"], # hack to make rspec happy, not used
rb_test(
name = "rubocop_test",
timeout = "short",
args = [
"src/ruby/template/",
"src/ruby/template/spec/",
],
main = "@bundle//bin:rubocop",
tags = ["no-sandbox"],
deps = [
":template",
"//src/ruby/template/spec:template_test",
"@bundle",
],
)
1 change: 0 additions & 1 deletion src/ruby/template/empty.rb

This file was deleted.

14 changes: 14 additions & 0 deletions src/ruby/template/spec/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@rules_ruby//ruby:defs.bzl", "rb_test")

rb_test(
name = "template_test",
timeout = "short",
srcs = ["template_spec.rb"],
args = ["src/ruby/template/spec/"],
data = ["//src/ruby/template"],
main = "@bundle//bin:rspec",
visibility = ["//src/ruby/template:__subpackages__"],
deps = [
"@bundle",
],
)
4 changes: 1 addition & 3 deletions src/ruby/template/spec/template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require_relative '../template'

EXPECTED_OUTPUT = "=== ERB ===
<h1>Hello, ERB!</h1>
=== Haml ===
Expand All @@ -12,7 +10,7 @@

RSpec.describe 'template', 'main' do # rubocop:disable RSpec/DescribeClass, RSpec/DescribeMethod
it 'renders templates' do
expect { system %(./src/ruby/template/template) }
expect { system %(./src/ruby/template/template.sh) }
.to output(EXPECTED_OUTPUT)
.to_stdout_from_any_process
end
Expand Down
32 changes: 0 additions & 32 deletions third_party/bazelruby_rules_ruby/0001-fix-rspec.patch

This file was deleted.

Empty file.

0 comments on commit 33d865b

Please sign in to comment.