go_gem 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf04032b5fd467ed3123d922c9ad7978e577601552bf46a2fe4bde8b0b464caf
4
- data.tar.gz: dd5a7b4c2742f4d3a8b19871729c89ae59ceb4035d7a573476f34a9178406b4d
3
+ metadata.gz: de781c3ea978d43846ab114c957f973d1273a385b4a2cda8b4ab8bcae31e7b61
4
+ data.tar.gz: ff9e4ec5ee199bcc5aeabeec13426caa2db9cf2d593bb5fdca44f164daed6f2f
5
5
  SHA512:
6
- metadata.gz: 66a47a395e84b2b241974b77da353834f8f344982b2f85ab9ec2a7c2ddb67b29242b3ecc9235f36188be82a575733b3d608b16e367adb74e03476c77d929f27c
7
- data.tar.gz: 3db32329bcbba23583fca335ae00b0fa78b4dcbab64262afba18e09fd495af47e0eda7c5c16cf3abc7cdd2fca67441fbebb777003ab3c116d83541a96203c481
6
+ metadata.gz: 55fe501bd31919fe173a8ed9dbb7998a51da0098679e15f3d1ad2da120c62b78d80dc91139feb9056f949d08e49ed0bcd5ef1e217dd6d7e52297baa9039b9871
7
+ data.tar.gz: 82d8f84fb59e73fd7e555446fc02121e516fb5a376478a2484174bff7f2e3cdb60e7d5f461432783126fef30130c7b7e6e9081cbe6460957e87de0b1bf8b8cdd
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
@@ -35,11 +37,13 @@ module GoGem
35
37
 
36
38
  current_dir = File.expand_path(".")
37
39
 
40
+ goflags = "-tags=#{GoGem::Util.ruby_minor_version_build_tag}"
41
+
38
42
  File.open("Makefile", "a") do |f|
39
43
  f.write <<~MAKEFILE.gsub(/^ {8}/, "\t")
40
44
  $(DLLIB): Makefile $(srcdir)/*.go
41
45
  cd $(srcdir); \
42
- CGO_CFLAGS='$(INCFLAGS)' CGO_LDFLAGS='#{ldflags}' \
46
+ CGO_CFLAGS='$(INCFLAGS)' CGO_LDFLAGS='#{ldflags}' GOFLAGS='#{goflags}' \
43
47
  go build -p 4 -buildmode=c-shared -o #{current_dir}/$(DLLIB)
44
48
  MAKEFILE
45
49
  end
@@ -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
  #
@@ -40,7 +42,7 @@ module GoGem
40
42
  # end
41
43
  # end
42
44
  # end
43
- class RakeTask < ::Rake::TaskLib
45
+ class RakeTask < ::Rake::TaskLib # rubocop:disable Metrics/ClassLength
44
46
  DEFAULT_TASK_NAMESPACE = :go
45
47
 
46
48
  DEFAULT_GO_BIN_PATH = "go"
@@ -87,6 +89,7 @@ module GoGem
87
89
  define_go_testrace_task
88
90
  define_go_fmt_task
89
91
  define_go_build_envs_task
92
+ define_go_build_tag_task
90
93
  end
91
94
  end
92
95
 
@@ -94,20 +97,8 @@ module GoGem
94
97
  #
95
98
  # @return [Hash<String, String>]
96
99
  def self.build_env_vars
97
- ldflags = "-L#{RbConfig::CONFIG["libdir"]} -l#{RbConfig::CONFIG["RUBY_SO_NAME"]}"
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(" ")
100
+ ldflags = generate_ldflags
101
+ cflags = generate_cflags
111
102
 
112
103
  # FIXME: Workaround for Ubuntu (GitHub Actions)
113
104
  if RUBY_PLATFORM =~ /linux/i
@@ -123,12 +114,44 @@ module GoGem
123
114
  ld_library_path = RbConfig::CONFIG["libdir"].to_s
124
115
 
125
116
  {
117
+ "GOFLAGS" => generate_goflags,
126
118
  "CGO_CFLAGS" => cflags,
127
119
  "CGO_LDFLAGS" => ldflags,
128
120
  "LD_LIBRARY_PATH" => ld_library_path,
129
121
  }
130
122
  end
131
123
 
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
+
132
155
  # @yield
133
156
  def within_target_dir
134
157
  Dir.chdir(target_dir) do # rubocop:disable Style/ExplicitBlockArgument
@@ -183,5 +206,12 @@ module GoGem
183
206
  end
184
207
  end
185
208
  end
209
+
210
+ def define_go_build_tag_task
211
+ desc "Print build tag"
212
+ task(:build_tag) do
213
+ puts GoGem::Util.ruby_minor_version_build_tag
214
+ end
215
+ end
186
216
  end
187
217
  end
@@ -0,0 +1,18 @@
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
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GoGem
4
- VERSION = "0.5.1"
4
+ VERSION = "0.6.0"
5
5
  end
@@ -28,7 +28,13 @@ 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
+
33
+ def self.generate_goflags: () -> String
34
+
35
+ def self.generate_ldflags: () -> String
36
+
37
+ def self.generate_cflags: () -> String
32
38
 
33
39
  private
34
40
 
@@ -40,6 +46,8 @@ module GoGem
40
46
 
41
47
  def define_go_build_envs_task: () -> void
42
48
 
49
+ def define_go_build_tag_task: () -> void
50
+
43
51
  def within_target_dir: () { () -> void } -> void
44
52
 
45
53
  def ext_dir: () -> String
@@ -0,0 +1,5 @@
1
+ module GoGem
2
+ module Util
3
+ def self.ruby_minor_version_build_tag: (?String ruby_version) -> String
4
+ end
5
+ end
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.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-12-15 00:00:00.000000000 Z
10
+ date: 2025-01-06 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.5.22
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: []