Skip to content

Commit 27e20ef

Browse files
committed
Pass ruby version build tag to go build and go test
1 parent 7b67323 commit 27e20ef

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

_gem/lib/go_gem/mkmf.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require_relative "util"
4+
35
module GoGem
46
# Helper module for creating Go Makefiles
57
module Mkmf
@@ -35,11 +37,13 @@ def $objs.empty?; false; end
3537

3638
current_dir = File.expand_path(".")
3739

40+
goflags = "-tags=#{GoGem::Util.ruby_minor_version_build_tag}"
41+
3842
File.open("Makefile", "a") do |f|
3943
f.write <<~MAKEFILE.gsub(/^ {8}/, "\t")
4044
$(DLLIB): Makefile $(srcdir)/*.go
4145
cd $(srcdir); \
42-
CGO_CFLAGS='$(INCFLAGS)' CGO_LDFLAGS='#{ldflags}' \
46+
CGO_CFLAGS='$(INCFLAGS)' CGO_LDFLAGS='#{ldflags}' GOFLAGS='#{goflags}' \
4347
go build -p 4 -buildmode=c-shared -o #{current_dir}/$(DLLIB)
4448
MAKEFILE
4549
end

_gem/lib/go_gem/rake_task.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require "rake"
44
require "rake/tasklib"
55

6+
require_relative "util"
7+
68
module GoGem
79
# Provides rake tasks for `go test` with CRuby
810
#
@@ -94,6 +96,8 @@ def initialize(gem_name)
9496
#
9597
# @return [Hash<String, String>]
9698
def self.build_env_vars
99+
goflags = "-tags=#{GoGem::Util.ruby_minor_version_build_tag}"
100+
97101
ldflags = "-L#{RbConfig::CONFIG["libdir"]} -l#{RbConfig::CONFIG["RUBY_SO_NAME"]}"
98102

99103
case `#{RbConfig::CONFIG["CC"]} --version` # rubocop:disable Lint/LiteralAsCondition
@@ -123,6 +127,7 @@ def self.build_env_vars
123127
ld_library_path = RbConfig::CONFIG["libdir"].to_s
124128

125129
{
130+
"GOFLAGS" => goflags,
126131
"CGO_CFLAGS" => cflags,
127132
"CGO_LDFLAGS" => ldflags,
128133
"LD_LIBRARY_PATH" => ld_library_path,

_gem/sig/go_gem/rake_task.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module GoGem
2828

2929
def initialize: (String gem_name) ?{ (RakeTask) -> void } -> void
3030

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 }
3232

3333
private
3434

0 commit comments

Comments
 (0)