-
Notifications
You must be signed in to change notification settings - Fork 19
feat: expose MRI C headers and JRuby jars #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8ff9910
eb753fc
637e14e
2787dca
e387688
3b882a0
f7cd85e
f10fd7d
228d8a6
0f52ccb
ec1c382
b8421f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| bazel-bin | ||
| bazel-gem | ||
| bazel-out | ||
| bazel-native_ext | ||
| bazel-rules_ruby | ||
| bazel-testlogs |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Not ready for the MODULE.lock file yet, as of Bazel 7.0.0 there are still some stability issues. | ||
| common --lockfile_mode=off | ||
|
|
||
| # Allow to run Bazel without pre-installed JDK. | ||
| # Docs: https://bazel.build/reference/command-line-reference#flag--java_runtime_version | ||
| build --java_runtime_version=remotejdk_11 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| jruby-9.4.9.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_library") | ||
| load("@rules_java//java:defs.bzl", "java_library") | ||
|
|
||
| cc_library( | ||
| name = "ext_c", | ||
| srcs = glob([ | ||
| "ext/**/*.c", | ||
| "ext/**/*.h", | ||
| ]), | ||
| target_compatible_with = select({ | ||
| "@ruby//engine:ruby": [], | ||
| "//conditions:default": ["@platforms//:incompatible"], | ||
| }), | ||
| deps = ["@ruby//:headers"], | ||
| ) | ||
|
|
||
| java_library( | ||
| name = "ext_java", | ||
| srcs = glob(["ext/**/*.java"]), | ||
| target_compatible_with = select({ | ||
| "@ruby//engine:jruby": [], | ||
| "//conditions:default": ["@platforms//:incompatible"], | ||
| }), | ||
| deps = ["@ruby//:jars"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| "Bazel dependencies" | ||
|
|
||
| bazel_dep(name = "platforms", version = "0.0.10", dev_dependency = True) | ||
| bazel_dep(name = "rules_cc", version = "0.1.0", dev_dependency = True) | ||
| bazel_dep(name = "rules_java", version = "8.7.1", dev_dependency = True) | ||
| bazel_dep(name = "rules_ruby", version = "0.0.0", dev_dependency = True) | ||
| local_path_override( | ||
| module_name = "rules_ruby", | ||
| path = "../..", | ||
| ) | ||
|
|
||
| ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby") | ||
| ruby.toolchain( | ||
| name = "ruby", | ||
| version_file = "//:.ruby-version", | ||
| ) | ||
| use_repo(ruby, "ruby", "ruby_toolchains") | ||
|
|
||
| register_toolchains("@ruby_toolchains//:all") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #include "native_ext.h" | ||
|
|
||
| VALUE rb_mNativeExt; | ||
|
|
||
| RUBY_FUNC_EXPORTED void | ||
| Init_native_ext(void) | ||
| { | ||
| rb_mNativeExt = rb_define_module("NativeExt"); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #ifndef NATIVE_EXT_H | ||
| #define NATIVE_EXT_H 1 | ||
|
|
||
| #include "ruby.h" | ||
|
|
||
| #endif /* NATIVE_EXT_H */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import org.jruby.*; | ||
| import org.jruby.anno.JRubyClass; | ||
|
|
||
| @JRubyClass(name = "Dummy") | ||
| public class Dummy { | ||
| public Dummy() { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_library") | ||
| load("@rules_java//java:defs.bzl", "java_import") | ||
| load("@rules_ruby//ruby:defs.bzl", "rb_binary") | ||
| load("@rules_ruby//ruby:toolchain.bzl", "rb_toolchain") | ||
|
|
||
|
|
@@ -16,6 +18,23 @@ rb_binary( | |
| main = ":ruby_file", | ||
| ) | ||
|
|
||
| cc_library( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: there's some flag in bazel forcing these symbols to be
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we should probably use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added an explicit dependency on rules_cc and rules_java in 0f52ccb, I hope that makes sense. Not sure what is the lowest version I could use so I looked at what other rulesets use.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is OK but it feels a bit undesirable that you're forced into carrying these CC/Java toolchain deps even if you have no interest in using them. Don't have any good ideas to avoid it though.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's why I originally didn't add those and used native rules. @alexeagle Can you advise what would be better here?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't really have a choice. This repo wants to expose the providers for interop with users repository, and providers are symbols rather than strings, so they have to be loaded from the same place. We'll hope that rules_java and rules_cc are well-maintained so there aren't breaking changes that mean your users are sensitive to the version you pick. In bzlmod you can pick something old, since you're really picking a lower-bound; the MVS algorithm means users can still resolve to something newer.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For both rulesets, I used > 1-year-old releases and crossed-check what other dependents do (e.g. rules_python, rules_kotlin). |
||
| name = "headers", | ||
| hdrs = glob( | ||
| ["dist/include/**/*.h"], | ||
| allow_empty = True, | ||
| ), | ||
| includes = {includes}, | ||
| ) | ||
|
|
||
| java_import( | ||
| name = "jars", | ||
| jars = glob( | ||
| ["dist/lib/**/*.jar"], | ||
| allow_empty = True, | ||
| ), | ||
| ) | ||
|
|
||
| rb_toolchain( | ||
| name = "toolchain", | ||
| bundle = select({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it's better to gitignore it instead. You can get some perf benefits locally by Bazel reading the lockfile from your previous work, and not share it to others