Helpers for compiling Go extensions for ruby
Add below.
spec.add_dependency "go_gem"See below for details.
create_go_makefile is an extension of create_makefile.
Add a task and hacks to build Go against the Makefile generated by create_makefile.
e.g.
# ext/GEM_NAME/extconf.rb
require "mkmf"
require "go_gem/mkmf" # Append this
# Use create_go_makefile instead of create_makefile
# create_makefile("example/example")
create_go_makefile("example/example")Provides rake tasks for go test with CRuby
# Rakefile
require "go_gem/rake_task"
GoGem::RakeTask.new("gem_name")Following tasks are generated
rake go:testrake go:testracerake go:fmtrake go:build_envs
# Rakefile
require "go_gem/rake_task"
GoGem::RakeTask.new("gem_name") do |t|
t.task_namespace = "go5"
t.go_bin_path = "/path/to/go"
t.go_test_args = "-mod=readonly"
t.target_dir = "/dir/to/go-mod/"
endFollowing tasks are generated
rake go5:testrake go5:testracerake go5:fmtrake go5:build_envs
# Rakefile
require "go_gem/rake_task"
go_task = GoGem::RakeTask.new("gem_name")
namespace :go do
desc "Run golangci-lint"
task :lint do
go_task.within_target_dir do
sh "which golangci-lint" do |ok, _|
raise "golangci-lint isn't installed. See. https://golangci-lint.run/welcome/install/" unless ok
end
sh GoGem::RakeTask.build_env_vars, "golangci-lint run"
end
end
endExample (Use golangci/golangci-lint-action)
jobs:
go-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- uses: ruby/setup-ruby@v1
- name: export CGO_CFLAGS for golangci-lint
run: bundle exec rake go:build_envs[CGO_CFLAGS] >> $GITHUB_ENV
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6task_namespace: task namespace (default::go)go_bin_path: path to go binary (default:"go")go_test_args: argument passed togo test(default:"-mod=readonly -count=1")target_dir: directory when executing go commands. (default:"ext/#{gem_name}")
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec 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.
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby-go-gem/go-gem-wrapper.
The gem is available as open source under the terms of the MIT License.