This is an automated email from the ASF dual-hosted git repository.
psiace pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/main by this push:
new f56aa106 feat(bindings/ruby): Setup the integrate with magnus (#1712)
f56aa106 is described below
commit f56aa106c7628ced28909a539a244c7c27adb445
Author: Chojan Shang <[email protected]>
AuthorDate: Tue Mar 21 23:17:32 2023 +0800
feat(bindings/ruby): Setup the integrate with magnus (#1712)
* feat: init ruby gem
Signed-off-by: Chojan Shang <[email protected]>
* feat: init cargo lib
Signed-off-by: Chojan Shang <[email protected]>
* feat(bindings/ruby): try to work with magnus
Signed-off-by: Chojan Shang <[email protected]>
* fix(bindings/ruby): work with magnus
Signed-off-by: Chojan Shang <[email protected]>
* feat(bindings/ruby): hello opendal
Signed-off-by: Chojan Shang <[email protected]>
* chore(bindings/ruby): add license header
Signed-off-by: Chojan Shang <[email protected]>
* docs(bindings/ruby): polish readme
Signed-off-by: Chojan Shang <[email protected]>
* chore: pin rocksdb
Signed-off-by: Chojan Shang <[email protected]>
* refactor: config ext_dir to keep style
Signed-off-by: Chojan Shang <[email protected]>
* chore: minor fix
Signed-off-by: Chojan Shang <[email protected]>
---------
Signed-off-by: Chojan Shang <[email protected]>
---
Cargo.lock | 102 ++++++++++++++++++++-
Cargo.toml | 1 +
bindings/ruby/.gitignore | 11 +++
Cargo.toml => bindings/ruby/.standard.yml | 17 +---
Cargo.toml => bindings/ruby/Cargo.toml | 28 +++---
Cargo.toml => bindings/ruby/Gemfile | 22 ++---
bindings/ruby/README.md | 23 +++++
Cargo.toml => bindings/ruby/Rakefile | 33 ++++---
Cargo.toml => bindings/ruby/extconf.rb | 16 +---
Cargo.toml => bindings/ruby/lib/opendal.rb | 16 +---
.../ruby/lib/opendal_ruby/version.rb | 17 +---
bindings/ruby/opendal.gemspec | 61 ++++++++++++
bindings/ruby/src/lib.rs | 30 ++++++
Cargo.toml => bindings/ruby/test/opendal_test.rb | 19 ++--
Cargo.toml => bindings/ruby/test/test_helper.rb | 18 +---
15 files changed, 297 insertions(+), 117 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 41bafbb0..0fb64c49 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -284,6 +284,25 @@ dependencies = [
"tokio",
]
+[[package]]
+name = "bindgen"
+version = "0.60.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6"
+dependencies = [
+ "bitflags 1.3.2",
+ "cexpr",
+ "clang-sys",
+ "lazy_static",
+ "lazycell",
+ "peeking_take_while",
+ "proc-macro2",
+ "quote",
+ "regex",
+ "rustc-hash",
+ "shlex",
+]
+
[[package]]
name = "bindgen"
version = "0.64.0"
@@ -1438,16 +1457,16 @@ dependencies = [
[[package]]
name = "iana-time-zone"
-version = "0.1.53"
+version = "0.1.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765"
+checksum = "0c17cc76786e99f8d2f055c11159e7f0091c42474dcc3189fbab96072e873e6d"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
- "winapi",
+ "windows",
]
[[package]]
@@ -1681,7 +1700,7 @@ version = "0.10.0+7.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fe4d5874f5ff2bc616e55e8c6086d478fcda13faf9495768a4aa1c22042d30b"
dependencies = [
- "bindgen",
+ "bindgen 0.64.0",
"bzip2-sys",
"cc",
"glob",
@@ -1759,6 +1778,28 @@ dependencies = [
"libc",
]
+[[package]]
+name = "magnus"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f3fda351681130b40996b3e40592565b5e44ef1a677c45ea3768ed223b5918a5"
+dependencies = [
+ "magnus-macros",
+ "rb-sys",
+ "rb-sys-env",
+]
+
+[[package]]
+name = "magnus-macros"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "85aa71c9891b2732ff1157e1860a1ee578459fd25811fd3d72cc6e32b3fbdfea"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 1.0.109",
+]
+
[[package]]
name = "match_cfg"
version = "0.1.0"
@@ -2209,6 +2250,14 @@ dependencies = [
"tokio",
]
+[[package]]
+name = "opendal_ruby"
+version = "0.1.0"
+dependencies = [
+ "magnus",
+ "opendal",
+]
+
[[package]]
name = "openssl"
version = "0.10.47"
@@ -2876,6 +2925,36 @@ dependencies = [
"num_cpus",
]
+[[package]]
+name = "rb-sys"
+version = "0.9.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "74a18381b4e31d2c3d0f7bdbcce22d53f6ff18131842d1fec1adcef6527ff573"
+dependencies = [
+ "rb-sys-build",
+]
+
+[[package]]
+name = "rb-sys-build"
+version = "0.9.69"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a9e211890b3bd43f4d90111b7bfd863b519e3c62a5118f1bf620a0ffb43ec7f3"
+dependencies = [
+ "bindgen 0.60.1",
+ "lazy_static",
+ "proc-macro2",
+ "quote",
+ "regex",
+ "shell-words",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "rb-sys-env"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a35802679f07360454b418a5d1735c89716bde01d35b1560fc953c1415a0b3bb"
+
[[package]]
name = "redis"
version = "0.22.3"
@@ -3365,6 +3444,12 @@ dependencies = [
"lazy_static",
]
+[[package]]
+name = "shell-words"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
+
[[package]]
name = "shlex"
version = "1.1.0"
@@ -4285,6 +4370,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+[[package]]
+name = "windows"
+version = "0.46.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25"
+dependencies = [
+ "windows-targets",
+]
+
[[package]]
name = "windows-sys"
version = "0.42.0"
diff --git a/Cargo.toml b/Cargo.toml
index 3b87d145..9522c0ae 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -26,6 +26,7 @@ members = [
"bindings/nodejs",
"bindings/object_store",
"bindings/python",
+ "bindings/ruby",
"bin/oli",
]
diff --git a/bindings/ruby/.gitignore b/bindings/ruby/.gitignore
new file mode 100644
index 00000000..2db1ceb9
--- /dev/null
+++ b/bindings/ruby/.gitignore
@@ -0,0 +1,11 @@
+/.bundle/
+/.yardoc
+/_yardoc/
+/coverage/
+/doc/
+/pkg/
+/spec/reports/
+/tmp/
+*.bundle
+*.so
+Gemfile.lock
\ No newline at end of file
diff --git a/Cargo.toml b/bindings/ruby/.standard.yml
similarity index 82%
copy from Cargo.toml
copy to bindings/ruby/.standard.yml
index 3b87d145..3450e559 100644
--- a/Cargo.toml
+++ b/bindings/ruby/.standard.yml
@@ -15,17 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-[profile.bench]
-debug = true
-
-[workspace]
-members = [
- "core",
-
- "bindings/c",
- "bindings/nodejs",
- "bindings/object_store",
- "bindings/python",
-
- "bin/oli",
-]
+# For available configuration options, see:
+# https://github.com/testdouble/standard
+ruby_version: 2.6
diff --git a/Cargo.toml b/bindings/ruby/Cargo.toml
similarity index 65%
copy from Cargo.toml
copy to bindings/ruby/Cargo.toml
index 3b87d145..63d7a762 100644
--- a/Cargo.toml
+++ b/bindings/ruby/Cargo.toml
@@ -15,17 +15,21 @@
# specific language governing permissions and limitations
# under the License.
-[profile.bench]
-debug = true
+[package]
+authors = ["OpenDAL Contributors <[email protected]>"]
+edition = "2021"
+homepage = "https://opendal.apache.org/"
+license = "Apache-2.0"
+name = "opendal_ruby"
+publish = false
+repository = "https://github.com/apache/incubator-opendal"
+version = "0.1.0"
-[workspace]
-members = [
- "core",
+[lib]
+crate-type = ["cdylib"]
+doc = false
+name = "opendal_ruby"
- "bindings/c",
- "bindings/nodejs",
- "bindings/object_store",
- "bindings/python",
-
- "bin/oli",
-]
+[dependencies]
+opendal = { version = "0.30", path = "../../core" }
+magnus = "0.5"
\ No newline at end of file
diff --git a/Cargo.toml b/bindings/ruby/Gemfile
similarity index 74%
copy from Cargo.toml
copy to bindings/ruby/Gemfile
index 3b87d145..27866d0d 100644
--- a/Cargo.toml
+++ b/bindings/ruby/Gemfile
@@ -15,17 +15,17 @@
# specific language governing permissions and limitations
# under the License.
-[profile.bench]
-debug = true
+# frozen_string_literal: true
-[workspace]
-members = [
- "core",
+source "https://rubygems.org"
- "bindings/c",
- "bindings/nodejs",
- "bindings/object_store",
- "bindings/python",
+# Specify your gem's dependencies in opendal.gemspec
+gemspec
- "bin/oli",
-]
+gem "rake", "~> 13.0"
+
+gem "minitest", "~> 5.10"
+gem "minitest-reporters", "~> 1.1"
+gem "color_pound_spec_reporter", "~> 0.0.6"
+
+gem "standard", "~> 1.3"
diff --git a/bindings/ruby/README.md b/bindings/ruby/README.md
new file mode 100644
index 00000000..15db8fb2
--- /dev/null
+++ b/bindings/ruby/README.md
@@ -0,0 +1,23 @@
+# OpenDAL Ruby Binding
+
+This crate intends to build a native ruby binding.
+
+## Development
+
+Install gems:
+
+```shell
+bundle install
+```
+
+Build bindings:
+
+```shell
+rake compile
+```
+
+Run some tests:
+
+```shell
+rake test
+```
diff --git a/Cargo.toml b/bindings/ruby/Rakefile
similarity index 61%
copy from Cargo.toml
copy to bindings/ruby/Rakefile
index 3b87d145..89bbfaef 100644
--- a/Cargo.toml
+++ b/bindings/ruby/Rakefile
@@ -15,17 +15,28 @@
# specific language governing permissions and limitations
# under the License.
-[profile.bench]
-debug = true
+# frozen_string_literal: true
-[workspace]
-members = [
- "core",
+require "rake/testtask"
+require "rake/extensiontask"
+require "bundler/gem_tasks"
+require "standard/rake"
- "bindings/c",
- "bindings/nodejs",
- "bindings/object_store",
- "bindings/python",
+task default: ["lint", "test"]
- "bin/oli",
-]
+Rake::ExtensionTask.new do |ext|
+ ext.name = "opendal_ruby"
+ ext.ext_dir = "."
+ ext.lib_dir = "lib/opendal_ruby"
+end
+
+task lint: :standard
+
+task :dev do
+ ENV["RB_SYS_CARGO_PROFILE"] = "dev"
+end
+
+Rake::TestTask.new do |t|
+ t.deps << :dev << :compile
+ t.test_files = FileList[File.expand_path("test/*_test.rb", __dir__)]
+end
diff --git a/Cargo.toml b/bindings/ruby/extconf.rb
similarity index 82%
copy from Cargo.toml
copy to bindings/ruby/extconf.rb
index 3b87d145..98ec2ea8 100644
--- a/Cargo.toml
+++ b/bindings/ruby/extconf.rb
@@ -15,17 +15,7 @@
# specific language governing permissions and limitations
# under the License.
-[profile.bench]
-debug = true
+require "mkmf"
+require "rb_sys/mkmf"
-[workspace]
-members = [
- "core",
-
- "bindings/c",
- "bindings/nodejs",
- "bindings/object_store",
- "bindings/python",
-
- "bin/oli",
-]
+create_rust_makefile("opendal_ruby/opendal_ruby")
diff --git a/Cargo.toml b/bindings/ruby/lib/opendal.rb
similarity index 82%
copy from Cargo.toml
copy to bindings/ruby/lib/opendal.rb
index 3b87d145..0e477faa 100644
--- a/Cargo.toml
+++ b/bindings/ruby/lib/opendal.rb
@@ -15,17 +15,7 @@
# specific language governing permissions and limitations
# under the License.
-[profile.bench]
-debug = true
+# frozen_string_literal: true
-[workspace]
-members = [
- "core",
-
- "bindings/c",
- "bindings/nodejs",
- "bindings/object_store",
- "bindings/python",
-
- "bin/oli",
-]
+require "opendal_ruby/version"
+require_relative "opendal_ruby/opendal_ruby"
diff --git a/Cargo.toml b/bindings/ruby/lib/opendal_ruby/version.rb
similarity index 82%
copy from Cargo.toml
copy to bindings/ruby/lib/opendal_ruby/version.rb
index 3b87d145..a5927bb8 100644
--- a/Cargo.toml
+++ b/bindings/ruby/lib/opendal_ruby/version.rb
@@ -15,17 +15,8 @@
# specific language governing permissions and limitations
# under the License.
-[profile.bench]
-debug = true
+# frozen_string_literal: true
-[workspace]
-members = [
- "core",
-
- "bindings/c",
- "bindings/nodejs",
- "bindings/object_store",
- "bindings/python",
-
- "bin/oli",
-]
+module OpenDAL
+ VERSION = "0.1.0"
+end
diff --git a/bindings/ruby/opendal.gemspec b/bindings/ruby/opendal.gemspec
new file mode 100644
index 00000000..d30b4a6d
--- /dev/null
+++ b/bindings/ruby/opendal.gemspec
@@ -0,0 +1,61 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# frozen_string_literal: true
+
+require_relative "lib/opendal_ruby/version"
+
+Gem::Specification.new do |spec|
+ spec.name = "opendal"
+ spec.version = OpenDAL::VERSION
+ spec.authors = ["OpenDAL Contributors"]
+ spec.email = ["[email protected]"]
+
+ spec.summary = "OpenDAL Ruby Binding"
+ spec.homepage = "https://opendal.apache.org/"
+ spec.required_ruby_version = ">= 2.6.0"
+
+ spec.metadata["allowed_push_host"] = "TODO: Set to your gem server
'https://example.com'"
+
+ spec.metadata["homepage_uri"] = spec.homepage
+ spec.metadata["source_code_uri"] =
"https://github.com/apache/incubator-opendal"
+ spec.metadata["changelog_uri"] =
"https://github.com/apache/incubator-opendal/releases"
+
+ # Specify which files should be added to the gem when it is released.
+ # The `git ls-files -z` loads the files in the RubyGem that have been added
into git.
+ spec.files = Dir.chdir(__dir__) do
+ `git ls-files -z`.split("\x0").reject do |f|
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/
features/ .git .circleci appveyor])
+ end
+ end
+ spec.bindir = "exe"
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
+ spec.require_paths = ["lib"]
+
+ # Uncomment to register a new dependency of your gem
+ # spec.add_dependency "example-gem", "~> 1.0"
+ spec.extensions = ["./extconf.rb"]
+
+ # needed until rubygems supports Rust support is out of beta
+ spec.add_dependency "rb_sys", "~> 0.9.39"
+
+ # only needed when developing or packaging your gem
+ spec.add_development_dependency "rake-compiler", "~> 1.2.0"
+
+ # For more information and examples about making a new gem, check out our
+ # guide at: https://bundler.io/guides/creating_gem.html
+end
diff --git a/bindings/ruby/src/lib.rs b/bindings/ruby/src/lib.rs
new file mode 100644
index 00000000..e3f1c3a1
--- /dev/null
+++ b/bindings/ruby/src/lib.rs
@@ -0,0 +1,30 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use magnus::{define_global_function, function, Error};
+use opendal::{services::Memory, Operator};
+
+fn hello_opendal() {
+ let op = Operator::new(Memory::default()).unwrap().finish();
+ println!("{op:?}")
+}
+
+#[magnus::init]
+fn init() -> Result<(), Error> {
+ define_global_function("hello_opendal", function!(hello_opendal, 0));
+ Ok(())
+}
diff --git a/Cargo.toml b/bindings/ruby/test/opendal_test.rb
similarity index 82%
copy from Cargo.toml
copy to bindings/ruby/test/opendal_test.rb
index 3b87d145..1b5c2ac6 100644
--- a/Cargo.toml
+++ b/bindings/ruby/test/opendal_test.rb
@@ -15,17 +15,10 @@
# specific language governing permissions and limitations
# under the License.
-[profile.bench]
-debug = true
+require_relative "test_helper"
-[workspace]
-members = [
- "core",
-
- "bindings/c",
- "bindings/nodejs",
- "bindings/object_store",
- "bindings/python",
-
- "bin/oli",
-]
+class OpenDALTest < Minitest::Test
+ def test_hello_opendal
+ hello_opendal
+ end
+end
diff --git a/Cargo.toml b/bindings/ruby/test/test_helper.rb
similarity index 78%
copy from Cargo.toml
copy to bindings/ruby/test/test_helper.rb
index 3b87d145..63a525f7 100644
--- a/Cargo.toml
+++ b/bindings/ruby/test/test_helper.rb
@@ -15,17 +15,9 @@
# specific language governing permissions and limitations
# under the License.
-[profile.bench]
-debug = true
+$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
+require_relative "../lib/opendal"
-[workspace]
-members = [
- "core",
-
- "bindings/c",
- "bindings/nodejs",
- "bindings/object_store",
- "bindings/python",
-
- "bin/oli",
-]
+require "minitest/autorun"
+require "color_pound_spec_reporter"
+Minitest::Reporters.use! [ColorPoundSpecReporter.new]