diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 0bec9210..1de93efb 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -9,7 +9,8 @@ env: DUMP_SYMS_VERSION: '2.3.7' # Used for caching # TODO: Handle this better so that we don't have to update this in lockstep with checkout-deps - MYSQL_VERSION: '5.7' + MARIADB_CONNECTOR_C_VERSION: '3.4.9' + MARIADB_CONNECTOR_C_RELEASE: '3.4.9-sm.5' MMSOURCE_VERSION: '1.12' jobs: build: @@ -96,13 +97,13 @@ jobs: - name: Cache dependencies uses: actions/cache@v6 env: - cache-name: hl2sdk-mysql-mmsource + cache-name: hl2sdk-mariadb-connector-c-mmsource with: path: ${{ steps.path_helper.outputs.dependencies }} - key: ${{ runner.os }}-build-${{ env.cache-name }}-mysql${{ env.MYSQL_VERSION }}-mmsource${{ env.MMSOURCE_VERSION }}-${{ join(fromJson(steps.sdk_list.outputs.sdk_list), '') }} + 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), '') }} restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}-mysql${{ env.MYSQL_VERSION }}-mmsource${{ env.MMSOURCE_VERSION }}- - ${{ runner.os }}-build-${{ env.cache-name }}-mysql${{ env.MYSQL_VERSION }}- + ${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-mmsource${{ env.MMSOURCE_VERSION }}- + ${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}- - name: Install dependencies shell: bash @@ -150,8 +151,8 @@ jobs: --targets=${{ env.ARCH }} \ '--mms-path=${{ steps.path_helper.outputs.dependencies }}/mmsource-${{ env.MMSOURCE_VERSION }}' \ '--hl2sdk-root=${{ steps.path_helper.outputs.dependencies }}' \ - '--mysql-path=${{ steps.path_helper.outputs.dependencies }}/mysql-${{ env.MYSQL_VERSION }}' \ - '--mysql64-path=${{ steps.path_helper.outputs.dependencies }}/mysql-${{ env.MYSQL_VERSION }}-x86_64' + '--mariadb-path=${{ steps.path_helper.outputs.dependencies }}/mariadb-connector-c-${{ env.MARIADB_CONNECTOR_C_VERSION }}-x86' \ + '--mariadb64-path=${{ steps.path_helper.outputs.dependencies }}/mariadb-connector-c-${{ env.MARIADB_CONNECTOR_C_VERSION }}-x86_64' ambuild mkdir -p package/addons/sourcemod/configs/geoip diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index cec935c2..326dc3b7 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -29,7 +29,8 @@ jobs: env: SDKS: '["episode1","css","tf2","l4d2","csgo","dods"]' ARCH: x86,x86_64 - MYSQL_VERSION: '5.7' + MARIADB_CONNECTOR_C_VERSION: '3.4.9' + MARIADB_CONNECTOR_C_RELEASE: '3.4.9-sm.5' MMSOURCE_VERSION: '1.12' steps: - uses: actions/checkout@v7 @@ -48,13 +49,13 @@ jobs: - name: Cache dependencies uses: actions/cache@v6 env: - cache-name: hl2sdk-mysql-mmsource + cache-name: hl2sdk-mariadb-connector-c-mmsource with: path: ${{ steps.path_helper.outputs.dependencies }} - key: ${{ runner.os }}-build-${{ env.cache-name }}-mysql${{ env.MYSQL_VERSION }}-mmsource${{ env.MMSOURCE_VERSION }}-${{ join(fromJSON(env.SDKS), '') }} + key: ${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-mmsource${{ env.MMSOURCE_VERSION }}-${{ join(fromJSON(env.SDKS), '') }} restore-keys: | - ${{ runner.os }}-build-${{ env.cache-name }}-mysql${{ env.MYSQL_VERSION }}-mmsource${{ env.MMSOURCE_VERSION }}- - ${{ runner.os }}-build-${{ env.cache-name }}-mysql${{ env.MYSQL_VERSION }}- + ${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}-mmsource${{ env.MMSOURCE_VERSION }}- + ${{ runner.os }}-build-${{ env.cache-name }}-mariadb${{ env.MARIADB_CONNECTOR_C_RELEASE }}- - name: Install dependencies shell: bash @@ -78,6 +79,6 @@ jobs: --targets=${{ env.ARCH }} \ '--mms-path=${{ steps.path_helper.outputs.dependencies }}/mmsource-${{ env.MMSOURCE_VERSION }}' \ '--hl2sdk-root=${{ steps.path_helper.outputs.dependencies }}' \ - '--mysql-path=${{ steps.path_helper.outputs.dependencies }}/mysql-${{ env.MYSQL_VERSION }}' \ - '--mysql64-path=${{ steps.path_helper.outputs.dependencies }}/mysql-${{ env.MYSQL_VERSION }}-x86_64' + '--mariadb-path=${{ steps.path_helper.outputs.dependencies }}/mariadb-connector-c-${{ env.MARIADB_CONNECTOR_C_VERSION }}-x86' \ + '--mariadb64-path=${{ steps.path_helper.outputs.dependencies }}/mariadb-connector-c-${{ env.MARIADB_CONNECTOR_C_VERSION }}-x86_64' ambuild diff --git a/AMBuildScript b/AMBuildScript index cf689fbf..5a093bc7 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -45,7 +45,7 @@ class SMConfig(object): self.extensions = [] self.generated_headers = None self.mms_root = None - self.mysql_root = {} + self.mariadb_root = {} self.spcomp = None self.spcomp_bins = [] self.smx_files = {} @@ -141,28 +141,26 @@ class SMConfig(object): if builder.options.hasMySql: if 'x86' in self.target_archs: - if builder.options.mysql_path: - self.mysql_root['x86'] = builder.options.mysql_path + mariadb_path = getattr(builder.options, 'mariadb_path', + getattr(builder.options, 'mysql_path', None)) + if mariadb_path: + self.mariadb_root['x86'] = mariadb_path else: - for i in range(10): - self.mysql_root['x86'] = ResolveEnvPath('MYSQL57', 'mysql-5.' + str(i)) - if self.mysql_root['x86']: - break - if not self.mysql_root['x86'] or not os.path.isdir(self.mysql_root['x86']): - raise Exception('Could not find a path to MySQL. Configure with --no-mysql to disable it.') - self.mysql_root['x86'] = Normalize(self.mysql_root['x86']) + self.mariadb_root['x86'] = ResolveEnvPath('MARIADB_CONNECTOR_C', 'mariadb-connector-c-3.4.8-x86') + if not self.mariadb_root['x86'] or not os.path.isdir(self.mariadb_root['x86']): + raise Exception('Could not find an x86 MariaDB Connector/C path. Configure with --no-mysql to disable it.') + self.mariadb_root['x86'] = Normalize(self.mariadb_root['x86']) if 'x86_64' in self.target_archs: - if builder.options.mysql64_path: - self.mysql_root['x86_64'] = builder.options.mysql64_path + mariadb64_path = getattr(builder.options, 'mariadb64_path', + getattr(builder.options, 'mysql64_path', None)) + if mariadb64_path: + self.mariadb_root['x86_64'] = mariadb64_path else: - for i in range(10): - self.mysql_root['x86_64'] = ResolveEnvPath('MYSQL57_64', 'mysql-5.' + str(i) + '-x86_64') - if self.mysql_root['x86_64']: - break - if not self.mysql_root['x86_64'] or not os.path.isdir(self.mysql_root['x86_64']): - raise Exception('Could not find a path to 64-bit MySQL!') - self.mysql_root['x86_64'] = Normalize(self.mysql_root['x86_64']) + self.mariadb_root['x86_64'] = ResolveEnvPath('MARIADB_CONNECTOR_C_64', 'mariadb-connector-c-3.4.8-x86_64') + if not self.mariadb_root['x86_64'] or not os.path.isdir(self.mariadb_root['x86_64']): + raise Exception('Could not find an x86_64 MariaDB Connector/C path.') + self.mariadb_root['x86_64'] = Normalize(self.mariadb_root['x86_64']) def configure(self): builder.AddConfigureFile('pushbuild.txt') diff --git a/configure.py b/configure.py index edb64371..721d47e6 100644 --- a/configure.py +++ b/configure.py @@ -21,10 +21,10 @@ if ambuild_version.startswith('2.1'): parser = run.BuildParser(sourcePath=sys.path[0], api='2.2') parser.options.add_argument('--hl2sdk-root', type=str, dest='hl2sdk_root', default=None, help='Root search folder for HL2SDKs') -parser.options.add_argument('--mysql-path', type=str, dest='mysql_path', default=None, - help='Path to MySQL 5') -parser.options.add_argument('--mysql64-path', type=str, dest='mysql64_path', default=None, - help='Path to 64-bit MySQL 5') +parser.options.add_argument('--mariadb-path', type=str, dest='mariadb_path', default=None, + help='Path to x86 MariaDB Connector/C') +parser.options.add_argument('--mariadb64-path', type=str, dest='mariadb64_path', default=None, + help='Path to x86_64 MariaDB Connector/C') parser.options.add_argument('--mms-path', type=str, dest='mms_path', default=None, help='Path to Metamod:Source') parser.options.add_argument('--enable-debug', action='store_const', const='1', dest='debug', diff --git a/extensions/mysql/AMBuilder b/extensions/mysql/AMBuilder index 2c2f3e74..a0b88890 100644 --- a/extensions/mysql/AMBuilder +++ b/extensions/mysql/AMBuilder @@ -1,46 +1,45 @@ # vim: set sts=2 ts=8 sw=2 tw=99 et ft=python: import os -if SM.mysql_root: +if SM.mariadb_root: for cxx in builder.targets: arch = cxx.target.arch binary = SM.ExtLibrary(builder, cxx, 'dbi.mysql.ext') binary.compiler.cxxincludes += [ - os.path.join(SM.mysql_root[arch], 'include'), + os.path.join(SM.mariadb_root[arch], 'include', 'mariadb'), os.path.join(SM.mms_root, 'core', 'sourcehook') ] if binary.compiler.family == 'gcc' or binary.compiler.family == 'clang': binary.compiler.cxxflags += ['-fno-rtti'] elif binary.compiler.family == 'msvc': binary.compiler.cxxflags += ['/GR-'] - if builder.options.debug == '1': - binary.compiler.cflags += ['/MDd'] - else: - binary.compiler.cflags += ['/MD'] if binary.compiler.target.platform == 'linux' or binary.compiler.target.platform == 'mac': binary.compiler.postlink += [ - os.path.join(SM.mysql_root[arch], 'lib', 'libmysqlclient.a'), + os.path.join(SM.mariadb_root[arch], 'lib', 'libmariadbclient.a'), '-lz', '-lpthread', '-lm', ] if binary.compiler.target.platform == 'linux': - binary.compiler.postlink += ['-lrt'] + binary.compiler.postlink += ['-lrt', '-ldl', '-lssl', '-lcrypto'] elif binary.compiler.target.platform == 'windows': binary.compiler.defines += ['WIN32_LEAN_AND_MEAN'] if builder.options.debug == '1': binary.compiler.defines += ['_ITERATOR_DEBUG_LEVEL=2'] binary.compiler.postlink += [ - os.path.join(SM.mysql_root[arch], 'lib', 'debug', 'mysqlclient.lib'), + os.path.join(SM.mariadb_root[arch], 'lib', 'debug', 'mariadbclient.lib'), ] else: binary.compiler.postlink += [ - os.path.join(SM.mysql_root[arch], 'lib', 'mysqlclient.lib'), + os.path.join(SM.mariadb_root[arch], 'lib', 'mariadbclient.lib'), ] binary.compiler.postlink += [ 'crypt32.lib', - 'wsock32.lib' + 'secur32.lib', + 'bcrypt.lib', + 'ws2_32.lib', + 'shlwapi.lib', ] binary.sources += [ @@ -59,4 +58,3 @@ if SM.mysql_root: binary.compiler.defines += ['HAVE_STRUCT_TIMESPEC'] SM.extensions += [builder.Add(binary)] - diff --git a/extensions/mysql/mysql/MyDriver.h b/extensions/mysql/mysql/MyDriver.h index 86c9dfa6..4cc0d4c4 100644 --- a/extensions/mysql/mysql/MyDriver.h +++ b/extensions/mysql/mysql/MyDriver.h @@ -39,8 +39,6 @@ #include #endif -#include -#include #include // On macOS, the MySQL includes define min/max. diff --git a/tools/checkout-deps.ps1 b/tools/checkout-deps.ps1 index 988cb382..97d669d4 100644 --- a/tools/checkout-deps.ps1 +++ b/tools/checkout-deps.ps1 @@ -6,7 +6,7 @@ #> [CmdletBinding()] -param( +param( [string[]]$SDKs = @( 'csgo', 'hl2dm', @@ -29,9 +29,63 @@ param( 'eye', 'contagion', 'doi', - 'pvkii' - ) -) + 'pvkii' + ), + [switch]$NoMariaDB +) + +$MARIADB_CONNECTOR_C_VERSION = if ($env:MARIADB_CONNECTOR_C_VERSION) { $env:MARIADB_CONNECTOR_C_VERSION } else { '3.4.9' } +$MARIADB_CONNECTOR_C_RELEASE = if ($env:MARIADB_CONNECTOR_C_RELEASE) { $env:MARIADB_CONNECTOR_C_RELEASE } else { '3.4.9-sm.5' } +$MARIADB_CONNECTOR_C_REPOSITORY = 'alliedmodders/mariadb-connector-c' + +Function Get-MariaDBConnectorC +{ + param( + [Parameter(Mandatory=$true)][string]$Architecture + ) + + $folder = "mariadb-connector-c-$MARIADB_CONNECTOR_C_VERSION-$Architecture" + if (Test-Path $folder -PathType Container) + { + return + } + + $releaseUrl = "https://github.com/$MARIADB_CONNECTOR_C_REPOSITORY/releases/download/v$MARIADB_CONNECTOR_C_RELEASE" + $archiveName = "mariadb-connector-c-$MARIADB_CONNECTOR_C_VERSION-windows-$Architecture.zip" + $checksumPath = Join-Path (Resolve-Path '.') 'SHA256SUMS' + $archivePath = Join-Path (Resolve-Path '.') $archiveName + + Invoke-WebRequest -Uri "$releaseUrl/SHA256SUMS" -OutFile $checksumPath + Invoke-WebRequest -Uri "$releaseUrl/$archiveName" -OutFile $archivePath + + $expected = Get-Content -LiteralPath $checksumPath | + ForEach-Object { + $fields = $_ -split '\s+' + if ($fields.Length -ge 2 -and $fields[-1].TrimStart('*') -eq $archiveName) + { + $fields[0] + } + } | + Select-Object -First 1 + if (-not $expected) + { + throw "No SHA256 checksum was published for $archiveName." + } + + $actual = (Get-FileHash -Algorithm SHA256 -LiteralPath $archivePath).Hash + if ($actual -ne $expected) + { + throw "SHA256 verification failed for $archiveName." + } + + Expand-Archive -LiteralPath $archivePath -DestinationPath . + if (-not (Test-Path $folder -PathType Container)) + { + throw "MariaDB Connector/C archive did not contain $folder." + } + + Remove-Item -LiteralPath $archivePath, $checksumPath +} Function Get-Repository { @@ -69,13 +123,19 @@ Function Get-Repository } } -if (-not (Test-Path "sourcemod" -PathType Container)) +if (-not (Test-Path "sourcemod" -PathType Container)) { Write-Error "Could not find a SourceMod repository; make sure you aren't running this script inside it." Exit 1 -} - -Get-Repository -Name "mmsource-1.12" -Branch "1.12-dev" -Repo "https://github.com/alliedmodders/metamod-source.git" +} + +if (-not $NoMariaDB) +{ + Get-MariaDBConnectorC -Architecture 'x86' + Get-MariaDBConnectorC -Architecture 'x86_64' +} + +Get-Repository -Name "mmsource-1.12" -Branch "1.12-dev" -Repo "https://github.com/alliedmodders/metamod-source.git" if (-not (Test-Path "hl2sdk-proxy-repo" -PathType Container)) { diff --git a/tools/checkout-deps.sh b/tools/checkout-deps.sh index 4817fa2a..87b772af 100755 --- a/tools/checkout-deps.sh +++ b/tools/checkout-deps.sh @@ -3,22 +3,21 @@ trap "exit" INT -download_mysql=1 -download_mysql_debug=1 +download_mariadb=1 + +mariadb_version=${MARIADB_CONNECTOR_C_VERSION:-3.4.9} +mariadb_release=${MARIADB_CONNECTOR_C_RELEASE:-3.4.9-sm.5} +mariadb_repo=alliedmodders/mariadb-connector-c # List of HL2SDK branch names to download. # ./checkout-deps.sh -s tf2,css -# Disable downloading of mysql libraries. +# Disable downloading of MariaDB Connector/C libraries. # ./checkout-deps.sh -m -# Disable downloading of mysql debug libraries on Windows. -# ./checkout-deps.sh -d while getopts ":s:m" opt; do case $opt in s) IFS=', ' read -r -a sdks <<< "$OPTARG" ;; - m) download_mysql=0 - ;; - d) download_mysql_debug=0 + m) download_mariadb=0 ;; \?) echo "Invalid option -$OPTARG" >&2 ;; @@ -46,73 +45,66 @@ if [ ! -d "sourcemod" ]; then fi fi -getmysql () +download_file () { - if [ ! -d $mysqlfolder ]; then - if [ `command -v wget` ]; then - wget -q $mysqlurl -O $mysqlfolder.$archive_ext - elif [ `command -v curl` ]; then - curl -sS -o $mysqlfolder.$archive_ext $mysqlurl - else - echo "Failed to locate wget or curl. Install one of these programs to download MySQL." - exit 1 - fi - $decomp $mysqlfolder.$archive_ext - mv $mysqlver $mysqlfolder - rm $mysqlfolder.$archive_ext + if command -v wget >/dev/null; then + wget -q "$1" -O "$2" + elif command -v curl >/dev/null; then + curl -fsSL "$1" -o "$2" + else + echo "Failed to locate wget or curl. Install one of these programs to download MariaDB Connector/C." + exit 1 fi } -# 32-bit MySQL -mysqlfolder=mysql-5.7 +verify_checksum () +{ + local archive=$1 + local sums=$2 + local entry + entry=$(grep -E "[[:space:]][*]?$archive$" "$sums") + if [ -z "$entry" ]; then + echo "No checksum found for $archive" + exit 1 + fi + if command -v sha256sum >/dev/null; then + printf '%s\n' "$entry" | sha256sum -c - + else + printf '%s\n' "$entry" | shasum -a 256 -c - + fi +} + +getmariadb () +{ + local arch=$1 + local platform=$2 + local folder="mariadb-connector-c-$mariadb_version-$arch" + local archive="mariadb-connector-c-$mariadb_version-$platform-$arch.$archive_ext" + local release_url="https://github.com/$mariadb_repo/releases/download/v$mariadb_release" + local sums=SHA256SUMS + + if [ ! -d "$folder" ]; then + download_file "$release_url/$sums" "$sums" + download_file "$release_url/$archive" "$archive" + verify_checksum "$archive" "$sums" + $decomp "$archive" + if [ ! -d "$folder" ]; then + echo "MariaDB Connector/C archive did not contain $folder" + exit 1 + fi + rm "$archive" "$sums" + fi +} + +if [ $download_mariadb -eq 1 ]; then + mariadb_platform=linux if [ $ismac -eq 1 ]; then - mysqlfolder=mysql-5.5 - mysqlver=mysql-5.5.28-osx10.5-x86 - mysqlurl=https://cdn.mysql.com/archives/mysql-5.5/$mysqlver.$archive_ext + mariadb_platform=macos elif [ $iswin -eq 1 ]; then - mysqlver=mysql-5.7.44-win32 - mysqlurl=https://cdn.mysql.com/archives/mysql-5.7/$mysqlver.$archive_ext - # The folder in the zip archive does not contain the substring "-noinstall", so strip it - mysqlver=${mysqlver/-noinstall} -else - mysqlver=mysql-5.7.44-linux-glibc2.12-i686 - mysqlurl=https://cdn.mysql.com/archives/mysql-5.7/$mysqlver.$archive_ext + mariadb_platform=windows fi -if [ $download_mysql -eq 1 ]; then - getmysql -fi - -# 64-bit MySQL -mysqlfolder=mysql-5.7-x86_64 -if [ $ismac -eq 1 ]; then - mysqlfolder=mysql-5.5-x86_64 - mysqlver=mysql-5.5.28-osx10.5-x86_64 - mysqlurl=https://cdn.mysql.com/archives/mysql-5.5/$mysqlver.$archive_ext -elif [ $iswin -eq 1 ]; then - mysqlver=mysql-5.7.44-winx64 - mysqlurl=https://cdn.mysql.com/archives/mysql-5.7/$mysqlver.$archive_ext -else - mysqlver=mysql-5.7.44-linux-glibc2.12-x86_64 - mysqlurl=https://cdn.mysql.com/archives/mysql-5.7/$mysqlver.$archive_ext -fi -if [ $download_mysql -eq 1 ]; then - getmysql -fi - -if [ $iswin -eq 1 ] && [ $download_mysql_debug -eq 1 ]; then - mysqlfolder=mysql-5.7-debug - mysqlver=mysql-5.7.44-win32 - mysqlurl=https://cdn.mysql.com/archives/mysql-5.7/$mysqlver-debug-test.$archive_ext - getmysql - cp -r $mysqlfolder/lib/* mysql-5.7/lib - rm -rf $mysqlfolder - - mysqlfolder=mysql-5.7-debug-x86_64 - mysqlver=mysql-5.7.44-winx64 - mysqlurl=https://cdn.mysql.com/archives/mysql-5.7/$mysqlver-debug-test.$archive_ext - getmysql - cp -r $mysqlfolder/lib/* mysql-5.7-x86_64/lib - rm -rf $mysqlfolder + getmariadb x86 "$mariadb_platform" + getmariadb x86_64 "$mariadb_platform" fi checkout ()