Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ jobs:
- run: bundle update --jobs $(nproc) --retry 3
working-directory: testdata/example/

- name: export LD_LIBRARY_PATH
run: |
ruby -e "puts %Q(LD_LIBRARY_PATH=#{RbConfig::CONFIG['libdir']}:#{ENV['LD_LIBRARY_PATH']})" >> $GITHUB_ENV
echo LD_LIBRARY_PATH=${LD_LIBRARY_PATH}

- name: build and test (Go)
run: |
set -xe
Expand Down
26 changes: 20 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,42 @@ namespace :ruby do
end
end

# @return [Hash<String, String>]
def env_vars
ldflags = "-L#{RbConfig::CONFIG["libdir"]} -l#{RbConfig::CONFIG["RUBY_SO_NAME"]}"

case `#{RbConfig::CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition
when /Free Software Foundation/
ldflags = "-Wl,--unresolved-symbols=ignore-all"
ldflags << " -Wl,--unresolved-symbols=ignore-all"
when /clang/
ldflags = "-undefined dynamic_lookup"
ldflags << " -undefined dynamic_lookup"
end

cflags = "#{RbConfig::CONFIG["CFLAGS"]} -I#{RbConfig::CONFIG["rubyarchhdrdir"]} -I#{RbConfig::CONFIG["rubyhdrdir"]}"

# FIXME: Workaround for GitHub Actions
if ENV["GITHUB_ACTIONS"]
cflags.gsub!("-Wno-self-assign", "")
cflags.gsub!("-Wno-parentheses-equality", "")
cflags.gsub!("-Wno-constant-logical-operand", "")
cflags.gsub!("-Wsuggest-attribute=format", "")
cflags.gsub!("-Wold-style-definition", "")
cflags.gsub!("-Wsuggest-attribute=noreturn", "")
ldflags.gsub!("-Wl,--unresolved-symbols=ignore-all", "")
end

{
"CGO_CFLAGS" => "-I#{RbConfig::CONFIG["rubyarchhdrdir"]} -I#{RbConfig::CONFIG["rubyhdrdir"]}",
"CGO_LDFLAGS" => "'#{ldflags}'",
"CGO_CFLAGS" => cflags,
"CGO_LDFLAGS" => ldflags,
}
end

namespace :go do
# FIXME: This doesn't work when test file is exists...
desc "Run go test"
task :test do
sh env_vars, "go test -count=1 ${TEST_ARGS}"
end

# FIXME: This doesn't work when test file is exists...
desc "Run go test -race"
task :testrace do
sh env_vars, "go test -count=1 ${TEST_ARGS} -race"
Expand Down
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module github.com/sue445/go-gem-wrapper

go 1.23

require github.com/stretchr/testify v1.9.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
30 changes: 30 additions & 0 deletions wrapper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ruby_test

import (
"fmt"
"github.com/stretchr/testify/assert"
"github.com/sue445/go-gem-wrapper"
"testing"
)

func TestBool2Int(t *testing.T) {
tests := []struct {
arg bool
want int
}{
{
arg: true,
want: 1,
},
{
arg: false,
want: 0,
},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%v", tt.arg), func(t *testing.T) {
got := ruby.Bool2Int(tt.arg)
assert.Equal(t, tt.want, got)
})
}
}