Skip to content

Commit 9d12f78

Browse files
committed
Restore cross-compiled code from final gem file
1 parent 741d1c5 commit 9d12f78

File tree

3 files changed

+69
-45
lines changed

3 files changed

+69
-45
lines changed

.circleci/config.yml

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,29 @@ jobs:
141141
key: v1-bundle-<< parameters.ruby_version >>-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }}
142142

143143
- restore_cache:
144-
name: restore cross-compiled code
144+
name: restore cross-compiled gems
145145
keys:
146-
- compiled-<< pipeline.git.revision >>
146+
- gems-<< pipeline.git.revision >>
147147

148148
- run:
149-
name: restore cross-compiled code
149+
name: restore cross-compiled code from gem
150150
command: |
151151
$Env:PATH = "C:\\Ruby<< parameters.ruby_version >>-x64\\bin;$Env:PATH"
152+
$rubyArchitecture = (ruby -e 'puts RUBY_PLATFORM').Trim()
153+
$gemVersion = (Get-Content VERSION).Trim()
152154
153-
$rubyArchitecture = (ruby -e 'puts RUBY_PLATFORM').Trim()
154-
$source = "C:\home\circleci\project\tmp\$rubyArchitecture\stage\lib\tiny_tds"
155-
$destination = ".\lib\tiny_tds"
155+
# Install appropriate gem
156+
# The project on Windows is checked out at C:/Users/circleci.PACKER-633B1A5A/project
157+
# However, since the cache with the gems was created on Linux, it uses a different path
158+
gem install --local --install-dir=./tmp "C:\home\circleci\project\gems\tiny_tds-$gemVersion-$rubyArchitecture.gem"
159+
160+
# Restore precompiled code
161+
$source = (Resolve-Path ".\tmp\gems\tiny_tds-$gemVersion-$rubyArchitecture\lib\tiny_tds").Path
162+
$destination = (Resolve-Path ".\lib\tiny_tds").Path
156163
Get-ChildItem $source -Recurse -Exclude "*.rb" | Copy-Item -Destination {Join-Path $destination $_.FullName.Substring($source.length)}
164+
165+
# Restore ports
166+
Copy-Item -Path ".\tmp\gems\tiny_tds-$gemVersion-$rubyArchitecture\ports" -Destination "." -Recurse
157167
158168
- restore_cache:
159169
name: restore mssql installation file
@@ -176,16 +186,6 @@ jobs:
176186
choco install toxiproxy-server --version=2.5.0 -y
177187
Start-Process toxiproxy-server
178188
179-
- restore_cache:
180-
name: restore ports cache
181-
keys:
182-
- ports-libiconv115-openssl111s-freetds1124
183-
184-
- run:
185-
name: copy ports cache into project
186-
command: |
187-
Move-Item C:\home\circleci\project\ports .
188-
189189
- run:
190190
name: test gem
191191
command: |
@@ -223,18 +223,26 @@ jobs:
223223
- ./vendor/bundle
224224
key: v1-bundle-{{ .Branch }}-{{ checksum "tiny_tds.gemspec" }}
225225

226+
- run:
227+
name: Write used versions for ports into file
228+
command: |
229+
bundle exec rake ports:version_file
230+
226231
- restore_cache:
227232
name: restore ports cache
228233
keys:
229-
- ports-libiconv115-openssl111s-freetds1124
234+
- ports-{{ checksum ".ports_versions" }}
235+
- ports-
230236

231237
- run:
232238
name: Build gems
233239
command: |
234240
bundle exec rake gem
235241
bundle exec rake gem:native
236242
237-
# Move gem files to a separate directory, as CircleCI artifacts don't support wildcards for paths
243+
- run:
244+
name: Move gems into separate directory before caching
245+
command: |
238246
mkdir gems
239247
mv pkg/*.gem gems
240248
@@ -245,13 +253,13 @@ jobs:
245253
name: save ports cache
246254
paths:
247255
- ./ports
248-
key: ports-libiconv115-openssl111s-freetds1124
256+
key: ports-{{ checksum ".ports_versions" }}
249257

250258
- save_cache:
251-
name: save cross-compiled-code
259+
name: save gems into cache
252260
paths:
253-
- ./tmp
254-
key: compiled-<< pipeline.git.revision >>
261+
- ./gems
262+
key: gems-<< pipeline.git.revision >>
255263

256264
workflows:
257265
test_supported_ruby_versions:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ misc
1919
/ports/*
2020
!/ports/patches/
2121
test/reports
22+
.ports_versions

tasks/ports.rake

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ require_relative 'ports/freetds'
77
require_relative '../ext/tiny_tds/extconsts'
88

99
namespace :ports do
10-
openssl = Ports::Openssl.new(OPENSSL_VERSION)
11-
libiconv = Ports::Libiconv.new(ICONV_VERSION)
12-
freetds = Ports::Freetds.new(FREETDS_VERSION)
10+
libraries_to_compile = {
11+
freetds: Ports::Freetds.new(FREETDS_VERSION),
12+
libiconv: Ports::Libiconv.new(ICONV_VERSION),
13+
openssl: Ports::Openssl.new(OPENSSL_VERSION)
14+
}
1315

1416
directory "ports"
1517
CLEAN.include "ports/*mingw32*"
@@ -18,51 +20,51 @@ namespace :ports do
1820
task :openssl, [:host] do |task, args|
1921
args.with_defaults(host: RbConfig::CONFIG['host'])
2022

21-
openssl.files = [OPENSSL_SOURCE_URI]
22-
openssl.host = args.host
23-
openssl.cook
24-
openssl.activate
23+
libraries_to_compile[:openssl].files = [OPENSSL_SOURCE_URI]
24+
libraries_to_compile[:openssl].host = args.host
25+
libraries_to_compile[:openssl].cook
26+
libraries_to_compile[:openssl].activate
2527
end
2628

2729
task :libiconv, [:host] do |task, args|
2830
args.with_defaults(host: RbConfig::CONFIG['host'])
2931

30-
libiconv.files = [ICONV_SOURCE_URI]
31-
libiconv.host = args.host
32-
libiconv.cook
33-
libiconv.activate
32+
libraries_to_compile[:libiconv].files = [ICONV_SOURCE_URI]
33+
libraries_to_compile[:libiconv].host = args.host
34+
libraries_to_compile[:libiconv].cook
35+
libraries_to_compile[:libiconv].activate
3436
end
3537

3638
task :freetds, [:host] do |task, args|
3739
args.with_defaults(host: RbConfig::CONFIG['host'])
3840

39-
freetds.files = [FREETDS_SOURCE_URI]
40-
freetds.host = args.host
41+
libraries_to_compile[:freetds].files = [FREETDS_SOURCE_URI]
42+
libraries_to_compile[:freetds].host = args.host
4143

42-
if openssl
44+
if libraries_to_compile[:openssl]
4345
# freetds doesn't have an option that will provide an rpath
4446
# so we do it manually
45-
ENV['OPENSSL_CFLAGS'] = "-Wl,-rpath -Wl,#{openssl.path}/lib"
47+
ENV['OPENSSL_CFLAGS'] = "-Wl,-rpath -Wl,#{libraries_to_compile[:openssl].path}/lib"
4648
# Add the pkgconfig file with MSYS2'ish path, to prefer our ports build
4749
# over MSYS2 system OpenSSL.
48-
ENV['PKG_CONFIG_PATH'] = "#{openssl.path.gsub(/^(\w):/i){"/"+$1.downcase}}/lib/pkgconfig:#{ENV['PKG_CONFIG_PATH']}"
49-
freetds.configure_options << "--with-openssl=#{openssl.path}"
50+
ENV['PKG_CONFIG_PATH'] = "#{libraries_to_compile[:openssl].path.gsub(/^(\w):/i) { "/" + $1.downcase }}/lib/pkgconfig:#{ENV['PKG_CONFIG_PATH']}"
51+
libraries_to_compile[:freetds].configure_options << "--with-openssl=#{libraries_to_compile[:openssl].path}"
5052
end
5153

52-
if libiconv
53-
freetds.configure_options << "--with-libiconv-prefix=#{libiconv.path}"
54+
if libraries_to_compile[:libiconv]
55+
libraries_to_compile[:freetds].configure_options << "--with-libiconv-prefix=#{libraries_to_compile[:libiconv].path}"
5456
end
5557

56-
freetds.cook
57-
freetds.activate
58+
libraries_to_compile[:freetds].cook
59+
libraries_to_compile[:freetds].activate
5860
end
5961

60-
task :compile, [:host] do |task,args|
62+
task :compile, [:host] do |task, args|
6163
args.with_defaults(host: RbConfig::CONFIG['host'])
6264

6365
puts "Compiling ports for #{args.host}..."
6466

65-
['openssl','libiconv','freetds'].each do |lib|
67+
libraries_to_compile.keys.each do |lib|
6668
Rake::Task["ports:#{lib}"].invoke(args.host)
6769
end
6870
end
@@ -79,6 +81,19 @@ namespace :ports do
7981
RakeCompilerDock.sh build.join(' && '), platform: gem_platform
8082
end
8183
end
84+
85+
desc "Notes the actual versions for the compiled ports into a file"
86+
task "version_file" do
87+
ports_version = {}
88+
89+
libraries_to_compile.each do |library, library_recipe|
90+
ports_version[library] = library_recipe.version
91+
end
92+
93+
File.open(".ports_versions", "w") do |f|
94+
f.write ports_version
95+
end
96+
end
8297
end
8398

8499
desc 'Build ports and activate libraries for the current architecture.'

0 commit comments

Comments
 (0)