Skip to content

Commit fd0877b

Browse files
authored
Merge pull request #533 from simplificator/ruby-3-1-3-2
Support Ruby 3.1 and 3.2
2 parents 23ed1e4 + 69a6dbd commit fd0877b

File tree

9 files changed

+143
-88
lines changed

9 files changed

+143
-88
lines changed

.circleci/config.yml

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,47 @@ jobs:
3939
docker exec cimg_ruby bash -c './test/bin/setup_tinytds_db.sh'
4040
4141
- run:
42-
name: compile openssl library
42+
name: bundle install gems
4343
command: |
44-
docker exec cimg_ruby bash -c 'sudo -E ./test/bin/install-openssl.sh'
44+
docker exec cimg_ruby bash -c 'bundle install'
4545
4646
- run:
47-
name: compile freetds library
47+
name: Write used versions into file
4848
command: |
49-
docker exec cimg_ruby bash -c 'sudo -E ./test/bin/install-freetds.sh'
49+
docker exec cimg_ruby bash -c 'bundle exec rake ports:version_file'
50+
51+
- restore_cache:
52+
name: restore ports cache
53+
keys:
54+
- ports-<< parameters.ruby_version >>-{{ checksum ".ports_versions" }}
55+
- ports-<< parameters.ruby_version >>-
5056

5157
- run:
52-
name: bundle install gems
58+
name: compile ports
5359
command: |
54-
docker exec cimg_ruby bash -c 'bundle install'
60+
docker exec cimg_ruby bash -c 'bundle exec rake ports'
5561
5662
- run:
5763
name: build gem
5864
command: |
5965
docker exec cimg_ruby bash -c 'bundle exec rake build'
6066
67+
- run:
68+
name: Fix permissions on ports directory
69+
command: |
70+
docker exec cimg_ruby bash -c 'sudo chown -R $(id -u):$(id -g) ports'
71+
6172
- run:
6273
name: test gem
6374
command: |
6475
docker exec cimg_ruby bash -c 'bundle exec rake test'
6576
77+
- save_cache:
78+
name: save ports cache
79+
paths:
80+
- ./ports
81+
key: ports-<< parameters.ruby_version >>-{{ checksum ".ports_versions" }}
82+
6683
- store_test_results:
6784
path: test/reports
6885

@@ -197,53 +214,49 @@ jobs:
197214
path: test/reports
198215

199216
cross_compile_gem:
200-
machine:
201-
image: ubuntu-2004:current
217+
parameters:
218+
platform:
219+
description: "Platform to compile the gem resources"
220+
type: string
221+
222+
docker:
223+
- image: "ghcr.io/rake-compiler/rake-compiler-dock-image:1.3.0-mri-<< parameters.platform >>"
202224

203225
steps:
204-
- ruby/install:
205-
version: '2.7'
206226
- checkout
207-
- restore_cache:
208-
name: restore gem cache
209-
keys:
210-
- v1-bundle-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }}
211-
- v1-bundle-{{ .Branch }}-
212-
- v1-bundle-
213227

214228
- run:
215229
name: bundle install gems
216230
command: |
217-
bundle install --path vendor/bundle
218-
219-
- save_cache:
220-
name: save gem cache
221-
paths:
222-
- ./vendor/bundle
223-
key: v1-bundle-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }}
231+
bundle install
224232
225233
- run:
226234
name: Write used versions for ports into file
227235
command: |
228-
bundle exec rake ports:version_file
236+
rake ports:version_file[<< parameters.platform >>]
229237
230238
- restore_cache:
231239
name: restore ports cache
232240
keys:
233-
- ports-{{ checksum ".ports_versions" }}
234-
- ports-
241+
- ports-win-{{ checksum ".ports_versions" }}
242+
- ports-win-
235243

236244
- run:
237-
name: Build gems
245+
name: Build gem
238246
command: |
239-
bundle exec rake gem
240-
bundle exec rake gem:native
247+
rake gem:for_platform[<< parameters.platform >>]
241248
242249
- run:
243250
name: Move gems into separate directory before caching
244251
command: |
245-
mkdir -p artifacts/gems
246-
mv pkg/*.gem artifacts/gems
252+
mkdir -p artifacts-<< parameters.platform >>/gems
253+
mv pkg/*.gem artifacts-<< parameters.platform >>/gems
254+
255+
- run:
256+
name: Remove non-native gem to avoid conflict in workspace
257+
command: |
258+
gemVersion=$(cat VERSION | tr -d "[:space:]")
259+
rm -rf artifacts-<< parameters.platform >>/gems/tiny_tds-$gemVersion.gem
247260
248261
- store_artifacts:
249262
path: artifacts/gems
@@ -252,18 +265,24 @@ jobs:
252265
name: save ports cache
253266
paths:
254267
- ./ports
255-
key: ports-{{ checksum ".ports_versions" }}
268+
key: ports-win-{{ checksum ".ports_versions" }}
256269

257270
- persist_to_workspace:
258271
name: save gems into workspace
259-
root: artifacts
272+
root: artifacts-<< parameters.platform >>
260273
paths:
261274
- gems
262275

263276
workflows:
264277
test_supported_ruby_versions:
265278
jobs:
266-
- cross_compile_gem
279+
- cross_compile_gem:
280+
matrix:
281+
parameters:
282+
platform:
283+
- "x86-mingw32"
284+
- "x64-mingw32"
285+
- "x64-mingw-ucrt"
267286
- test_windows:
268287
requires:
269288
- cross_compile_gem
@@ -275,5 +294,7 @@ workflows:
275294
- '2.6'
276295
- '2.7'
277296
- '3.0'
297+
- '3.1'
298+
- '3.2'
278299
- test_linux:
279300
matrix: *ruby_versions

Rakefile

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,33 @@ require 'rake/extensiontask'
66
require_relative './ext/tiny_tds/extconsts'
77

88
SPEC = Gem::Specification.load(File.expand_path('../tiny_tds.gemspec', __FILE__))
9+
10+
ruby_cc_ucrt_versions = "3.2.0:3.1.0".freeze
11+
ruby_cc_mingw32_versions = "3.0.0:2.7.0:2.6.0:2.5.0:2.4.0".freeze
12+
913
GEM_PLATFORM_HOSTS = {
10-
'x86-mingw32' => 'i686-w64-mingw32',
11-
'x64-mingw32' => 'x86_64-w64-mingw32'
14+
'x86-mingw32' => {
15+
host: 'i686-w64-mingw32',
16+
ruby_versions: ruby_cc_mingw32_versions
17+
},
18+
'x64-mingw32' => {
19+
host: 'x86_64-w64-mingw32',
20+
ruby_versions: ruby_cc_mingw32_versions
21+
},
22+
'x64-mingw-ucrt' => {
23+
host: 'x86_64-w64-mingw32',
24+
ruby_versions: ruby_cc_ucrt_versions
25+
},
1226
}
13-
RUBY_CC_VERSION="3.0.0:2.7.0:2.6.0:2.5.0:2.4.0".freeze
1427

1528
# Add our project specific files to clean for a rebuild
1629
CLEAN.include FileList["{ext,lib}/**/*.{so,#{RbConfig::CONFIG['DLEXT']},o}"],
17-
FileList["exe/*"]
30+
FileList["exe/*"]
1831

1932
# Clobber all our temp files and ports files including .install files
2033
# and archives
2134
CLOBBER.include FileList["tmp/**/*"],
22-
FileList["ports/**/*"].exclude(%r{^ports/archives})
35+
FileList["ports/**/*"].exclude(%r{^ports/archives})
2336

2437
Dir['tasks/*.rake'].sort.each { |f| load f }
2538

@@ -33,15 +46,11 @@ Rake::ExtensionTask.new('tiny_tds', SPEC) do |ext|
3346
# The fat binary gem doesn't depend on the freetds package, since it bundles the library.
3447
spec.metadata.delete('msys2_mingw_dependencies')
3548

36-
platform_host_map = GEM_PLATFORM_HOSTS
37-
gemplat = spec.platform.to_s
38-
host = platform_host_map[gemplat]
39-
4049
# We don't need the sources in a fat binary gem
4150
spec.files = spec.files.reject { |f| f =~ %r{^ports\/archives/} }
4251

4352
# Make sure to include the ports binaries and libraries
44-
spec.files += FileList["ports/#{host}/**/**/{bin,lib}/*"].exclude do |f|
53+
spec.files += FileList["ports/#{spec.platform.to_s}/**/**/{bin,lib}/*"].exclude do |f|
4554
File.directory? f
4655
end
4756

ext/tiny_tds/extconf.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ def do_help
2121
do_help if arg_config('--help')
2222

2323
# Make sure to check the ports path for the configured host
24-
host = RbConfig::CONFIG['host']
24+
architecture = RbConfig::CONFIG['arch']
25+
architecture = "x86-mingw32" if architecture == "i386-mingw32"
26+
2527
project_dir = File.expand_path("../../..", __FILE__)
26-
freetds_ports_dir = File.join(project_dir, 'ports', host, 'freetds', FREETDS_VERSION)
28+
freetds_ports_dir = File.join(project_dir, 'ports', architecture, 'freetds', FREETDS_VERSION)
2729
freetds_ports_dir = File.expand_path(freetds_ports_dir)
2830

2931
# Add all the special path searching from the original tiny_tds build

lib/tiny_tds/gem.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ def ports_lib_paths
2020
end
2121

2222
def ports_host
23-
h = RbConfig::CONFIG['host']
24-
25-
# Our fat binary builds with a i686-w64-mingw32 toolchain
26-
# but ruby for windows x32-mingw32 reports i686-pc-mingw32
27-
# so correct the host here
28-
h.gsub('i686-pc-mingw32', 'i686-w64-mingw32')
23+
RbConfig::CONFIG["arch"]
2924
end
3025
end
3126
end

tasks/native_gem.rake

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@ task 'gem:native' => ['ports:cross'] do
55
require 'rake_compiler_dock'
66

77
# make sure to install our bundle
8-
sh "bundle package --all" # Avoid repeated downloads of gems by using gem files from the host.
8+
sh "bundle package --all" # Avoid repeated downloads of gems by using gem files from the host.
99

10-
GEM_PLATFORM_HOSTS.keys.each do |plat|
11-
RakeCompilerDock.sh "bundle --local && RUBY_CC_VERSION=#{RUBY_CC_VERSION} rake native:#{plat} gem", platform: plat
10+
GEM_PLATFORM_HOSTS.each do |plat, meta|
11+
RakeCompilerDock.sh "bundle --local && RUBY_CC_VERSION=#{meta[:ruby_versions]} rake native:#{plat} gem", platform: plat
1212
end
1313
end
14+
15+
# assumes you are in a container provided by Rake compiler
16+
# if not, use the task above
17+
task 'gem:for_platform', [:gem_platform] do |_task, args|
18+
args.with_defaults(gem_platform: RbConfig::CONFIG["arch"])
19+
20+
sh "bundle install"
21+
Rake::Task["ports:compile"].invoke(GEM_PLATFORM_HOSTS[args.gem_platform][:host], args.gem_platform)
22+
sh "RUBY_CC_VERSION=#{GEM_PLATFORM_HOSTS[args.gem_platform][:ruby_versions]} rake native:#{args.gem_platform} gem"
23+
end

tasks/ports.rake

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,36 @@ namespace :ports do
1414
}
1515

1616
directory "ports"
17-
CLEAN.include "ports/*mingw32*"
17+
CLEAN.include "ports/*mingw*"
1818
CLEAN.include "ports/*.installed"
1919

20-
task :openssl, [:host] do |task, args|
21-
args.with_defaults(host: RbConfig::CONFIG['host'])
20+
task :openssl, [:host, :gem_platform] do |_task, args|
21+
args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
2222

2323
libraries_to_compile[:openssl].files = [OPENSSL_SOURCE_URI]
2424
libraries_to_compile[:openssl].host = args.host
25+
libraries_to_compile[:openssl].gem_platform = args.gem_platform
26+
2527
libraries_to_compile[:openssl].cook
2628
libraries_to_compile[:openssl].activate
2729
end
2830

29-
task :libiconv, [:host] do |task, args|
30-
args.with_defaults(host: RbConfig::CONFIG['host'])
31+
task :libiconv, [:host, :gem_platform] do |_task, args|
32+
args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
3133

3234
libraries_to_compile[:libiconv].files = [ICONV_SOURCE_URI]
3335
libraries_to_compile[:libiconv].host = args.host
36+
libraries_to_compile[:libiconv].gem_platform = args.gem_platform
3437
libraries_to_compile[:libiconv].cook
3538
libraries_to_compile[:libiconv].activate
3639
end
3740

38-
task :freetds, [:host] do |task, args|
39-
args.with_defaults(host: RbConfig::CONFIG['host'])
41+
task :freetds, [:host, :gem_platform] do |_task, args|
42+
args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
4043

4144
libraries_to_compile[:freetds].files = [FREETDS_SOURCE_URI]
4245
libraries_to_compile[:freetds].host = args.host
46+
libraries_to_compile[:freetds].gem_platform = args.gem_platform
4347

4448
if libraries_to_compile[:openssl]
4549
# freetds doesn't have an option that will provide an rpath
@@ -59,13 +63,13 @@ namespace :ports do
5963
libraries_to_compile[:freetds].activate
6064
end
6165

62-
task :compile, [:host] do |task, args|
63-
args.with_defaults(host: RbConfig::CONFIG['host'])
66+
task :compile, [:host, :gem_platform] do |_task, args|
67+
args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
6468

65-
puts "Compiling ports for #{args.host}..."
69+
puts "Compiling ports for #{args.host} (Ruby platform #{args.gem_platform}) ..."
6670

6771
libraries_to_compile.keys.each do |lib|
68-
Rake::Task["ports:#{lib}"].invoke(args.host)
72+
Rake::Task["ports:#{lib}"].invoke(args.host, args.gem_platform)
6973
end
7074
end
7175

@@ -74,22 +78,26 @@ namespace :ports do
7478
require 'rake_compiler_dock'
7579

7680
# build the ports for all our cross compile hosts
77-
GEM_PLATFORM_HOSTS.each do |gem_platform, host|
81+
GEM_PLATFORM_HOSTS.each do |gem_platform, meta|
7882
# make sure to install our bundle
7983
build = ['bundle']
80-
build << "rake ports:compile[#{host}] MAKE='make -j`nproc`'"
84+
build << "RUBY_CC_VERSION=#{meta[:ruby_versions]} rake ports:compile[#{meta[:host]},#{gem_platform}] MAKE='make -j`nproc`'"
8185
RakeCompilerDock.sh build.join(' && '), platform: gem_platform
8286
end
8387
end
8488

8589
desc "Notes the actual versions for the compiled ports into a file"
86-
task "version_file" do
90+
task "version_file", [:gem_platform] do |_task, args|
91+
args.with_defaults(gem_platform: RbConfig::CONFIG["arch"])
92+
8793
ports_version = {}
8894

8995
libraries_to_compile.each do |library, library_recipe|
9096
ports_version[library] = library_recipe.version
9197
end
9298

99+
ports_version[:platform] = args.gem_platform
100+
93101
File.open(".ports_versions", "w") do |f|
94102
f.write ports_version
95103
end

0 commit comments

Comments
 (0)