@@ -96,22 +96,8 @@ def initialize(gem_name)
9696 #
9797 # @return [Hash<String, String>]
9898 def self . build_env_vars
99- goflags = "-tags=#{ GoGem ::Util . ruby_minor_version_build_tag } "
100-
101- ldflags = "-L#{ RbConfig ::CONFIG [ "libdir" ] } -l#{ RbConfig ::CONFIG [ "RUBY_SO_NAME" ] } "
102-
103- case `#{ RbConfig ::CONFIG [ "CC" ] } --version` # rubocop:disable Lint/LiteralAsCondition
104- when /Free Software Foundation/
105- ldflags << " -Wl,--unresolved-symbols=ignore-all"
106- when /clang/
107- ldflags << " -undefined dynamic_lookup"
108- end
109-
110- cflags = [
111- RbConfig ::CONFIG [ "CFLAGS" ] ,
112- "-I#{ RbConfig ::CONFIG [ "rubyarchhdrdir" ] } " ,
113- "-I#{ RbConfig ::CONFIG [ "rubyhdrdir" ] } " ,
114- ] . join ( " " )
99+ ldflags = generate_ldflags
100+ cflags = generate_cflags
115101
116102 # FIXME: Workaround for Ubuntu (GitHub Actions)
117103 if RUBY_PLATFORM =~ /linux/i
@@ -127,13 +113,44 @@ def self.build_env_vars
127113 ld_library_path = RbConfig ::CONFIG [ "libdir" ] . to_s
128114
129115 {
130- "GOFLAGS" => goflags ,
116+ "GOFLAGS" => generate_goflags ,
131117 "CGO_CFLAGS" => cflags ,
132118 "CGO_LDFLAGS" => ldflags ,
133119 "LD_LIBRARY_PATH" => ld_library_path ,
134120 }
135121 end
136122
123+ # @return [String]
124+ def self . generate_goflags
125+ "-tags=#{ GoGem ::Util . ruby_minor_version_build_tag } "
126+ end
127+ private_class_method :generate_goflags
128+
129+ # @return [String]
130+ def self . generate_ldflags
131+ ldflags = "-L#{ RbConfig ::CONFIG [ "libdir" ] } -l#{ RbConfig ::CONFIG [ "RUBY_SO_NAME" ] } "
132+
133+ case `#{ RbConfig ::CONFIG [ "CC" ] } --version` # rubocop:disable Lint/LiteralAsCondition
134+ when /Free Software Foundation/
135+ ldflags << " -Wl,--unresolved-symbols=ignore-all"
136+ when /clang/
137+ ldflags << " -undefined dynamic_lookup"
138+ end
139+
140+ ldflags
141+ end
142+ private_class_method :generate_ldflags
143+
144+ # @return [String]
145+ def self . generate_cflags
146+ [
147+ RbConfig ::CONFIG [ "CFLAGS" ] ,
148+ "-I#{ RbConfig ::CONFIG [ "rubyarchhdrdir" ] } " ,
149+ "-I#{ RbConfig ::CONFIG [ "rubyhdrdir" ] } " ,
150+ ] . join ( " " )
151+ end
152+ private_class_method :generate_cflags
153+
137154 # @yield
138155 def within_target_dir
139156 Dir . chdir ( target_dir ) do # rubocop:disable Style/ExplicitBlockArgument
0 commit comments