go_gem 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -1
- data/lib/go_gem/mkmf.rb +12 -10
- data/lib/go_gem/rake_task.rb +16 -26
- data/lib/go_gem/util.rb +65 -0
- data/lib/go_gem/version.rb +1 -1
- data/sig/go_gem/mkmf.rbs +1 -1
- data/sig/go_gem/rake_task.rbs +3 -1
- data/sig/go_gem/util.rbs +11 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9391de7a479373991e4d34ffc16b48c12b0b939f7738d3534d35d46d0e8f031a
|
4
|
+
data.tar.gz: 9de4ce2876dfd5e63c2858502ab63f268c3dda3c0da535701f4cfc739b3f1cf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5bbf69c9727d91331d4ac4e316a3cfa9462fcd180b965789da3f7e57c1d61e2cfad60d46e2db49be1335ddf88c83c18b931afe4cf0ce42a17ad208476f6ccc6
|
7
|
+
data.tar.gz: c78e49338aabb2cdd1490a8f258e5e39db8c1a75bb63397f280ecad88deacc39338bdddcb134d8c619c76a997abaa216cb4d6e5921133e5305a076f9a8e0f772
|
data/README.md
CHANGED
@@ -85,7 +85,9 @@ namespace :go do
|
|
85
85
|
sh "which golangci-lint" do |ok, _|
|
86
86
|
raise "golangci-lint isn't installed. See. https://golangci-lint.run/welcome/install/" unless ok
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
|
+
build_tag = GoGem::Util.ruby_minor_version_build_tag
|
90
|
+
sh GoGem::RakeTask.build_env_vars, "golangci-lint run --build-tags #{build_tag}"
|
89
91
|
end
|
90
92
|
end
|
91
93
|
end
|
@@ -101,12 +103,28 @@ jobs:
|
|
101
103
|
- uses: actions/checkout@v4
|
102
104
|
- uses: actions/setup-go@v5
|
103
105
|
- uses: ruby/setup-ruby@v1
|
106
|
+
with:
|
107
|
+
bundler-cache: false
|
108
|
+
|
109
|
+
# FIXME: setup-go installs cache in `vendor/` and setup-ruby installs cache in `vendor/bundle/`
|
110
|
+
# If we use the cache in setup-go and setup-ruby at the same time, this doesn't work well because they use the same directory.
|
111
|
+
# Therefore, the installation location needs to be changed from the setup-ruby default.
|
112
|
+
- name: bundle install
|
113
|
+
run: |
|
114
|
+
set -xe
|
115
|
+
bundle config --local path ruby-vendor/bundle
|
116
|
+
bundle install --jobs 4
|
104
117
|
|
105
118
|
- name: export CGO_CFLAGS for golangci-lint
|
106
119
|
run: bundle exec rake go:build_envs[CGO_CFLAGS] >> $GITHUB_ENV
|
107
120
|
|
121
|
+
- name: export BUILD_TAG for golangci-lint
|
122
|
+
run: echo "BUILD_TAG=$(bundle exec rake go:build_tag)" >> $GITHUB_ENV
|
123
|
+
|
108
124
|
- name: Run golangci-lint
|
109
125
|
uses: golangci/golangci-lint-action@v6
|
126
|
+
with:
|
127
|
+
args: --build-tags ${{ env.BUILD_TAG }}
|
110
128
|
```
|
111
129
|
|
112
130
|
#### Available configurations
|
data/lib/go_gem/mkmf.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "util"
|
4
|
+
|
3
5
|
module GoGem
|
4
6
|
# Helper module for creating Go Makefiles
|
5
7
|
module Mkmf
|
@@ -7,6 +9,7 @@ module GoGem
|
|
7
9
|
#
|
8
10
|
# @param target [String]
|
9
11
|
# @param srcprefix [String,nil]
|
12
|
+
# @param go_build_args [String,nil] Arguments passed to `go build`
|
10
13
|
#
|
11
14
|
# @example
|
12
15
|
# require "mkmf"
|
@@ -15,7 +18,10 @@ module GoGem
|
|
15
18
|
# # Use create_go_makefile instead of create_makefile
|
16
19
|
# # create_makefile("example/example")
|
17
20
|
# create_go_makefile("example/example")
|
18
|
-
|
21
|
+
#
|
22
|
+
# @example Pass debug flags to `go build`
|
23
|
+
# create_go_makefile("example/example", go_build_args: "-gcflags='all=-N -l'")
|
24
|
+
def create_go_makefile(target, srcprefix: nil, go_build_args: nil)
|
19
25
|
find_executable("go")
|
20
26
|
|
21
27
|
# rubocop:disable Style/GlobalVars
|
@@ -26,21 +32,17 @@ module GoGem
|
|
26
32
|
|
27
33
|
create_makefile(target, srcprefix)
|
28
34
|
|
29
|
-
|
30
|
-
when /Free Software Foundation/
|
31
|
-
ldflags = "-Wl,--unresolved-symbols=ignore-all"
|
32
|
-
when /clang/
|
33
|
-
ldflags = "-undefined dynamic_lookup"
|
34
|
-
end
|
35
|
-
|
35
|
+
ldflags = GoGem::Util.generate_ldflags
|
36
36
|
current_dir = File.expand_path(".")
|
37
37
|
|
38
|
+
goflags = "-tags=#{GoGem::Util.ruby_minor_version_build_tag}"
|
39
|
+
|
38
40
|
File.open("Makefile", "a") do |f|
|
39
41
|
f.write <<~MAKEFILE.gsub(/^ {8}/, "\t")
|
40
42
|
$(DLLIB): Makefile $(srcdir)/*.go
|
41
43
|
cd $(srcdir); \
|
42
|
-
CGO_CFLAGS='$(INCFLAGS)' CGO_LDFLAGS='#{ldflags}' \
|
43
|
-
go build -p 4 -buildmode=c-shared -o #{current_dir}/$(DLLIB)
|
44
|
+
CGO_CFLAGS='$(INCFLAGS)' CGO_LDFLAGS='#{ldflags}' GOFLAGS='#{goflags}' \
|
45
|
+
go build -p 4 -buildmode=c-shared -o #{current_dir}/$(DLLIB) #{go_build_args}
|
44
46
|
MAKEFILE
|
45
47
|
end
|
46
48
|
end
|
data/lib/go_gem/rake_task.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require "rake"
|
4
4
|
require "rake/tasklib"
|
5
5
|
|
6
|
+
require_relative "util"
|
7
|
+
|
6
8
|
module GoGem
|
7
9
|
# Provides rake tasks for `go test` with CRuby
|
8
10
|
#
|
@@ -36,7 +38,9 @@ module GoGem
|
|
36
38
|
# sh "which golangci-lint" do |ok, _|
|
37
39
|
# raise "golangci-lint isn't installed. See. https://golangci-lint.run/welcome/install/" unless ok
|
38
40
|
# end
|
39
|
-
#
|
41
|
+
#
|
42
|
+
# build_tag = GoGem::Util.ruby_minor_version_build_tag
|
43
|
+
# sh GoGem::RakeTask.build_env_vars, "golangci-lint run --build-tags #{build_tag}"
|
40
44
|
# end
|
41
45
|
# end
|
42
46
|
# end
|
@@ -87,6 +91,7 @@ module GoGem
|
|
87
91
|
define_go_testrace_task
|
88
92
|
define_go_fmt_task
|
89
93
|
define_go_build_envs_task
|
94
|
+
define_go_build_tag_task
|
90
95
|
end
|
91
96
|
end
|
92
97
|
|
@@ -94,35 +99,13 @@ module GoGem
|
|
94
99
|
#
|
95
100
|
# @return [Hash<String, String>]
|
96
101
|
def self.build_env_vars
|
97
|
-
ldflags =
|
98
|
-
|
99
|
-
case `#{RbConfig::CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition
|
100
|
-
when /Free Software Foundation/
|
101
|
-
ldflags << " -Wl,--unresolved-symbols=ignore-all"
|
102
|
-
when /clang/
|
103
|
-
ldflags << " -undefined dynamic_lookup"
|
104
|
-
end
|
105
|
-
|
106
|
-
cflags = [
|
107
|
-
RbConfig::CONFIG["CFLAGS"],
|
108
|
-
"-I#{RbConfig::CONFIG["rubyarchhdrdir"]}",
|
109
|
-
"-I#{RbConfig::CONFIG["rubyhdrdir"]}",
|
110
|
-
].join(" ")
|
111
|
-
|
112
|
-
# FIXME: Workaround for Ubuntu (GitHub Actions)
|
113
|
-
if RUBY_PLATFORM =~ /linux/i
|
114
|
-
cflags.gsub!("-Wno-self-assign", "")
|
115
|
-
cflags.gsub!("-Wno-parentheses-equality", "")
|
116
|
-
cflags.gsub!("-Wno-constant-logical-operand", "")
|
117
|
-
cflags.gsub!("-Wsuggest-attribute=format", "")
|
118
|
-
cflags.gsub!("-Wold-style-definition", "")
|
119
|
-
cflags.gsub!("-Wsuggest-attribute=noreturn", "")
|
120
|
-
ldflags.gsub!("-Wl,--unresolved-symbols=ignore-all", "")
|
121
|
-
end
|
102
|
+
ldflags = GoGem::Util.generate_ldflags
|
103
|
+
cflags = GoGem::Util.generate_cflags
|
122
104
|
|
123
105
|
ld_library_path = RbConfig::CONFIG["libdir"].to_s
|
124
106
|
|
125
107
|
{
|
108
|
+
"GOFLAGS" => GoGem::Util.generate_goflags,
|
126
109
|
"CGO_CFLAGS" => cflags,
|
127
110
|
"CGO_LDFLAGS" => ldflags,
|
128
111
|
"LD_LIBRARY_PATH" => ld_library_path,
|
@@ -183,5 +166,12 @@ module GoGem
|
|
183
166
|
end
|
184
167
|
end
|
185
168
|
end
|
169
|
+
|
170
|
+
def define_go_build_tag_task
|
171
|
+
desc "Print build tag"
|
172
|
+
task(:build_tag) do
|
173
|
+
puts GoGem::Util.ruby_minor_version_build_tag
|
174
|
+
end
|
175
|
+
end
|
186
176
|
end
|
187
177
|
end
|
data/lib/go_gem/util.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GoGem
|
4
|
+
# Common utility methods for {GoGem::Mkmf} and {GoGem::RakeTask}
|
5
|
+
module Util
|
6
|
+
# Return ruby version build tag for `go build` and `go test`
|
7
|
+
#
|
8
|
+
# @param ruby_version [String]
|
9
|
+
# @return [String]
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# GoGem::Util.ruby_minor_version_build_tag("3.4.1")
|
13
|
+
# #=> "ruby_3_4"
|
14
|
+
def self.ruby_minor_version_build_tag(ruby_version = RUBY_VERSION)
|
15
|
+
"ruby_#{ruby_version.to_f.to_s.gsub(".", "_")}"
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [String]
|
19
|
+
def self.generate_ldflags
|
20
|
+
ldflags = "-L#{RbConfig::CONFIG["libdir"]} -l#{RbConfig::CONFIG["RUBY_SO_NAME"]}"
|
21
|
+
|
22
|
+
case `#{RbConfig::CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition
|
23
|
+
when /Free Software Foundation/
|
24
|
+
ldflags << " -Wl,--unresolved-symbols=ignore-all"
|
25
|
+
when /clang/
|
26
|
+
ldflags << " -undefined dynamic_lookup"
|
27
|
+
end
|
28
|
+
|
29
|
+
# FIXME: Workaround for Ubuntu (GitHub Actions)
|
30
|
+
ldflags.gsub!("-Wl,--unresolved-symbols=ignore-all", "") if RUBY_PLATFORM =~ /linux/i
|
31
|
+
|
32
|
+
ldflags.strip
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return [String]
|
36
|
+
def self.generate_cflags
|
37
|
+
cflags =
|
38
|
+
[
|
39
|
+
RbConfig::CONFIG["CFLAGS"],
|
40
|
+
"-I#{RbConfig::CONFIG["rubyarchhdrdir"]}",
|
41
|
+
"-I#{RbConfig::CONFIG["rubyhdrdir"]}",
|
42
|
+
].join(" ")
|
43
|
+
|
44
|
+
# FIXME: Workaround for Ubuntu (GitHub Actions)
|
45
|
+
if RUBY_PLATFORM =~ /linux/i
|
46
|
+
cflags.gsub!("-Wno-self-assign", "")
|
47
|
+
cflags.gsub!("-Wno-parentheses-equality", "")
|
48
|
+
cflags.gsub!("-Wno-constant-logical-operand", "")
|
49
|
+
cflags.gsub!("-Wsuggest-attribute=format", "")
|
50
|
+
cflags.gsub!("-Wold-style-definition", "")
|
51
|
+
cflags.gsub!("-Wsuggest-attribute=noreturn", "")
|
52
|
+
end
|
53
|
+
|
54
|
+
# FIXME: Workaround for Alpine
|
55
|
+
cflags.gsub!("-Wpointer-arith", "") if RUBY_PLATFORM =~ /linux-musl/i
|
56
|
+
|
57
|
+
cflags.strip
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [String]
|
61
|
+
def self.generate_goflags
|
62
|
+
"-tags=#{ruby_minor_version_build_tag}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/go_gem/version.rb
CHANGED
data/sig/go_gem/mkmf.rbs
CHANGED
data/sig/go_gem/rake_task.rbs
CHANGED
@@ -28,7 +28,7 @@ module GoGem
|
|
28
28
|
|
29
29
|
def initialize: (String gem_name) ?{ (RakeTask) -> void } -> void
|
30
30
|
|
31
|
-
def self.build_env_vars: () -> { "CGO_CFLAGS" => String, "CGO_LDFLAGS" => String, "LD_LIBRARY_PATH" => String }
|
31
|
+
def self.build_env_vars: () -> { "GOFLAGS" => String, "CGO_CFLAGS" => String, "CGO_LDFLAGS" => String, "LD_LIBRARY_PATH" => String }
|
32
32
|
|
33
33
|
private
|
34
34
|
|
@@ -40,6 +40,8 @@ module GoGem
|
|
40
40
|
|
41
41
|
def define_go_build_envs_task: () -> void
|
42
42
|
|
43
|
+
def define_go_build_tag_task: () -> void
|
44
|
+
|
43
45
|
def within_target_dir: () { () -> void } -> void
|
44
46
|
|
45
47
|
def ext_dir: () -> String
|
data/sig/go_gem/util.rbs
ADDED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: go_gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sue445
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-24 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: Helpers for compiling Go extensions for ruby
|
14
13
|
email:
|
@@ -24,10 +23,12 @@ files:
|
|
24
23
|
- lib/go_gem.rb
|
25
24
|
- lib/go_gem/mkmf.rb
|
26
25
|
- lib/go_gem/rake_task.rb
|
26
|
+
- lib/go_gem/util.rb
|
27
27
|
- lib/go_gem/version.rb
|
28
28
|
- sig/go_gem.rbs
|
29
29
|
- sig/go_gem/mkmf.rbs
|
30
30
|
- sig/go_gem/rake_task.rbs
|
31
|
+
- sig/go_gem/util.rbs
|
31
32
|
homepage: https://github.com/ruby-go-gem/go-gem-wrapper
|
32
33
|
licenses:
|
33
34
|
- MIT
|
@@ -37,7 +38,6 @@ metadata:
|
|
37
38
|
changelog_uri: https://github.com/ruby-go-gem/go-gem-wrapper/blob/main/CHANGELOG.md
|
38
39
|
documentation_uri: https://ruby-go-gem.github.io/go-gem-wrapper/
|
39
40
|
rubygems_mfa_required: 'true'
|
40
|
-
post_install_message:
|
41
41
|
rdoc_options: []
|
42
42
|
require_paths:
|
43
43
|
- lib
|
@@ -46,14 +46,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
46
|
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: 3.3.0
|
49
|
+
- - "<"
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 3.5.0
|
49
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
53
|
requirements:
|
51
54
|
- - ">="
|
52
55
|
- !ruby/object:Gem::Version
|
53
56
|
version: '0'
|
54
57
|
requirements: []
|
55
|
-
rubygems_version: 3.
|
56
|
-
signing_key:
|
58
|
+
rubygems_version: 3.6.2
|
57
59
|
specification_version: 4
|
58
60
|
summary: Helpers for compiling Go extensions for ruby
|
59
61
|
test_files: []
|