go_gem 0.6.0 → 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 +7 -9
- data/lib/go_gem/rake_task.rb +7 -47
- data/lib/go_gem/util.rb +47 -0
- data/lib/go_gem/version.rb +1 -1
- data/sig/go_gem/mkmf.rbs +1 -1
- data/sig/go_gem/rake_task.rbs +0 -6
- data/sig/go_gem/util.rbs +6 -0
- metadata +2 -2
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
@@ -9,6 +9,7 @@ module GoGem
|
|
9
9
|
#
|
10
10
|
# @param target [String]
|
11
11
|
# @param srcprefix [String,nil]
|
12
|
+
# @param go_build_args [String,nil] Arguments passed to `go build`
|
12
13
|
#
|
13
14
|
# @example
|
14
15
|
# require "mkmf"
|
@@ -17,7 +18,10 @@ module GoGem
|
|
17
18
|
# # Use create_go_makefile instead of create_makefile
|
18
19
|
# # create_makefile("example/example")
|
19
20
|
# create_go_makefile("example/example")
|
20
|
-
|
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)
|
21
25
|
find_executable("go")
|
22
26
|
|
23
27
|
# rubocop:disable Style/GlobalVars
|
@@ -28,13 +32,7 @@ module GoGem
|
|
28
32
|
|
29
33
|
create_makefile(target, srcprefix)
|
30
34
|
|
31
|
-
|
32
|
-
when /Free Software Foundation/
|
33
|
-
ldflags = "-Wl,--unresolved-symbols=ignore-all"
|
34
|
-
when /clang/
|
35
|
-
ldflags = "-undefined dynamic_lookup"
|
36
|
-
end
|
37
|
-
|
35
|
+
ldflags = GoGem::Util.generate_ldflags
|
38
36
|
current_dir = File.expand_path(".")
|
39
37
|
|
40
38
|
goflags = "-tags=#{GoGem::Util.ruby_minor_version_build_tag}"
|
@@ -44,7 +42,7 @@ module GoGem
|
|
44
42
|
$(DLLIB): Makefile $(srcdir)/*.go
|
45
43
|
cd $(srcdir); \
|
46
44
|
CGO_CFLAGS='$(INCFLAGS)' CGO_LDFLAGS='#{ldflags}' GOFLAGS='#{goflags}' \
|
47
|
-
go build -p 4 -buildmode=c-shared -o #{current_dir}/$(DLLIB)
|
45
|
+
go build -p 4 -buildmode=c-shared -o #{current_dir}/$(DLLIB) #{go_build_args}
|
48
46
|
MAKEFILE
|
49
47
|
end
|
50
48
|
end
|
data/lib/go_gem/rake_task.rb
CHANGED
@@ -38,11 +38,13 @@ module GoGem
|
|
38
38
|
# sh "which golangci-lint" do |ok, _|
|
39
39
|
# raise "golangci-lint isn't installed. See. https://golangci-lint.run/welcome/install/" unless ok
|
40
40
|
# end
|
41
|
-
#
|
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}"
|
42
44
|
# end
|
43
45
|
# end
|
44
46
|
# end
|
45
|
-
class RakeTask < ::Rake::TaskLib
|
47
|
+
class RakeTask < ::Rake::TaskLib
|
46
48
|
DEFAULT_TASK_NAMESPACE = :go
|
47
49
|
|
48
50
|
DEFAULT_GO_BIN_PATH = "go"
|
@@ -97,61 +99,19 @@ module GoGem
|
|
97
99
|
#
|
98
100
|
# @return [Hash<String, String>]
|
99
101
|
def self.build_env_vars
|
100
|
-
ldflags = generate_ldflags
|
101
|
-
cflags = generate_cflags
|
102
|
-
|
103
|
-
# FIXME: Workaround for Ubuntu (GitHub Actions)
|
104
|
-
if RUBY_PLATFORM =~ /linux/i
|
105
|
-
cflags.gsub!("-Wno-self-assign", "")
|
106
|
-
cflags.gsub!("-Wno-parentheses-equality", "")
|
107
|
-
cflags.gsub!("-Wno-constant-logical-operand", "")
|
108
|
-
cflags.gsub!("-Wsuggest-attribute=format", "")
|
109
|
-
cflags.gsub!("-Wold-style-definition", "")
|
110
|
-
cflags.gsub!("-Wsuggest-attribute=noreturn", "")
|
111
|
-
ldflags.gsub!("-Wl,--unresolved-symbols=ignore-all", "")
|
112
|
-
end
|
102
|
+
ldflags = GoGem::Util.generate_ldflags
|
103
|
+
cflags = GoGem::Util.generate_cflags
|
113
104
|
|
114
105
|
ld_library_path = RbConfig::CONFIG["libdir"].to_s
|
115
106
|
|
116
107
|
{
|
117
|
-
"GOFLAGS" => generate_goflags,
|
108
|
+
"GOFLAGS" => GoGem::Util.generate_goflags,
|
118
109
|
"CGO_CFLAGS" => cflags,
|
119
110
|
"CGO_LDFLAGS" => ldflags,
|
120
111
|
"LD_LIBRARY_PATH" => ld_library_path,
|
121
112
|
}
|
122
113
|
end
|
123
114
|
|
124
|
-
# @return [String]
|
125
|
-
def self.generate_goflags
|
126
|
-
"-tags=#{GoGem::Util.ruby_minor_version_build_tag}"
|
127
|
-
end
|
128
|
-
private_class_method :generate_goflags
|
129
|
-
|
130
|
-
# @return [String]
|
131
|
-
def self.generate_ldflags
|
132
|
-
ldflags = "-L#{RbConfig::CONFIG["libdir"]} -l#{RbConfig::CONFIG["RUBY_SO_NAME"]}"
|
133
|
-
|
134
|
-
case `#{RbConfig::CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition
|
135
|
-
when /Free Software Foundation/
|
136
|
-
ldflags << " -Wl,--unresolved-symbols=ignore-all"
|
137
|
-
when /clang/
|
138
|
-
ldflags << " -undefined dynamic_lookup"
|
139
|
-
end
|
140
|
-
|
141
|
-
ldflags
|
142
|
-
end
|
143
|
-
private_class_method :generate_ldflags
|
144
|
-
|
145
|
-
# @return [String]
|
146
|
-
def self.generate_cflags
|
147
|
-
[
|
148
|
-
RbConfig::CONFIG["CFLAGS"],
|
149
|
-
"-I#{RbConfig::CONFIG["rubyarchhdrdir"]}",
|
150
|
-
"-I#{RbConfig::CONFIG["rubyhdrdir"]}",
|
151
|
-
].join(" ")
|
152
|
-
end
|
153
|
-
private_class_method :generate_cflags
|
154
|
-
|
155
115
|
# @yield
|
156
116
|
def within_target_dir
|
157
117
|
Dir.chdir(target_dir) do # rubocop:disable Style/ExplicitBlockArgument
|
data/lib/go_gem/util.rb
CHANGED
@@ -14,5 +14,52 @@ module GoGem
|
|
14
14
|
def self.ruby_minor_version_build_tag(ruby_version = RUBY_VERSION)
|
15
15
|
"ruby_#{ruby_version.to_f.to_s.gsub(".", "_")}"
|
16
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
|
17
64
|
end
|
18
65
|
end
|
data/lib/go_gem/version.rb
CHANGED
data/sig/go_gem/mkmf.rbs
CHANGED
data/sig/go_gem/rake_task.rbs
CHANGED
@@ -30,12 +30,6 @@ module GoGem
|
|
30
30
|
|
31
31
|
def self.build_env_vars: () -> { "GOFLAGS" => String, "CGO_CFLAGS" => String, "CGO_LDFLAGS" => String, "LD_LIBRARY_PATH" => String }
|
32
32
|
|
33
|
-
def self.generate_goflags: () -> String
|
34
|
-
|
35
|
-
def self.generate_ldflags: () -> String
|
36
|
-
|
37
|
-
def self.generate_cflags: () -> String
|
38
|
-
|
39
33
|
private
|
40
34
|
|
41
35
|
def define_go_test_task: () -> void
|
data/sig/go_gem/util.rbs
CHANGED
metadata
CHANGED
@@ -1,13 +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
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-01-
|
10
|
+
date: 2025-01-24 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: Helpers for compiling Go extensions for ruby
|
13
13
|
email:
|