diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8fc5485 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +name: CI + +on: + push: + branches: + - main + - migrate-to-magnus + + pull_request: + +jobs: + ci: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: ["ubuntu-latest", "macos-latest", "windows-latest"] + ruby: ["2.7", "3.0", "3.1", "head"] + steps: + - uses: actions/checkout@v3 + + - uses: oxidize-rb/actions/setup-ruby-and-rust@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + cargo-cache: true + cache-version: v1 + + - name: Run ruby tests + run: bundle exec rake + + - name: Lint rust + run: | + cargo clippy || true # consider enabling this once lints are fixed + cargo fmt --check || true # consider enabling this once lints are fixed diff --git a/.github/workflows/gem.yml b/.github/workflows/gem.yml index c0379ea..5c3199c 100644 --- a/.github/workflows/gem.yml +++ b/.github/workflows/gem.yml @@ -2,6 +2,9 @@ name: Build and release gem on: workflow_dispatch: + push: + branches: + - migrate-to-magnus jobs: native_gem: @@ -10,23 +13,24 @@ jobs: strategy: matrix: platform: - - x86_64-linux - - x86_64-darwin - - arm64-darwin + - "aarch64-linux" + - "arm64-darwin" + - "x86_64-darwin" + - "x86_64-linux" steps: - uses: actions/checkout@v2 - - uses: ruby/setup-ruby@v1 + - uses: oxidize-rb/actions/setup-ruby-and-rust@main with: - ruby-version: '3.1' - bundler-cache: true + ruby-version: "3.1" + bundler-cache: false + cargo-cache: true + cargo-vendor: true - uses: oxidize-rb/cross-gem-action@main with: platform: ${{ matrix.platform }} - setup: | - bundle env: | RUBY_CC_VERSION=3.1.0:3.0.0:2.7.0 diff --git a/.gitignore b/.gitignore index e45c863..bdbcacd 100644 --- a/.gitignore +++ b/.gitignore @@ -16,10 +16,12 @@ mkmf.log # Added by cargo /target -Cargo.lock # build artifacts ext/**/target pkg/ lib/yrb.bundle build/out +vendor/ +target/ +Gemfile.lock diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d260a25 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.checkOnSave.command": "clippy" +} diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..8087f5c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,534 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +dependencies = [ + "memchr", +] + +[[package]] +name = "bindgen" +version = "0.60.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bumpalo" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clang-sys" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a050e2153c5be08febd6734e29298e844fdb0fa21aeddd63b4eb7baa106c69b" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "js-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "lib0" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb83a90e2a0beb4a6c5ffd6ddc24afab7b1340f5615d6050987f311e850724e2" +dependencies = [ + "thiserror", +] + +[[package]] +name = "libc" +version = "0.2.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966" + +[[package]] +name = "libloading" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "linkify" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96dd5884008358112bc66093362197c7248ece00d46624e2cf71e50029f8cff5" +dependencies = [ + "memchr", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "magnus" +version = "0.3.2" +source = "git+https://github.com/matsadler/magnus#cc852bfa31992d882d42509b1165eb5f67f9dc2c" +dependencies = [ + "magnus-macros", + "rb-sys", +] + +[[package]] +name = "magnus-macros" +version = "0.1.0" +source = "git+https://github.com/matsadler/magnus#cc852bfa31992d882d42509b1165eb5f67f9dc2c" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "once_cell" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + +[[package]] +name = "proc-macro2" +version = "1.0.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rb-sys" +version = "0.9.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24b22a374fc2e92eb6f49d7efe4eb7663655c6e9455d9259ed3342cc1599da85" +dependencies = [ + "bindgen", + "linkify", + "rb-sys-build", +] + +[[package]] +name = "rb-sys-build" +version = "0.9.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cd23b6dd929b7d50ccb35a6d3aa77dec364328ab9cb304dd32c629332491671" +dependencies = [ + "regex", + "shell-words", +] + +[[package]] +name = "regex" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" + +[[package]] +name = "smallstr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e922794d168678729ffc7e07182721a14219c65814e66e91b839a272fe5ae4f" +dependencies = [ + "smallvec", +] + +[[package]] +name = "smallvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasm-bindgen" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "yrb" +version = "0.1.3" +dependencies = [ + "lib0", + "magnus", + "yrs", +] + +[[package]] +name = "yrs" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd45a7bd25be78f285276a9054183e5b77cfcce79ecca1beebd0c8816bef32e1" +dependencies = [ + "lib0", + "rand", + "smallstr", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..cddb51f --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = ["ext/yrb"] \ No newline at end of file diff --git a/Gemfile b/Gemfile index 7ca3c3e..585e095 100644 --- a/Gemfile +++ b/Gemfile @@ -5,9 +5,9 @@ source "https://rubygems.org" # Specify your gem's dependencies in y-rb.gemspec gemspec -# gem "github-markup" -# gem "redcarpet" -# gem "rspec", "~> 3.11.0" -# gem "rubocop", "~> 1.35" -# gem "rubocop-rspec", "~> 2.12.1" -# gem "yard" +gem "github-markup" +gem "redcarpet" +gem "rspec", "~> 3.11.0" +gem "rubocop", "~> 1.35" +gem "rubocop-rspec", "~> 2.12.1" +gem "yard" diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index c5aaa06..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,43 +0,0 @@ -PATH - remote: . - specs: - y-rb (0.1.3) - rake (~> 13.0) - rb_sys (~> 0.9.30) - -GEM - remote: https://rubygems.org/ - specs: - activesupport (6.1.6.1) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 1.6, < 2) - minitest (>= 5.1) - tzinfo (~> 2.0) - zeitwerk (~> 2.3) - concurrent-ruby (1.1.10) - i18n (1.12.0) - concurrent-ruby (~> 1.0) - minitar (0.9) - minitest (5.16.3) - rake (13.0.6) - rake-compiler (1.2.0) - rake - rake-compiler-dock (1.2.2) - rb_sys (0.9.30) - tzinfo (2.0.5) - concurrent-ruby (~> 1.0) - zeitwerk (2.6.0) - -PLATFORMS - arm64-darwin-21 - x86_64-linux - -DEPENDENCIES - activesupport (~> 6.1.6.1) - minitar (~> 0.9) - rake-compiler (~> 1.2.0) - rake-compiler-dock (~> 1.2.2) - y-rb! - -BUNDLED WITH - 2.2.32 diff --git a/Rakefile b/Rakefile index 87335e8..e692d54 100644 --- a/Rakefile +++ b/Rakefile @@ -4,15 +4,15 @@ require "bundler/gem_tasks" require "rubygems/package_task" require "rake/testtask" require "rake/extensiontask" -require "rake_compiler_dock" -# require "rspec/core/rake_task" -# require "rubocop/rake_task" -# require "yard" - -task default: %i[test] cross_rubies = %w[3.1.0 3.0.0 2.7.0] -cross_platforms = %w[x86_64-linux x86_64-darwin arm64-darwin] +cross_platforms = %w[ + arm-linux + aarch64-linux + arm64-darwin + x86_64-darwin + x86_64-linux +] ENV["RUBY_CC_VERSION"] = cross_rubies.join(":") spec = Bundler.load_gemspec("y-rb.gemspec") @@ -27,24 +27,47 @@ Rake::ExtensionTask.new("yrb", spec) do |ext| ext.config_script = ENV["ALTERNATE_CONFIG_SCRIPT"] || "extconf.rb" ext.cross_compiling do |spec| spec.files.reject! { |file| File.fnmatch?("*.tar.gz", file) } + spec.dependencies.reject! { |dep| dep.name == "rb-sys" } end end task :setup do + require "rake_compiler_dock" RakeCompilerDock.sh "bundle" +rescue => e + warn e.message end cross_platforms.each do |p| task "native:#{p}" => :setup end -# RSpec::Core::RakeTask.new(:spec, [] => [:compile]) -# -# task test: :spec -# -# task :docs do -# `yard server --reload` -# end +begin + require "rspec/core/rake_task" + RSpec::Core::RakeTask.new(:spec, [] => [:compile]) + task test: :spec + task default: %i[test] +rescue LoadError + # Ok +end + +begin + require "rubocop/rake_task" + + RuboCop::RakeTask.new +rescue LoadError + # Ok +end + + +begin + require "yard" + + YARD::Rake::YardocTask.new -# RuboCop::RakeTask.new -# YARD::Rake::YardocTask.new + task :docs do + `yard server --reload` + end +rescue LoadError + # Ok +end diff --git a/ext/yrb/Cargo.toml b/ext/yrb/Cargo.toml index aee045f..89053e9 100644 --- a/ext/yrb/Cargo.toml +++ b/ext/yrb/Cargo.toml @@ -8,10 +8,13 @@ repository = "https://github.com/y-crdt/yrb" [dependencies] lib0 = "0.11.2" # must match yrs version -magnus = "0.3.2" - +magnus = { git = "https://github.com/matsadler/magnus" } # waiting for release with full rb-sys backend yrs = "0.11.2" +[dev-dependencies] +magnus = { git = "https://github.com/matsadler/magnus", features = ["embed"] } # waiting for release with full rb-sys backend + + [lib] name = "yrb" crate-type = ["cdylib"] diff --git a/ext/yrb/src/yarray.rs b/ext/yrb/src/yarray.rs index 559f6a7..0515334 100644 --- a/ext/yrb/src/yarray.rs +++ b/ext/yrb/src/yarray.rs @@ -11,6 +11,9 @@ use yrs::Array; #[magnus::wrap(class = "Y::Array")] pub(crate) struct YArray(pub(crate) RefCell); +/// SAFETY: This is safe because we only access this data when the GVL is held. +unsafe impl Send for YArray {} + impl YArray { pub(crate) fn yarray_each(&self, block: Proc) -> () { self.0.borrow_mut().iter().for_each(|val| { diff --git a/ext/yrb/src/ymap.rs b/ext/yrb/src/ymap.rs index e52d7c4..80717a5 100644 --- a/ext/yrb/src/ymap.rs +++ b/ext/yrb/src/ymap.rs @@ -11,6 +11,9 @@ use yrs::Map; #[magnus::wrap(class = "Y::Map")] pub(crate) struct YMap(pub(crate) RefCell); +/// SAFETY: This is safe because we only access this data when the GVL is held. +unsafe impl Send for YMap {} + impl YMap { pub(crate) fn ymap_clear(&self, transaction: &YTransaction) { self.0.borrow_mut().clear(&mut *transaction.0.borrow_mut()); diff --git a/ext/yrb/src/ytext.rs b/ext/yrb/src/ytext.rs index 1379613..2250799 100644 --- a/ext/yrb/src/ytext.rs +++ b/ext/yrb/src/ytext.rs @@ -12,6 +12,9 @@ use yrs::Text; #[magnus::wrap(class = "Y::Text")] pub(crate) struct YText(pub(crate) RefCell); +/// SAFETY: This is safe because we only access this data when the GVL is held. +unsafe impl Send for YText {} + impl YText { pub(crate) fn ytext_format( &self, diff --git a/ext/yrb/src/ytransaction.rs b/ext/yrb/src/ytransaction.rs index efc97a8..e3cc22c 100644 --- a/ext/yrb/src/ytransaction.rs +++ b/ext/yrb/src/ytransaction.rs @@ -12,6 +12,9 @@ use yrs::{Transaction, Update}; #[magnus::wrap(class = "Y::Transaction")] pub(crate) struct YTransaction(pub(crate) RefCell); +/// SAFETY: This is safe because we only access this data when the GVL is held. +unsafe impl Send for YTransaction {} + impl YTransaction { pub(crate) fn ytransaction_apply_update( &self, diff --git a/ext/yrb/src/yvalue.rs b/ext/yrb/src/yvalue.rs index 679bf96..3101d16 100644 --- a/ext/yrb/src/yvalue.rs +++ b/ext/yrb/src/yvalue.rs @@ -225,11 +225,13 @@ impl Into for YValue { mod tests { use crate::yvalue::YValue; use lib0::any::Any; - use magnus::RArray; #[test] fn convert_any_to_yvalue() { + let _cleanup = unsafe { magnus::embed::init() }; let value = Any::Null; let yvalue: YValue = value.into(); + + assert!(yvalue.0.into_inner().is_nil()); } } diff --git a/ext/yrb/src/yxml_element.rs b/ext/yrb/src/yxml_element.rs index 712a726..7a177cd 100644 --- a/ext/yrb/src/yxml_element.rs +++ b/ext/yrb/src/yxml_element.rs @@ -10,6 +10,9 @@ use yrs::{Xml, XmlElement}; #[magnus::wrap(class = "Y::XMLElement")] pub(crate) struct YXmlElement(pub(crate) RefCell); +/// SAFETY: This is safe because we only access this data when the GVL is held. +unsafe impl Send for YXmlElement {} + impl YXmlElement { pub(crate) fn yxml_element_attributes(&self) -> RHash { RHash::from_iter(self.0.borrow().attributes().into_iter()) diff --git a/ext/yrb/src/yxml_text.rs b/ext/yrb/src/yxml_text.rs index 90d62b0..76a1cc1 100644 --- a/ext/yrb/src/yxml_text.rs +++ b/ext/yrb/src/yxml_text.rs @@ -9,6 +9,9 @@ use yrs::{Xml, XmlText}; #[magnus::wrap(class = "Y::XMLText")] pub(crate) struct YXmlText(pub(crate) RefCell); +/// SAFETY: This is safe because we only access this data when the GVL is held. +unsafe impl Send for YXmlText {} + impl YXmlText { pub(crate) fn yxml_text_attributes(&self) -> RHash { RHash::from_iter(self.0.borrow().attributes().into_iter()) diff --git a/y-rb.gemspec b/y-rb.gemspec index 8d41ad7..05f7fd9 100644 --- a/y-rb.gemspec +++ b/y-rb.gemspec @@ -38,8 +38,6 @@ Gem::Specification.new do |spec| spec.add_dependency "rb_sys", "~> 0.9.30" - spec.add_development_dependency "activesupport", "~> 6.1.6.1" - spec.add_development_dependency "minitar", "~> 0.9" spec.add_development_dependency "rake-compiler", "~> 1.2.0" spec.add_development_dependency "rake-compiler-dock", "~> 1.2.2"