Skip to content

Commit 593d298

Browse files
authored
Updates for MSYS2 Upgrade to OpenSSL 3 (#5)
* Use MSYS2 OpenSSL 3, add FORCE_UPDATE * Update README.md to show additional '-3.0' packages * Add FORCE_UPDATE to CI
1 parent 8043fd8 commit 593d298

File tree

6 files changed

+94
-18
lines changed

6 files changed

+94
-18
lines changed

.github/workflows/mswin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
mswin:
1313
name: >-
1414
mswin vcpkg tools
15+
env:
16+
FORCE_UPDATE: true
1517
runs-on: windows-2022
1618
strategy:
1719
fail-fast: false

.github/workflows/windows-build-tools.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
msys2:
1313
name: >-
1414
msys2 tools
15+
# env:
16+
# FORCE_UPDATE: true
1517
runs-on: windows-2022
1618
strategy:
1719
fail-fast: false
@@ -43,12 +45,15 @@ jobs:
4345
gcc:
4446
name: >-
4547
${{ matrix.gcc }} gcc
48+
env:
49+
FORCE_UPDATE: true
4650
runs-on: windows-2022
4751
strategy:
4852
fail-fast: false
4953
matrix:
5054
include:
5155
- { gcc: mingw64 , ruby: mingw }
56+
- { gcc: mingw64-3.0, ruby: mingw }
5257
- { gcc: ucrt64 , ruby: ucrt }
5358
- { gcc: ucrt64-3.0 , ruby: 3.2 }
5459
steps:

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Below summarizes the default MSYS2 installations on Actions Windows images:
2121

2222
### Notes
2323

24-
Four package files are stored in a GitHub release, and are used by
24+
Six package files are stored in a GitHub release, and are used by
2525
[ruby/setup-ruby](https://github.com/ruby/setup-ruby). They are:
2626

2727
* **`msys2.7z`** The base msys2 installation on Actions Windows images contains a minimal
@@ -30,14 +30,23 @@ updated files to the 7z. All Ruby Windows releases from version 2.4 and later u
3030
tools.
3131

3232
* **`mingw64.7z`** This contains the mingw64 gcc chain and any packages needed to build
33-
Ruby. Normal Ruby Windows releases from version 2.4 thru 3.0 use these tools.
33+
Ruby. This has OpenSSL 1.1.1 installed, as of 19-Jan-2023, 1.1.1.s. Normal Ruby Windows
34+
releases from version 2.4 thru 3.0 use these tools.
35+
36+
* **`mingw64-3.0.7z`** This contains the mingw64 gcc chain and any packages needed to build
37+
Ruby. The MSYS2 OpenSSL 3.0.z package is installed. The mingw Ruby master build is the
38+
only build that uses this.
3439

3540
* **`ucrt64.7z`** This contains the ucrt64 gcc chain and any packages needed to build
36-
Ruby. Normal Ruby Windows releases from version 3.1 and later use these tools.
41+
Ruby. This has OpenSSL 1.1.1 installed, as of 19-Jan-2023, 1.1.1.s. Ruby version 3.1 is
42+
the only release that uses this.
3743

38-
* **`mswin.7z`** This contains files needed to compile Windows Ruby mswin builds. It contains
39-
libffi, libyaml, openssl, readline, and zlib, built with the Microsoft vcpkg system.
44+
* **`ucrt64-3.0.7z`** This contains the ucrt64 gcc chain and any packages needed to build
45+
Ruby. The MSYS2 OpenSSL 3.0.z package is installed. Ruby 3.2, head, & ucrt builds use this.
4046

47+
* **`mswin.7z`** This contains files needed to compile Windows Ruby mswin builds. It contains
48+
libffi, libyaml, openssl, readline, and zlib, built with the Microsoft vcpkg system. This
49+
contains OpenSSL 3.0.z.
4150

4251
The code installs the packages with [ruby/setup-ruby](https://github.com/ruby/setup-ruby),
4352
then updates the MSYS2 and vcpkg packages. If any packages have been updated, it creates

create_gcc_pkg.rb

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66
# Windows runner's hard drive, smaller zip files speed up the installation.
77
# Hence, many of the 'doc' related files in the 'share' folder are removed.
88

9+
# OpenSSL - There are comments and code lines that are commented out. The archives
10+
# may need to have one version of OpenSSL fully installed, and if that version
11+
# differs from the current MSYS2 version, the OpenSSL files needed to run (not build)
12+
# the MSYS2 utilities need to remain. They should be from the most recent version
13+
# that MSYS2 uses.
14+
#
15+
# This means there are files that are not associated with an installed package,
16+
# so the code gets more complex, and some code is just needed for the transition.
17+
918
require 'fileutils'
1019
require_relative 'common'
1120

@@ -19,20 +28,30 @@ class << self
1928
SYNC = 'var/lib/pacman/sync'
2029
LOCAL = 'var/lib/pacman/local'
2130

31+
PKG_NAME = ARGV[0].downcase
32+
2233
PKG_DIR, PKG_PRE =
23-
case ARGV[0].downcase[/[^-]+/]
24-
when 'ucrt64', 'ucrt64-3.0'
34+
case PKG_NAME[/\A[^-]+/]
35+
when 'ucrt64'
2536
['ucrt64', 'mingw-w64-ucrt-x86_64-']
26-
when 'mingw64', 'mingw64-3.0'
37+
when 'mingw64'
2738
['mingw64', 'mingw-w64-x86_64-']
28-
when 'mingw32', 'mingw32-3.0'
39+
when 'mingw32'
2940
['mingw32', 'mingw-w64-i686-']
3041
else
3142
STDOUT.syswrite "Invalid package type, must be ucrt64, mingw64, or mingw32\n"
3243
exit 1
3344
end
45+
46+
MSYS2_PKG = "#{MSYS2_ROOT}/#{PKG_DIR}"
47+
48+
SSL_3_SAVE_FILES = %w[
49+
bin/libcrypto-3-x64.dll
50+
bin/libssl-3-x64.dll
51+
etc/ssl/openssl.cnf
52+
]
3453

35-
PKG_NAME = ARGV[0].downcase
54+
SSL_1_DLLS = %w[bin/libcrypto-1_1-x64.dll bin/libssl-1_1-x64.dll]
3655

3756
def add_ri2_key
3857
# appveyor ri2 package signing key
@@ -42,6 +61,26 @@ def add_ri2_key
4261
exec_check "Sign RI2 Key", "bash.exe -c \"pacman-key --lsign-key #{key}\""
4362
end
4463

64+
def openssl_downgrade
65+
pkg_name = "openssl-1.1.1.s-1-any.pkg.tar.zst"
66+
pkg = "https://github.com/ruby/setup-msys2-gcc/releases/download/msys2-packages/#{PKG_PRE}#{pkg_name}"
67+
pkg_sig = "#{pkg}.sig"
68+
69+
# save previous dll files so we can copy back into folder
70+
SSL_3_SAVE_FILES.each { |fn| FileUtils.cp "#{MSYS2_PKG}/#{fn}", "." }
71+
72+
download pkg , "./#{PKG_PRE}#{pkg_name}"
73+
download pkg_sig, "./#{PKG_PRE}#{pkg_name}.sig"
74+
75+
# install package
76+
exec_check "Install OpenSSL Downgrade", "pacman.exe -Udd --noconfirm --noprogressbar #{PKG_PRE}#{pkg_name}"
77+
78+
# copy previous dlls back into MSYS2 folder
79+
SSL_3_SAVE_FILES.each { |fn| FileUtils.cp_r File.basename(fn) , "#{MSYS2_PKG}/#{fn}" }
80+
openssl_copy_cert_files
81+
end
82+
83+
# as of Jan-2023, not used, save for future use
4584
def openssl_upgrade
4685
add_ri2_key
4786

@@ -68,20 +107,37 @@ def openssl_upgrade
68107
end
69108
end
70109

110+
# Below files are part of the 'ca-certificates' package, they are not
111+
# included in the openssl package
112+
# This is needed due to MSYS2 OpenSSL 1.1.1 using 'ssl', and the 3.0 version
113+
# using 'etc/ssl'.
114+
def openssl_copy_cert_files
115+
new_dir = "#{MSYS2_PKG}/ssl"
116+
old_dir = "#{MSYS2_PKG}/etc/ssl"
117+
unless Dir.exist? "#{new_dir}/certs"
118+
FileUtils.mkdir_p "#{new_dir}/certs"
119+
end
120+
%w[cert.pem certs/ca-bundle.crt certs/ca-bundle.trust.crt].each do |fn|
121+
if File.exist?("#{old_dir}/#{fn}") && !File.exist?("#{new_dir}/#{fn}")
122+
FileUtils.cp "#{old_dir}/#{fn}", "#{new_dir}/#{fn}"
123+
end
124+
end
125+
end
126+
71127
def install_gcc
72-
73128
args = '--noconfirm --noprogressbar --needed'
74129
# zlib required by gcc, gdbm for older Rubies
75130
base_gcc = %w[make pkgconf libmangle-git tools-git gcc]
76131
base_ruby = PKG_NAME.end_with?('-3.0') ?
77-
%w[gdbm gmp libffi libyaml ragel readline] :
132+
%w[gdbm gmp libffi libyaml openssl ragel readline] :
78133
%w[gdbm gmp libffi libyaml openssl ragel readline]
79134

80135
pkgs = (base_gcc + base_ruby).unshift('').join " #{PKG_PRE}"
81136

82-
# may not be needed, but...
137+
# May not be needed, but...
138+
# Note that OpenSSL may need to be ignored
83139
if PKG_NAME.end_with?('-3.0')
84-
pacman_syuu "mingw-w64-ucrt-x86_64-openssl"
140+
pacman_syuu
85141
else
86142
pacman_syuu
87143
end
@@ -91,7 +147,11 @@ def install_gcc
91147
"#{PACMAN} -S #{args} #{pkgs}"
92148

93149
if PKG_NAME.end_with? '-3.0'
94-
openssl_upgrade
150+
SSL_1_DLLS.each do |fn|
151+
FileUtils.remove_file("#{MSYS2_PKG}/#{fn}") if File.exist?("#{MSYS2_PKG}/#{fn}")
152+
end
153+
else
154+
openssl_downgrade
95155
end
96156
end
97157

@@ -170,7 +230,7 @@ def run
170230
log_array_2_column updated_pkgs.map { |el| el.sub PKG_PRE, ''}, 48,
171231
"Installed #{PKG_PRE[0..-2]} Packages"
172232

173-
if current_pkgs == updated_pkgs
233+
if (current_pkgs == updated_pkgs) && !ENV.key?('FORCE_UPDATE')
174234
STDOUT.syswrite "\n** No update to #{PKG_DIR} gcc tools needed **\n\n"
175235
exit 0
176236
else

create_mswin_pkg.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def generate_package_files
5959

6060
Dir.chdir VCPKG do |d|
6161
update_info = %x(./vcpkg update)
62-
if update_info.include? 'No packages need updating'
62+
if update_info.include?('No packages need updating') && !ENV.key?('FORCE_UPDATE')
6363
STDOUT.syswrite "\n#{GRN}No packages need updating#{RST}\n\n"
6464
exit 0
6565
else

create_msys2_pkg.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def run
9696

9797
gpg_files = Dir["#{MSYS2_ROOT}/etc/pacman.d/gnupg/*"].count { |fn| File.file? fn }
9898

99-
if current_pkgs == updated_pkgs && !updated_keys
99+
if current_pkgs == updated_pkgs && !updated_keys && !ENV.key?('FORCE_UPDATE')
100100
STDOUT.syswrite "\n** No update to MSYS2 tools needed **\n\n"
101101
exit 0
102102
else

0 commit comments

Comments
 (0)