Skip to content

Commit 83cdcb6

Browse files
committed
Embed ruby minor version as build tag
1 parent 8002e9a commit 83cdcb6

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

_tools/ruby_h_to_go/lib/ruby_h_to_go/go_util.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ def self.snake_to_camel(str)
1616
def self.generate_initial_go_file(go_file_path)
1717
return if File.exist?(go_file_path)
1818

19+
ruby_build_tag = ruby_minor_version_build_tag(RUBY_VERSION)
20+
1921
File.binwrite(go_file_path, <<~GO)
2022
// THE AUTOGENERATED LICENSE. ALL THE RIGHTS ARE RESERVED BY ROBOTS.
2123
2224
// WARNING: This file has automatically been generated
2325
// Code generated by ruby_h_to_go. DO NOT EDIT.
2426
27+
//go:build #{ruby_build_tag}
28+
2529
package ruby
2630
2731
/*
@@ -36,6 +40,12 @@ def self.generate_initial_go_file(go_file_path)
3640
GO
3741
end
3842

43+
# @param ruby_version [String]
44+
# @return [String]
45+
def self.ruby_minor_version_build_tag(ruby_version = RUBY_VERSION)
46+
"ruby_#{ruby_version.to_f.to_s.gsub(".", "_")}"
47+
end
48+
3949
C_TYPE_TO_GO_TYPE = {
4050
"RUBY_DATA_FUNC" => "unsafe.Pointer",
4151
"long long" => "Longlong",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe RubyHToGo::GoUtil do
4+
describe ".ruby_minor_version_build_tag" do
5+
subject { RubyHToGo::GoUtil.ruby_minor_version_build_tag(ruby_version) }
6+
7+
let(:ruby_version) { "3.4.1" }
8+
9+
it { should eq "ruby_3_4" }
10+
end
11+
end

0 commit comments

Comments
 (0)