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")
# Pass debug flags to `go build`
create_go_makefile("example/example", go_build_args: "-gcflags='all=-N -l'")
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:test
rake go:testrace
rake go:fmt
rake 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/"
end
Following tasks are generated
rake go5:test
rake go5:testrace
rake go5:fmt
rake 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
build_tag = GoGem::Util.ruby_minor_version_build_tag
sh GoGem::RakeTask.build_env_vars, "golangci-lint run --build-tags #{build_tag} --modules-download-mode=readonly"
end
end
end
Example (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
with:
bundler-cache: true
- name: export CGO_CFLAGS for golangci-lint
run: bundle exec rake go:build_envs[CGO_CFLAGS] >> $GITHUB_ENV
- name: export BUILD_TAG for golangci-lint
run: echo "BUILD_TAG=$(bundle exec rake go:build_tag)" >> $GITHUB_ENV
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
args: --build-tags ${{ env.BUILD_TAG }} --modules-download-mode=readonly
task_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.