Skip to content

Commit e4e49e0

Browse files
authored
Switch MySQL extension to use (latest) MariaDB connector (fixes 2526) (#2548)
* Switch MySQL extension to use (latest) MariaDB connector (fixes 2526) * Fix release
1 parent 261dd2c commit e4e49e0

8 files changed

Lines changed: 173 additions & 125 deletions

File tree

.github/workflows/build-release.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ env:
99
DUMP_SYMS_VERSION: '2.3.7'
1010
# Used for caching
1111
# TODO: Handle this better so that we don't have to update this in lockstep with checkout-deps
12-
MYSQL_VERSION: '5.7'
12+
MARIADB_CONNECTOR_C_VERSION: '3.4.9'
13+
MARIADB_CONNECTOR_C_RELEASE: '3.4.9-sm.5'
1314
MMSOURCE_VERSION: '1.12'
1415
jobs:
1516
build:
@@ -96,13 +97,13 @@ jobs:
9697
- name: Cache dependencies
9798
uses: actions/cache@v6
9899
env:
99-
cache-name: hl2sdk-mysql-mmsource
100+
cache-name: hl2sdk-mariadb-connector-c-mmsource
100101
with:
101102
path: ${{ steps.path_helper.outputs.dependencies }}
102-
key: ${{ runner.os }}-build-${{ env.cache-name }}-mysql${{ env.MYSQL_VERSION }}-mmsource${{ env.MMSOURCE_VERSION }}-${{ join(fromJson(steps.sdk_list.outputs.sdk_list), '') }}
103+
key: ${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-mmsource${{ env.MMSOURCE_VERSION }}-${{ join(fromJson(steps.sdk_list.outputs.sdk_list), '') }}
103104
restore-keys: |
104-
${{ runner.os }}-build-${{ env.cache-name }}-mysql${{ env.MYSQL_VERSION }}-mmsource${{ env.MMSOURCE_VERSION }}-
105-
${{ runner.os }}-build-${{ env.cache-name }}-mysql${{ env.MYSQL_VERSION }}-
105+
${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-mmsource${{ env.MMSOURCE_VERSION }}-
106+
${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-
106107
107108
- name: Install dependencies
108109
shell: bash
@@ -150,8 +151,8 @@ jobs:
150151
--targets=${{ env.ARCH }} \
151152
'--mms-path=${{ steps.path_helper.outputs.dependencies }}/mmsource-${{ env.MMSOURCE_VERSION }}' \
152153
'--hl2sdk-root=${{ steps.path_helper.outputs.dependencies }}' \
153-
'--mysql-path=${{ steps.path_helper.outputs.dependencies }}/mysql-${{ env.MYSQL_VERSION }}' \
154-
'--mysql64-path=${{ steps.path_helper.outputs.dependencies }}/mysql-${{ env.MYSQL_VERSION }}-x86_64'
154+
'--mariadb-path=${{ steps.path_helper.outputs.dependencies }}/mariadb-connector-c-${{ env.MARIADB_CONNECTOR_C_VERSION }}-x86' \
155+
'--mariadb64-path=${{ steps.path_helper.outputs.dependencies }}/mariadb-connector-c-${{ env.MARIADB_CONNECTOR_C_VERSION }}-x86_64'
155156
ambuild
156157
157158
mkdir -p package/addons/sourcemod/configs/geoip

.github/workflows/pr-checks.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ jobs:
2929
env:
3030
SDKS: '["episode1","css","tf2","l4d2","csgo","dods"]'
3131
ARCH: x86,x86_64
32-
MYSQL_VERSION: '5.7'
32+
MARIADB_CONNECTOR_C_VERSION: '3.4.9'
33+
MARIADB_CONNECTOR_C_RELEASE: '3.4.9-sm.5'
3334
MMSOURCE_VERSION: '1.12'
3435
steps:
3536
- uses: actions/checkout@v7
@@ -48,13 +49,13 @@ jobs:
4849
- name: Cache dependencies
4950
uses: actions/cache@v6
5051
env:
51-
cache-name: hl2sdk-mysql-mmsource
52+
cache-name: hl2sdk-mariadb-connector-c-mmsource
5253
with:
5354
path: ${{ steps.path_helper.outputs.dependencies }}
54-
key: ${{ runner.os }}-build-${{ env.cache-name }}-mysql${{ env.MYSQL_VERSION }}-mmsource${{ env.MMSOURCE_VERSION }}-${{ join(fromJSON(env.SDKS), '') }}
55+
key: ${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-mmsource${{ env.MMSOURCE_VERSION }}-${{ join(fromJSON(env.SDKS), '') }}
5556
restore-keys: |
56-
${{ runner.os }}-build-${{ env.cache-name }}-mysql${{ env.MYSQL_VERSION }}-mmsource${{ env.MMSOURCE_VERSION }}-
57-
${{ runner.os }}-build-${{ env.cache-name }}-mysql${{ env.MYSQL_VERSION }}-
57+
${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-mmsource${{ env.MMSOURCE_VERSION }}-
58+
${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-
5859
5960
- name: Install dependencies
6061
shell: bash
@@ -78,6 +79,6 @@ jobs:
7879
--targets=${{ env.ARCH }} \
7980
'--mms-path=${{ steps.path_helper.outputs.dependencies }}/mmsource-${{ env.MMSOURCE_VERSION }}' \
8081
'--hl2sdk-root=${{ steps.path_helper.outputs.dependencies }}' \
81-
'--mysql-path=${{ steps.path_helper.outputs.dependencies }}/mysql-${{ env.MYSQL_VERSION }}' \
82-
'--mysql64-path=${{ steps.path_helper.outputs.dependencies }}/mysql-${{ env.MYSQL_VERSION }}-x86_64'
82+
'--mariadb-path=${{ steps.path_helper.outputs.dependencies }}/mariadb-connector-c-${{ env.MARIADB_CONNECTOR_C_VERSION }}-x86' \
83+
'--mariadb64-path=${{ steps.path_helper.outputs.dependencies }}/mariadb-connector-c-${{ env.MARIADB_CONNECTOR_C_VERSION }}-x86_64'
8384
ambuild

AMBuildScript

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class SMConfig(object):
4545
self.extensions = []
4646
self.generated_headers = None
4747
self.mms_root = None
48-
self.mysql_root = {}
48+
self.mariadb_root = {}
4949
self.spcomp = None
5050
self.spcomp_bins = []
5151
self.smx_files = {}
@@ -141,28 +141,26 @@ class SMConfig(object):
141141

142142
if builder.options.hasMySql:
143143
if 'x86' in self.target_archs:
144-
if builder.options.mysql_path:
145-
self.mysql_root['x86'] = builder.options.mysql_path
144+
mariadb_path = getattr(builder.options, 'mariadb_path',
145+
getattr(builder.options, 'mysql_path', None))
146+
if mariadb_path:
147+
self.mariadb_root['x86'] = mariadb_path
146148
else:
147-
for i in range(10):
148-
self.mysql_root['x86'] = ResolveEnvPath('MYSQL57', 'mysql-5.' + str(i))
149-
if self.mysql_root['x86']:
150-
break
151-
if not self.mysql_root['x86'] or not os.path.isdir(self.mysql_root['x86']):
152-
raise Exception('Could not find a path to MySQL. Configure with --no-mysql to disable it.')
153-
self.mysql_root['x86'] = Normalize(self.mysql_root['x86'])
149+
self.mariadb_root['x86'] = ResolveEnvPath('MARIADB_CONNECTOR_C', 'mariadb-connector-c-3.4.8-x86')
150+
if not self.mariadb_root['x86'] or not os.path.isdir(self.mariadb_root['x86']):
151+
raise Exception('Could not find an x86 MariaDB Connector/C path. Configure with --no-mysql to disable it.')
152+
self.mariadb_root['x86'] = Normalize(self.mariadb_root['x86'])
154153

155154
if 'x86_64' in self.target_archs:
156-
if builder.options.mysql64_path:
157-
self.mysql_root['x86_64'] = builder.options.mysql64_path
155+
mariadb64_path = getattr(builder.options, 'mariadb64_path',
156+
getattr(builder.options, 'mysql64_path', None))
157+
if mariadb64_path:
158+
self.mariadb_root['x86_64'] = mariadb64_path
158159
else:
159-
for i in range(10):
160-
self.mysql_root['x86_64'] = ResolveEnvPath('MYSQL57_64', 'mysql-5.' + str(i) + '-x86_64')
161-
if self.mysql_root['x86_64']:
162-
break
163-
if not self.mysql_root['x86_64'] or not os.path.isdir(self.mysql_root['x86_64']):
164-
raise Exception('Could not find a path to 64-bit MySQL!')
165-
self.mysql_root['x86_64'] = Normalize(self.mysql_root['x86_64'])
160+
self.mariadb_root['x86_64'] = ResolveEnvPath('MARIADB_CONNECTOR_C_64', 'mariadb-connector-c-3.4.8-x86_64')
161+
if not self.mariadb_root['x86_64'] or not os.path.isdir(self.mariadb_root['x86_64']):
162+
raise Exception('Could not find an x86_64 MariaDB Connector/C path.')
163+
self.mariadb_root['x86_64'] = Normalize(self.mariadb_root['x86_64'])
166164

167165
def configure(self):
168166
builder.AddConfigureFile('pushbuild.txt')

configure.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
parser = run.BuildParser(sourcePath=sys.path[0], api='2.2')
2222
parser.options.add_argument('--hl2sdk-root', type=str, dest='hl2sdk_root', default=None,
2323
help='Root search folder for HL2SDKs')
24-
parser.options.add_argument('--mysql-path', type=str, dest='mysql_path', default=None,
25-
help='Path to MySQL 5')
26-
parser.options.add_argument('--mysql64-path', type=str, dest='mysql64_path', default=None,
27-
help='Path to 64-bit MySQL 5')
24+
parser.options.add_argument('--mariadb-path', type=str, dest='mariadb_path', default=None,
25+
help='Path to x86 MariaDB Connector/C')
26+
parser.options.add_argument('--mariadb64-path', type=str, dest='mariadb64_path', default=None,
27+
help='Path to x86_64 MariaDB Connector/C')
2828
parser.options.add_argument('--mms-path', type=str, dest='mms_path', default=None,
2929
help='Path to Metamod:Source')
3030
parser.options.add_argument('--enable-debug', action='store_const', const='1', dest='debug',

extensions/mysql/AMBuilder

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
11
# vim: set sts=2 ts=8 sw=2 tw=99 et ft=python:
22
import os
33

4-
if SM.mysql_root:
4+
if SM.mariadb_root:
55
for cxx in builder.targets:
66
arch = cxx.target.arch
77
binary = SM.ExtLibrary(builder, cxx, 'dbi.mysql.ext')
88
binary.compiler.cxxincludes += [
9-
os.path.join(SM.mysql_root[arch], 'include'),
9+
os.path.join(SM.mariadb_root[arch], 'include', 'mariadb'),
1010
os.path.join(SM.mms_root, 'core', 'sourcehook')
1111
]
1212
if binary.compiler.family == 'gcc' or binary.compiler.family == 'clang':
1313
binary.compiler.cxxflags += ['-fno-rtti']
1414
elif binary.compiler.family == 'msvc':
1515
binary.compiler.cxxflags += ['/GR-']
16-
if builder.options.debug == '1':
17-
binary.compiler.cflags += ['/MDd']
18-
else:
19-
binary.compiler.cflags += ['/MD']
2016

2117
if binary.compiler.target.platform == 'linux' or binary.compiler.target.platform == 'mac':
2218
binary.compiler.postlink += [
23-
os.path.join(SM.mysql_root[arch], 'lib', 'libmysqlclient.a'),
19+
os.path.join(SM.mariadb_root[arch], 'lib', 'libmariadbclient.a'),
2420
'-lz',
2521
'-lpthread',
2622
'-lm',
2723
]
2824
if binary.compiler.target.platform == 'linux':
29-
binary.compiler.postlink += ['-lrt']
25+
binary.compiler.postlink += ['-lrt', '-ldl', '-lssl', '-lcrypto']
3026
elif binary.compiler.target.platform == 'windows':
3127
binary.compiler.defines += ['WIN32_LEAN_AND_MEAN']
3228
if builder.options.debug == '1':
3329
binary.compiler.defines += ['_ITERATOR_DEBUG_LEVEL=2']
3430
binary.compiler.postlink += [
35-
os.path.join(SM.mysql_root[arch], 'lib', 'debug', 'mysqlclient.lib'),
31+
os.path.join(SM.mariadb_root[arch], 'lib', 'debug', 'mariadbclient.lib'),
3632
]
3733
else:
3834
binary.compiler.postlink += [
39-
os.path.join(SM.mysql_root[arch], 'lib', 'mysqlclient.lib'),
35+
os.path.join(SM.mariadb_root[arch], 'lib', 'mariadbclient.lib'),
4036
]
4137
binary.compiler.postlink += [
4238
'crypt32.lib',
43-
'wsock32.lib'
39+
'secur32.lib',
40+
'bcrypt.lib',
41+
'ws2_32.lib',
42+
'shlwapi.lib',
4443
]
4544

4645
binary.sources += [
@@ -59,4 +58,3 @@ if SM.mysql_root:
5958
binary.compiler.defines += ['HAVE_STRUCT_TIMESPEC']
6059

6160
SM.extensions += [builder.Add(binary)]
62-

extensions/mysql/mysql/MyDriver.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
#include <WinSock2.h>
4040
#endif
4141

42-
#include <my_global.h>
43-
#include <my_sys.h>
4442
#include <mysql.h>
4543

4644
// On macOS, the MySQL includes define min/max.

tools/checkout-deps.ps1

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#>
77

88
[CmdletBinding()]
9-
param(
9+
param(
1010
[string[]]$SDKs = @(
1111
'csgo',
1212
'hl2dm',
@@ -29,9 +29,63 @@ param(
2929
'eye',
3030
'contagion',
3131
'doi',
32-
'pvkii'
33-
)
34-
)
32+
'pvkii'
33+
),
34+
[switch]$NoMariaDB
35+
)
36+
37+
$MARIADB_CONNECTOR_C_VERSION = if ($env:MARIADB_CONNECTOR_C_VERSION) { $env:MARIADB_CONNECTOR_C_VERSION } else { '3.4.9' }
38+
$MARIADB_CONNECTOR_C_RELEASE = if ($env:MARIADB_CONNECTOR_C_RELEASE) { $env:MARIADB_CONNECTOR_C_RELEASE } else { '3.4.9-sm.5' }
39+
$MARIADB_CONNECTOR_C_REPOSITORY = 'alliedmodders/mariadb-connector-c'
40+
41+
Function Get-MariaDBConnectorC
42+
{
43+
param(
44+
[Parameter(Mandatory=$true)][string]$Architecture
45+
)
46+
47+
$folder = "mariadb-connector-c-$MARIADB_CONNECTOR_C_VERSION-$Architecture"
48+
if (Test-Path $folder -PathType Container)
49+
{
50+
return
51+
}
52+
53+
$releaseUrl = "https://github.com/$MARIADB_CONNECTOR_C_REPOSITORY/releases/download/v$MARIADB_CONNECTOR_C_RELEASE"
54+
$archiveName = "mariadb-connector-c-$MARIADB_CONNECTOR_C_VERSION-windows-$Architecture.zip"
55+
$checksumPath = Join-Path (Resolve-Path '.') 'SHA256SUMS'
56+
$archivePath = Join-Path (Resolve-Path '.') $archiveName
57+
58+
Invoke-WebRequest -Uri "$releaseUrl/SHA256SUMS" -OutFile $checksumPath
59+
Invoke-WebRequest -Uri "$releaseUrl/$archiveName" -OutFile $archivePath
60+
61+
$expected = Get-Content -LiteralPath $checksumPath |
62+
ForEach-Object {
63+
$fields = $_ -split '\s+'
64+
if ($fields.Length -ge 2 -and $fields[-1].TrimStart('*') -eq $archiveName)
65+
{
66+
$fields[0]
67+
}
68+
} |
69+
Select-Object -First 1
70+
if (-not $expected)
71+
{
72+
throw "No SHA256 checksum was published for $archiveName."
73+
}
74+
75+
$actual = (Get-FileHash -Algorithm SHA256 -LiteralPath $archivePath).Hash
76+
if ($actual -ne $expected)
77+
{
78+
throw "SHA256 verification failed for $archiveName."
79+
}
80+
81+
Expand-Archive -LiteralPath $archivePath -DestinationPath .
82+
if (-not (Test-Path $folder -PathType Container))
83+
{
84+
throw "MariaDB Connector/C archive did not contain $folder."
85+
}
86+
87+
Remove-Item -LiteralPath $archivePath, $checksumPath
88+
}
3589

3690
Function Get-Repository
3791
{
@@ -69,13 +123,19 @@ Function Get-Repository
69123
}
70124
}
71125

72-
if (-not (Test-Path "sourcemod" -PathType Container))
126+
if (-not (Test-Path "sourcemod" -PathType Container))
73127
{
74128
Write-Error "Could not find a SourceMod repository; make sure you aren't running this script inside it."
75129
Exit 1
76-
}
77-
78-
Get-Repository -Name "mmsource-1.12" -Branch "1.12-dev" -Repo "https://github.com/alliedmodders/metamod-source.git"
130+
}
131+
132+
if (-not $NoMariaDB)
133+
{
134+
Get-MariaDBConnectorC -Architecture 'x86'
135+
Get-MariaDBConnectorC -Architecture 'x86_64'
136+
}
137+
138+
Get-Repository -Name "mmsource-1.12" -Branch "1.12-dev" -Repo "https://github.com/alliedmodders/metamod-source.git"
79139

80140
if (-not (Test-Path "hl2sdk-proxy-repo" -PathType Container))
81141
{

0 commit comments

Comments
 (0)