go_gem 0.2.3 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cda178870c0c1d6b905e70e7f1c4c1d2f2479d0f304e5e6486e15c4a61db7d9c
4
- data.tar.gz: e13db335fd63705106c5ad9d2e7871771b332bf0237fb6b46374399b1b0da990
3
+ metadata.gz: 0b0aa853597fa94b01abc00c98cd1e743dda0d48c3909a56e24912608e38f659
4
+ data.tar.gz: 587c9a7cd18f75e599bf73488e8a84f65dfe851a35361e5f1f029a158bbf056e
5
5
  SHA512:
6
- metadata.gz: 41d4079f8ae8e399ddcfcdbe2bc1960e9b1907990227c745da304e80f87271bc810d737e90ac7e6b8d319812cdc0506732a040bda0cf2085159a8d50ee8923a1
7
- data.tar.gz: 4c71e84a1db2362a32abbc69f13806475af11f0c50caa7ecfea1d0c4dc2d052c2be952d029f8c66e818c924703efcdcf8c4f3047b4a899fd21c3711dee5f43f7
6
+ metadata.gz: 2164714d694ef237e8f41aa32121cef42a597ef86d251d5b47dcdae13741dd3fc1eab6c0278b8735c08e82b6bb49667145eb48785723bbc4dcb9cd219fb3d41b
7
+ data.tar.gz: c51924855aabdf873fcf78ba052014e89fb16e9792b9633a8699234d09dddd379e519f5f38a5efd524f9677e21f708fbdc7ec329a7de3dba66c4307af216639c
data/README.md CHANGED
@@ -33,6 +33,68 @@ require "go_gem/mkmf" # Append this
33
33
  create_go_makefile("example/example")
34
34
  ```
35
35
 
36
+ ### `GoGem::RakeTask`
37
+ Provides rake tasks for `go test` with CRuby
38
+
39
+ #### Example (Without config)
40
+ ```ruby
41
+ # Rakefile
42
+ require "go_gem/rake_task"
43
+
44
+ GoGem::RakeTask.new("gem_name")
45
+ ```
46
+
47
+ Following tasks are generated
48
+
49
+ * `rake go:test`
50
+ * `rake go:testrace`
51
+ * `rake go:fmt`
52
+
53
+ #### Example (With config)
54
+ ```ruby
55
+ # Rakefile
56
+ require "go_gem/rake_task"
57
+
58
+ GoGem::RakeTask.new("gem_name") do |t|
59
+ t.task_namespace = "go5"
60
+ t.go_bin_path = "/path/to/go"
61
+ t.go_test_args = "-mod=readonly"
62
+ t.target_dir = "/dir/to/go-mod/"
63
+ end
64
+ ```
65
+
66
+ Following tasks are generated
67
+
68
+ * `rake go5:test`
69
+ * `rake go5:testrace`
70
+ * `rake go5:fmt`
71
+
72
+ #### Example (Add additional tasks)
73
+ ```ruby
74
+ # Rakefile
75
+ require "go_gem/rake_task"
76
+
77
+ go_task = GoGem::RakeTask.new("gem_name")
78
+
79
+ namespace :go do
80
+ desc "Run golangci-lint"
81
+ task :lint do
82
+ go_task.within_target_dir do
83
+ sh "which golangci-lint" do |ok, _|
84
+ raise "golangci-lint isn't installed. See. https://golangci-lint.run/welcome/install/" unless ok
85
+ end
86
+ sh GoGem::RakeTask.build_env_vars, "golangci-lint run"
87
+ end
88
+ end
89
+ end
90
+ ```
91
+
92
+ #### Available configurations
93
+ * `task_namespace` : task namespace (default: `:go`)
94
+ * `go_bin_path` : path to go binary (default: `"go"`)
95
+ * `go_test_args` : argument passed to `go test` (default: `"-mod=readonly -count=1"`)
96
+ * `target_dir` : directory when executing go commands. (default: `"ext/#{gem_name}"`)
97
+
36
98
  ## Development
37
99
 
38
100
  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.
data/lib/go_gem/mkmf.rb CHANGED
@@ -26,7 +26,7 @@ module GoGem
26
26
 
27
27
  create_makefile(target, srcprefix)
28
28
 
29
- case `#{CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition
29
+ case `#{RbConfig::CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition
30
30
  when /Free Software Foundation/
31
31
  ldflags = "-Wl,--unresolved-symbols=ignore-all"
32
32
  when /clang/
@@ -0,0 +1,172 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake"
4
+ require "rake/tasklib"
5
+
6
+ module GoGem
7
+ # Provides rake tasks for `go test` with CRuby
8
+ #
9
+ # @example Without config
10
+ # # Rakefile
11
+ # require "go_gem/rake_task"
12
+ #
13
+ # GoGem::RakeTask.new("gem_name")
14
+ #
15
+ # @example With config
16
+ # # Rakefile
17
+ # require "go_gem/rake_task"
18
+ #
19
+ # GoGem::RakeTask.new("gem_name") do |t|
20
+ # t.task_namespace = "go5"
21
+ # t.go_bin_path = "/path/to/go"
22
+ # t.go_test_args = "-mod=readonly"
23
+ # t.target_dir = "/dir/to/go-mod/"
24
+ # end
25
+ #
26
+ # @example additional tasks
27
+ # # Rakefile
28
+ # require "go_gem/rake_task"
29
+ #
30
+ # t = GoGem::RakeTask.new("gem_name")
31
+ #
32
+ # namespace :go do
33
+ # desc "Run golangci-lint"
34
+ # task :lint do
35
+ # t.within_target_dir do
36
+ # sh "which golangci-lint" do |ok, _|
37
+ # raise "golangci-lint isn't installed. See. https://golangci-lint.run/welcome/install/" unless ok
38
+ # end
39
+ # sh GoGem::RakeTask.build_env_vars, "golangci-lint run"
40
+ # end
41
+ # end
42
+ # end
43
+ class RakeTask < ::Rake::TaskLib
44
+ DEFAULT_TASK_NAMESPACE = :go
45
+
46
+ DEFAULT_GO_BIN_PATH = "go"
47
+
48
+ DEFAULT_GO_TEST_ARGS = "-mod=readonly -count=1"
49
+
50
+ # @!attribute [r] gem_name
51
+ # @return [String]
52
+ attr_reader :gem_name
53
+
54
+ # @!attribute task_namespace
55
+ # @return [Symbol,String] task namespace (default: `:go`)
56
+ attr_accessor :task_namespace
57
+
58
+ # @!attribute go_bin_path
59
+ # @return [String] path to go binary (default: `"go"`)
60
+ attr_accessor :go_bin_path
61
+
62
+ # @!attribute go_test_args
63
+ # @return [String] argument passed to `go test` (default: `"-mod=readonly -count=1"`)
64
+ attr_accessor :go_test_args
65
+
66
+ # @!attribute cwd
67
+ # @return [String] directory when executing go commands. (default: `"ext/#{gem_name}"`)
68
+ attr_accessor :target_dir
69
+
70
+ # @param gem_name [String]
71
+ # @yield configuration of {RakeTask}
72
+ # @yieldparam t [RakeTask]
73
+ def initialize(gem_name)
74
+ super()
75
+
76
+ @gem_name = gem_name
77
+
78
+ @task_namespace = DEFAULT_TASK_NAMESPACE
79
+ @go_bin_path = DEFAULT_GO_BIN_PATH
80
+ @go_test_args = DEFAULT_GO_TEST_ARGS
81
+ @target_dir = ext_dir
82
+
83
+ yield(self) if block_given?
84
+
85
+ namespace(task_namespace) do
86
+ define_go_test_task
87
+ define_go_testrace_task
88
+ define_go_fmt_task
89
+ end
90
+ end
91
+
92
+ # Generate environment variables to build go programs in the Go gem
93
+ #
94
+ # @return [Hash<String, String>]
95
+ def self.build_env_vars
96
+ ldflags = "-L#{RbConfig::CONFIG["libdir"]} -l#{RbConfig::CONFIG["RUBY_SO_NAME"]}"
97
+
98
+ case `#{RbConfig::CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition
99
+ when /Free Software Foundation/
100
+ ldflags << " -Wl,--unresolved-symbols=ignore-all"
101
+ when /clang/
102
+ ldflags << " -undefined dynamic_lookup"
103
+ end
104
+
105
+ cflags = [
106
+ RbConfig::CONFIG["CFLAGS"],
107
+ "-I#{RbConfig::CONFIG["rubyarchhdrdir"]}",
108
+ "-I#{RbConfig::CONFIG["rubyhdrdir"]}",
109
+ ].join(" ")
110
+
111
+ # FIXME: Workaround for Ubuntu (GitHub Actions)
112
+ if RUBY_PLATFORM =~ /linux/i
113
+ cflags.gsub!("-Wno-self-assign", "")
114
+ cflags.gsub!("-Wno-parentheses-equality", "")
115
+ cflags.gsub!("-Wno-constant-logical-operand", "")
116
+ cflags.gsub!("-Wsuggest-attribute=format", "")
117
+ cflags.gsub!("-Wold-style-definition", "")
118
+ cflags.gsub!("-Wsuggest-attribute=noreturn", "")
119
+ ldflags.gsub!("-Wl,--unresolved-symbols=ignore-all", "")
120
+ end
121
+
122
+ ld_library_path = RbConfig::CONFIG["libdir"]
123
+
124
+ {
125
+ "CGO_CFLAGS" => cflags,
126
+ "CGO_LDFLAGS" => ldflags,
127
+ "LD_LIBRARY_PATH" => ld_library_path,
128
+ }
129
+ end
130
+
131
+ # @yield
132
+ def within_target_dir
133
+ Dir.chdir(target_dir) do # rubocop:disable Style/ExplicitBlockArgument
134
+ yield
135
+ end
136
+ end
137
+
138
+ # @return [String]
139
+ def ext_dir
140
+ File.join("ext", gem_name)
141
+ end
142
+
143
+ private
144
+
145
+ def define_go_test_task
146
+ desc "Run #{go_bin_path} test"
147
+ task(:test) do
148
+ within_target_dir do
149
+ sh RakeTask.build_env_vars, "#{go_bin_path} test #{go_test_args} ./..."
150
+ end
151
+ end
152
+ end
153
+
154
+ def define_go_testrace_task
155
+ desc "Run #{go_bin_path} test -race"
156
+ task(:testrace) do
157
+ within_target_dir do
158
+ sh RakeTask.build_env_vars, "#{go_bin_path} test #{go_test_args} -race ./..."
159
+ end
160
+ end
161
+ end
162
+
163
+ def define_go_fmt_task
164
+ desc "Run #{go_bin_path} fmt"
165
+ task(:fmt) do
166
+ within_target_dir do
167
+ sh "#{go_bin_path} fmt ./..."
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GoGem
4
- VERSION = "0.2.3"
4
+ VERSION = "0.3.0"
5
5
  end
data/sig/go_gem/mkmf.rbs CHANGED
@@ -1,5 +1,7 @@
1
1
  module GoGem
2
2
  module Mkmf
3
- def create_go_makefile: (String, String? nil) -> void
3
+ $objs: Array[untyped]
4
+
5
+ def create_go_makefile: (String target, String? srcprefix) -> void
4
6
  end
5
7
  end
@@ -0,0 +1,45 @@
1
+ module GoGem
2
+ class RakeTask < ::Rake::TaskLib
3
+ @gem_name: String
4
+
5
+ @task_namespace: Symbol | String
6
+
7
+ @go_bin_path: String
8
+
9
+ @go_test_args: String
10
+
11
+ @target_dir: String
12
+
13
+ DEFAULT_TASK_NAMESPACE: Symbol
14
+
15
+ DEFAULT_GO_BIN_PATH: String
16
+
17
+ DEFAULT_GO_TEST_ARGS: String
18
+
19
+ attr_reader gem_name: String
20
+
21
+ attr_accessor task_namespace: Symbol | String
22
+
23
+ attr_accessor go_bin_path: String
24
+
25
+ attr_accessor go_test_args: String
26
+
27
+ attr_accessor target_dir: String
28
+
29
+ def initialize: (String gem_name) ?{ (RakeTask) -> void } -> void
30
+
31
+ def self.build_env_vars: () -> { "CGO_CFLAGS" => String, "CGO_LDFLAGS" => String, "LD_LIBRARY_PATH" => String }
32
+
33
+ private
34
+
35
+ def define_go_test_task: () -> void
36
+
37
+ def define_go_testrace_task: () -> void
38
+
39
+ def define_go_fmt_task: () -> void
40
+
41
+ def within_target_dir: () { () -> void } -> void
42
+
43
+ def ext_dir: () -> String
44
+ end
45
+ end
data/sig/go_gem.rbs CHANGED
@@ -1,4 +1,8 @@
1
1
  module GoGem
2
2
  VERSION: String
3
+
4
+ class Error < StandardError
5
+ end
6
+
3
7
  # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: go_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-02 00:00:00.000000000 Z
11
+ date: 2024-11-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Helpers for compiling Go extensions for ruby
14
14
  email:
@@ -23,15 +23,17 @@ files:
23
23
  - Rakefile
24
24
  - lib/go_gem.rb
25
25
  - lib/go_gem/mkmf.rb
26
+ - lib/go_gem/rake_task.rb
26
27
  - lib/go_gem/version.rb
27
28
  - sig/go_gem.rbs
28
29
  - sig/go_gem/mkmf.rbs
30
+ - sig/go_gem/rake_task.rbs
29
31
  homepage: https://github.com/ruby-go-gem/go-gem-wrapper
30
32
  licenses:
31
33
  - MIT
32
34
  metadata:
33
35
  homepage_uri: https://github.com/ruby-go-gem/go-gem-wrapper
34
- source_code_uri: https://github.com/ruby-go-gem/go-gem-wrapper
36
+ source_code_uri: https://github.com/ruby-go-gem/go-gem-wrapper/tree/main/_gem
35
37
  changelog_uri: https://github.com/ruby-go-gem/go-gem-wrapper/blob/main/CHANGELOG.md
36
38
  documentation_uri: https://ruby-go-gem.github.io/go-gem-wrapper/
37
39
  rubygems_mfa_required: 'true'
@@ -50,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
52
  - !ruby/object:Gem::Version
51
53
  version: '0'
52
54
  requirements: []
53
- rubygems_version: 3.5.16
55
+ rubygems_version: 3.5.22
54
56
  signing_key:
55
57
  specification_version: 4
56
58
  summary: Helpers for compiling Go extensions for ruby