Skip to content

Commit

Permalink
0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
karreiro committed Jun 9, 2024
1 parent fd419b3 commit 9fef7af
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 33 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/main.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ jobs:
strategy:
matrix:
ruby:
- '3.1.4'
- '3.1'
- '3.2'
- '3.3'

steps:
- uses: actions/checkout@v4
Expand All @@ -24,6 +26,10 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
cargo-cache: true
rubygems: '3.5.10'
cache-version: v2

- name: Run the default task
run: bundle exec rake
run: |
bundle install
bundle exec rake compile
bundle exec rake
119 changes: 119 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
name: Release

on:
workflow_dispatch:
push:
tags: ["v*"]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
ci-data:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.fetch.outputs.result }}
steps:
- id: fetch
uses: oxidize-rb/actions/fetch-ci-data@v1
with:
supported-ruby-platforms: |
# Excluding:
# `arm-linux`: Cranelift doesn't support 32-bit architectures
# `x64-mingw32`: `x64-mingw-ucrt` should be used for Ruby 3.1+ (https://github.com/rake-compiler/rake-compiler-dock?tab=readme-ov-file#windows)
# 3.0 is deprecated as stable ruby version according to:
# https://github.com/oxidize-rb/actions/blob/main/fetch-ci-data/evaluate.rb#L54
exclude: [arm-linux, x64-mingw32]
stable-ruby-versions: |
exclude: [head]
build:
name: Build native gems
needs: ci-data
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby-platform: ${{ fromJSON(needs.ci-data.outputs.result).supported-ruby-platforms }}
steps:
- uses: actions/checkout@v4

- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
ruby-version: "3.3"
bundler-cache: false
cargo-cache: true
cargo-vendor: true
cache-version: v1-${{ matrix.ruby-platform }}

- uses: oxidize-rb/cross-gem-action@main
with:
version: latest
platform: ${{ matrix.ruby-platform }}
ruby-versions: ${{ join(fromJSON(needs.ci-data.outputs.result).stable-ruby-versions, ', ') }}

- name: Smoke gem install
if: matrix.ruby-platform == 'x86_64-linux' # GitHub actions architecture
run: |
gem install pkg/fast_toml-*x86_64-linux.gem --verbose
script="puts FastToml.parse('[it_works]')"
ruby -rfast_toml -e "$script" | grep it_work
echo "✅ Successfully gem installed"
release:
name: Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
ruby-version: "3.3"
bundler-cache: true
cargo-cache: true
cache-version: v1

# It seems that v4 is not compatible with how artifacts are uploaded by
# oxidize-rb/cross-gem-action. So this must stay as v3 until the issue
# below is fixed.
# See https://github.com/oxidize-rb/actions/issues/27, for more details.
- uses: actions/download-artifact@v3
with:
name: cross-gem

- name: Package source gem
run: bundle exec rake build

- name: Ensure version matches the tag
run: |
GEM_VERSION=$(grep 'VERSION =' lib/fast_toml/version.rb | sed -nE "s/.*VERSION = '([^']+)'.*/\1/p")
if [ "v$GEM_VERSION" != "${{ github.ref_name }}" ]; then
echo "Gem version does not match tag"
echo " v$GEM_VERSION != ${{ github.ref_name }}"
exit 1
fi
- name: Push Gem
working-directory: pkg/
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_KEY }}
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
ls -l
for i in *.gem; do
if [ -f "$i" ]; then
if ! gem push "$i" >push.out; then
gemerr=$?
sed 's/^/::error:: /' push.out
if ! grep -q "Repushing of gem" push.out; then
exit $gemerr
fi
fi
fi
done
16 changes: 9 additions & 7 deletions Cargo.lock

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

12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PATH
remote: .
specs:
fast_toml (0.2.0)
rb_sys (= 0.9.97)
fast_toml (0.3.0)
rb_sys (= 0.9.85)

GEM
remote: https://rubygems.org/
Expand All @@ -12,19 +12,19 @@ GEM
citrus (3.0.2)
json (2.7.2)
language_server-protocol (3.17.0.3)
minitest (5.23.0)
minitest (5.23.1)
parallel (1.24.0)
parser (3.3.1.0)
parser (3.3.2.0)
ast (~> 2.4.1)
racc
parslet (2.0.0)
perfect_toml (0.9.0)
racc (1.7.3)
racc (1.8.0)
rainbow (3.1.1)
rake (13.2.1)
rake-compiler (1.2.7)
rake
rb_sys (0.9.97)
rb_sys (0.9.85)
regexp_parser (2.9.2)
rexml (3.2.8)
strscan (>= 3.0.9)
Expand Down
51 changes: 41 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,61 @@
# FastToml

TODO: Delete this and the text below, and describe your gem
[![Ruby](https://github.com/karreiro/fast_toml/actions/workflows/ci.yml/badge.svg)](https://github.com/karreiro/fast_toml/actions/workflows/ci.yml)

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fast_toml`. To experiment with that code, run `bin/console` for an interactive prompt.
FastToml is a high-performance TOML parser for Ruby. It significantly outperforms other TOML parsers available in the Ruby ecosystem by wrapping the Rust `toml` parser in a native extension. FastToml is currently more than twice as fast as the next best parser and nearly 200 times faster than some others.

## Installation

TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
## Installation

Install the gem and add to the application's Gemfile by executing:
To install FastToml, add it to your application's Gemfile by executing:

$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
```
$ bundle add fast_toml
```

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
```
$ gem install fast_toml
```

## Usage

TODO: Write usage instructions here
To use FastToml, require the gem and parse your TOML input as shown in the example below:

```ruby
require 'fast_toml'

TOML_INPUT = <<~TOML
[package]
name = "fast_toml"
version = "0.1.0"
edition = "2021"
license = "MIT"
[dependencies]
magnus = "0.6.4"
toml = "0.8.13"
TOML

parsed_data = FastToml.parse(TOML_INPUT)
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
To install this gem onto your local machine, run `bundle exec rake install`.

## Releasing a New Version

To release a new version, follow these steps:
- Bump the version number in `lib/fast_toml/version.rb`
- Bump the version number in `ext/fast_toml/Cargo.toml`
- Run `bundle install && bundle rake`
- Push your commit
- Push a new tag called `vX.Y.Z`
- Create a release using the GitHub UI

## Contributing

Expand All @@ -36,4 +67,4 @@ The gem is available as open source under the terms of the [MIT License](https:/

## Code of Conduct

Everyone interacting in the FastToml project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/fast_toml/blob/main/CODE_OF_CONDUCT.md).
Everyone interacting in the FastToml project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/fast_toml/blob/main/CODE_OF_CONDUCT.md).
1 change: 0 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require 'bundler/gem_tasks'
require 'minitest/test_task'
require 'rubocop/rake_task'
require 'rb_sys/extensiontask'
require 'lib/fast_toml'

Minitest::TestTask.create

Expand Down
18 changes: 17 additions & 1 deletion ext/fast_toml/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fast_toml"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["Guilherme Carreiro <[email protected]>"]
license = "MIT"
Expand All @@ -12,3 +12,19 @@ crate-type = ["cdylib"]
[dependencies]
magnus = "0.6.4"
toml = "0.8.13"
rb-sys = { version = "0.9.85", features = [
"bindgen-rbimpls",
"bindgen-deprecated-types",
"stable-api-compiled-fallback",
] }

[dev-dependencies]
rb-sys = { version = "0.9.85", features = [
"link-ruby",
"bindgen-rbimpls",
"bindgen-deprecated-types",
"stable-api-compiled-fallback",
] }

[build-dependencies]
rb-sys-env = { version = "0.1.2" }
2 changes: 1 addition & 1 deletion fast_toml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.extensions = ['ext/fast_toml/extconf.rb']
spec.add_dependency 'rb_sys', '0.9.97'
spec.add_dependency 'rb_sys', '0.9.85'
spec.metadata['rubygems_mfa_required'] = 'true'
end
8 changes: 7 additions & 1 deletion lib/fast_toml.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# frozen_string_literal: true

require_relative 'fast_toml/version'
require_relative 'fast_toml/fast_toml'

begin
RUBY_VERSION =~ /(\d+\.\d+)/
require_relative "fast_toml/#{Regexp.last_match(1)}/fast_toml"
rescue LoadError
require_relative 'fast_toml/fast_toml'
end

module FastToml
class Error < StandardError; end
Expand Down
2 changes: 1 addition & 1 deletion lib/fast_toml/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module FastToml
VERSION = '0.2.0'
VERSION = '0.3.0'
end
4 changes: 2 additions & 2 deletions rakelib/benchmark.rake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TOML

namespace :benchmark do
desc 'Benchmark different TOML parsers (ips)'
task :ips do
task ips: :env do
Benchmark.ips do |x|
x.report('fast_toml') { FastToml.parse(TOML_INPUT) }
x.report('toml') { TOML::Parser.new(TOML_INPUT).parsed }
Expand All @@ -39,7 +39,7 @@ namespace :benchmark do
end

desc 'Benchmark different TOML parsers (ms)'
task :ms do
task ms: :env do
n = 5_000

Benchmark.bm(20) do |x|
Expand Down
6 changes: 6 additions & 0 deletions rakelib/env.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

desc 'Initialize fast_json environment'
task :env do
require 'lib/fast_toml'
end

0 comments on commit 9fef7af

Please sign in to comment.