{"id":21820629,"url":"https://github.com/ruby-go-gem/go-gem-wrapper","last_synced_at":"2025-04-14T03:01:19.162Z","repository":{"id":257812443,"uuid":"830570564","full_name":"ruby-go-gem/go-gem-wrapper","owner":"ruby-go-gem","description":"go-gem-wrapper is a wrapper for creating Ruby native extension in Go","archived":false,"fork":false,"pushed_at":"2025-04-13T22:42:23.000Z","size":1179,"stargazers_count":8,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T23:33:59.833Z","etag":null,"topics":["go-gem","go-module","ruby-gem"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/ruby-go-gem/go-gem-wrapper","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ruby-go-gem.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-07-18T14:21:04.000Z","updated_at":"2025-04-13T22:42:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"72a09417-6d89-4c3b-9d46-c9f19284aabf","html_url":"https://github.com/ruby-go-gem/go-gem-wrapper","commit_stats":null,"previous_names":["sue445/go-gem-wrapper"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby-go-gem%2Fgo-gem-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby-go-gem%2Fgo-gem-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby-go-gem%2Fgo-gem-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ruby-go-gem%2Fgo-gem-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ruby-go-gem","download_url":"https://codeload.github.com/ruby-go-gem/go-gem-wrapper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248813789,"owners_count":21165633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go-gem","go-module","ruby-gem"],"created_at":"2024-11-27T16:38:04.004Z","updated_at":"2025-04-14T03:01:19.045Z","avatar_url":"https://github.com/ruby-go-gem.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-gem-wrapper\n`go-gem-wrapper` is a wrapper for creating Ruby native extension in [Go](https://go.dev/)\n\n[![GitHub Tag](https://img.shields.io/github/v/tag/ruby-go-gem/go-gem-wrapper)](https://github.com/ruby-go-gem/go-gem-wrapper/releases)\n[![build](https://github.com/ruby-go-gem/go-gem-wrapper/actions/workflows/build.yml/badge.svg)](https://github.com/ruby-go-gem/go-gem-wrapper/actions/workflows/build.yml)\n[![Coverage Status](https://coveralls.io/repos/github/ruby-go-gem/go-gem-wrapper/badge.svg)](https://coveralls.io/github/ruby-go-gem/go-gem-wrapper)\n[![Go Report Card](https://goreportcard.com/badge/github.com/ruby-go-gem/go-gem-wrapper)](https://goreportcard.com/report/github.com/ruby-go-gem/go-gem-wrapper)\n[![Go Reference](https://pkg.go.dev/badge/github.com/ruby-go-gem/go-gem-wrapper.svg)](https://pkg.go.dev/github.com/ruby-go-gem/go-gem-wrapper)\n\n## Overview\n| Directory        | Name                                                  | API Reference                                            |\n|------------------|-------------------------------------------------------|----------------------------------------------------------|\n| [/](/)           | `github.com/ruby-go-gem/go-gem-wrapper` (Go module)   | https://pkg.go.dev/github.com/ruby-go-gem/go-gem-wrapper |\n| [/_gem/](/_gem/) | [go_gem](https://rubygems.org/gems/go_gem) (Ruby gem) | https://ruby-go-gem.github.io/go-gem-wrapper/            |\n\n## Requirements\n* Go 1.23+\n* Ruby 3.3+\n* glibc\n  * musl (often used in alpine) isn't supported\n  * See. https://github.com/ruby-go-gem/go-gem-wrapper/issues/253\n\nSee [.github/workflows/matrix.json](.github/workflows/matrix.json) for details\n\n## Getting started\nAt first, patch to make a gem into a Go gem right after `bundle gem`\n\nSee [_tools/patch_for_go_gem/](_tools/patch_for_go_gem/)\n\nPlease also add the following depending on the CI you are using.\n\n### GitHub Actions\ne.g.\n\n```yml\n- uses: actions/setup-go@v5\n  with:\n    go-version-file: ext/GEM_NAME/go.mod\n```\n\n## Implementing Ruby methods in Go\nFor example, consider the following Ruby method implemented in Go\n\n```ruby\nmodule Example\n  def self.sum(a, b)\n    a + b\n  end\nend\n```\n\n### 1. Implementing function in Go\n```go\n// ext/GEM_NAME/GEM_NAME.go\n\n//export rb_example_sum\nfunc rb_example_sum(_ C.VALUE, a C.VALUE, b C.VALUE) C.VALUE {\n\taLong := ruby.NUM2LONG(ruby.VALUE(a))\n\tbLong := ruby.NUM2LONG(ruby.VALUE(b))\n\n\tsum := aLong + bLong\n\n\treturn C.VALUE(ruby.LONG2NUM(sum))\n}\n```\n\n### 2. Write C function definitions for Go functions\n```go\n// ext/GEM_NAME/GEM_NAME.go\n\n/*\n#include \"example.h\"\n\n// TODO: Append this\nVALUE rb_example_sum(VALUE self, VALUE a, VALUE b);\n*/\nimport \"C\"\n```\n\n### 3. Call exported C functions with the Init function\n```go\n// ext/GEM_NAME/GEM_NAME.go\n\n//export Init_example\nfunc Init_example() {\n\trb_mExample := ruby.RbDefineModule(\"Example\")\n\n\t// TODO: Append this\n\truby.RbDefineSingletonMethod(rb_mExample, \"sum\", C.rb_example_sum, 2)\n}\n```\n\n### More examples\nSee also\n\n* [ruby/testdata/example/ext/example/example.go](ruby/testdata/example/ext/example/example.go)\n* [ruby/testdata/example/ext/example/tests.go](ruby/testdata/example/ext/example/tests.go)\n\n## Coverage\nWe provide auto-generated bindings for (almost) all CRuby functions available when including `ruby.h` :muscle:\n\nSee below for details.\n\n* [ruby/enum_ruby_3_3_generated.go](ruby/enum_ruby_3_3_generated.go)\n* [ruby/function_ruby_3_3_generated.go](ruby/function_ruby_3_3_generated.go)\n* [ruby/type_ruby_3_3_generated.go](ruby/type_ruby_3_3_generated.go)\n* [_tools/ruby_h_to_go/](_tools/ruby_h_to_go/)\n\n## Specification\n### Method name mapping from CRuby to Go\nCRuby methods are mapped to Go methods based on the following rules\n\n* No lowercase letters included (`/^[A-Z0-9_]+$/`)\n  * No changes\n  * e.g. `RB_NUM2UINT` (CRuby) -\u003e `ruby.RB_NUM2UINT` (Go)\n* Lowercase letters included\n  * Converted to CamelCase\n  * e.g. `rb_define_method` (CRuby) -\u003e `ruby.RbDefineMethod` (Go)\n\n### Limitation\nMost of the methods defined in `ruby.h` are automatically generated and defined in [ruby/function_ruby_3_3_generated.go](ruby/function_ruby_3_3_generated.go).\n\nHowever, some of the methods listed below are not supported.\n\n1. deprecated or internal methods\n    * See `function.exclude_name` in https://github.com/ruby-go-gem/ruby_header_parser/blob/main/config/default.yml\n2. Methods with variable-length arguments\n    * Because Go's variable-length arguments couldn't be passed directly to C.\n    * However, it is possible to execute functions with variable length arguments in CRuby from Go with a hack like `RbRaise` in [ruby/ruby_internal_error.go](ruby/ruby_internal_error.go)\n\n## Developing\n### Build\nRun `bundle exec rake build_all`.\n\nSee `bundle exec rake -T` for more tasks.\n\n### See `godoc` in local\n```bash\ngo install golang.org/x/tools/cmd/godoc@latest\ngodoc\n```\n\nopen http://localhost:6060/pkg/github.com/ruby-go-gem/go-gem-wrapper/ruby/\n\n### Release\n1. Run `bundle exec rake changelog`\n2. Add release note to [CHANGELOG.md](CHANGELOG.md)\n3. Update [_gem/lib/go_gem/version.rb](_gem/lib/go_gem/version.rb)\n4. Run `bundle exec rake release`\n\n## Original idea\n[Ruby meets Go - RubyKaigi 2015](https://rubykaigi.org/2015/presentations/mmasaki/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby-go-gem%2Fgo-gem-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruby-go-gem%2Fgo-gem-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruby-go-gem%2Fgo-gem-wrapper/lists"}