diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 48fa57af..8219053a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -177,13 +177,13 @@ jobs: release: false update: false install: >- - ${{ matrix.arch == 'x64' && 'mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake' || 'mingw-w64-i686-toolchain mingw-w64-i686-cmake' }} + ${{ matrix.arch == 'x64' && 'mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake' || 'mingw-w64-i686-toolchain mingw-w64-i686-cmake' }} python git make - name: Build static ACE library (MinGW) if: always() && runner.os == 'Windows' shell: msys2 {0} run: | - cmake -S . -B build/mingw-${{ matrix.arch }} -G "MinGW Makefiles" \ + cmake -S . -B build/mingw-${{ matrix.arch }} -G "MSYS Makefiles" \ -DCMAKE_BUILD_TYPE=Release \ -DOPENADS_BUILD_TESTS=ON \ -DOPENADS_VERSION_FORCE="${{ steps.tag.outputs.version }}" \ @@ -195,6 +195,25 @@ jobs: ctest --test-dir build/mingw-${{ matrix.arch }} --output-on-failure -C Release ls -la build/mingw-${{ matrix.arch }}/src/libopenace*.a + - name: Package one-archive static Harbour kit and run smoke + if: runner.os == 'Windows' + shell: msys2 {0} + run: | + bits=32; if [ '${{ matrix.arch }}' = x64 ]; then bits=64; fi + bash tools/scripts/test_harbour_static_mingw.sh build/mingw-${{ matrix.arch }}/src/libopenace$bits.a $bits + + - name: Regenerate MinGW DLL imports and link health probe + if: runner.os == 'Windows' + shell: msys2 {0} + run: | + set -euo pipefail + BITS="${{ matrix.arch == 'x64' && '64' || '32' }}" + mkdir -p build/fresh-imports + python3 tools/scripts/regenerate_mingw_imports.py \ + "build/${{ matrix.preset }}/src/Release/openace${BITS}.dll" \ + "dist/import-libs/${{ matrix.arch }}/mingw/libace${BITS}.a" \ + "build/fresh-imports/libace${BITS}.a" "$BITS" + - name: Stage release files (POSIX) if: always() && runner.os != 'Windows' shell: bash @@ -217,6 +236,8 @@ jobs: mkdir -p "$STAGE/include/openads" cp include/openads/ace.h "$STAGE/include/ace.h" cp include/openads/{ace,error,openads_sql,platform,version}.h "$STAGE/include/openads/" + mkdir -p "$STAGE/contrib/oads_hb" + cp contrib/oads_hb/{oads_hb.c,oads_stats_display.prg,README.md} "$STAGE/contrib/oads_hb/" tar czvf "$STAGE.tar.gz" "$STAGE" ls -la "$STAGE.tar.gz" echo "ASSET=$STAGE.tar.gz" >> "$GITHUB_ENV" @@ -266,11 +287,15 @@ jobs: # Static ACE library (MinGW): link into an hbmk2 -comp=mingw[64] # app and no ace.dll is needed at all. Built in the # "Build static ACE library (MinGW)" step above. - $staticLib = "build/mingw-${{ matrix.arch }}/src/libopenace$bits.a" + $staticLib = "build/static-kit-$bits/libopenace$bits.a" if (-not (Test-Path $staticLib)) { throw "Static ACE library missing: $staticLib" } Copy-Item $staticLib "$stage/libopenace$bits.a" + Copy-Item "build/static-kit-$bits/libopenace$bits.manifest.json" "$stage/" + Copy-Item -Recurse "build/static-kit-$bits/runtime-notices" "$stage/" + Copy-Item docs/mingw-static-ace.md,docs/static-runtime-notices.md "$stage/" + Copy-Item "build/fresh-imports/libace$bits.a" "$stage/lib/mingw/libace$bits.a" -Force # Server + bench CLIs Copy-Item "$build/tools/serverd/Release/openads_serverd.exe" "$stage/" Copy-Item "$build/tools/bench/Release/openads_bench.exe" "$stage/" @@ -283,13 +308,13 @@ jobs: # into the app, not shipped in the DLL. Arch-independent C # source: both Windows zips carry it. (Pritpal Bedi.) New-Item -ItemType Directory "$stage/contrib/oads_hb" -Force | Out-Null - Copy-Item contrib/oads_hb/oads_hb.c,contrib/oads_hb/README.md "$stage/contrib/oads_hb/" + Copy-Item contrib/oads_hb/oads_hb.c,contrib/oads_hb/oads_stats_display.prg,contrib/oads_hb/README.md "$stage/contrib/oads_hb/" if ("${{ matrix.arch }}" -eq "x86") { Copy-Item src/openads_ace_x86_stdcall.def "$stage/" # Ship the 32-bit MinGW import library at the archive root too: # 32-bit Harbour (hbmk2 -comp=mingw, rddads) links it directly. # (Reported by Pritpal Bedi.) - Copy-Item dist/import-libs/x86/mingw/libace32.a "$stage/" + Copy-Item build/fresh-imports/libace32.a "$stage/" } else { Copy-Item src/openads_ace.def "$stage/" } @@ -438,12 +463,19 @@ jobs: with tarfile.open(path) as t: files = {m.name: t.extractfile(m).read() for m in t.getmembers() if m.isfile()} byname = {pathlib.PurePosixPath(n).name: data for n, data in files.items()} - required = ['LICENSE','NOTICE','README.md','openads.ini.sample'] + required = ['LICENSE','NOTICE','README.md','openads.ini.sample','oads_hb.c','oads_stats_display.prg'] windows = '-windows-' in path.name if windows: bits = '64' if '-x64.' in path.name else '32' - required += [f'ace{bits}.dll',f'openace{bits}.dll',f'ace{bits}.lib',f'openace{bits}.lib',f'libopenace{bits}.a','openads_serverd.exe','openads_bench.exe','oads_hb.c'] + required += [f'ace{bits}.dll',f'openace{bits}.dll',f'ace{bits}.lib',f'openace{bits}.lib',f'libopenace{bits}.a',f'libopenace{bits}.manifest.json','openads_serverd.exe','openads_bench.exe','mingw-static-ace.md','static-runtime-notices.md'] assert byname[f'ace{bits}.dll'] == byname[f'openace{bits}.dll'], 'ACE aliases differ' + import json + manifest = json.loads(byname[f'libopenace{bits}.manifest.json']) + assert manifest['profile'] == 'matching', 'Unexpected release static profile' + assert manifest['archive_sha256'] == hashlib.sha256(byname[f'libopenace{bits}.a']).hexdigest(), 'Static archive hash mismatch' + for name, digest in manifest['runtime_notice_sha256'].items(): + assert any(n.endswith('/runtime-notices/' + name) and hashlib.sha256(data).hexdigest() == digest for n, data in files.items()), f'Missing or mismatched runtime notice {name}' + assert len(manifest['runtime_notice_sha256']) == 4, 'Missing runtime notices' binary = byname['openads_serverd.exe'] else: ext = 'dylib' if '-macos-' in path.name else 'so' diff --git a/docs/mingw-static-ace.md b/docs/mingw-static-ace.md new file mode 100644 index 00000000..486516c6 --- /dev/null +++ b/docs/mingw-static-ace.md @@ -0,0 +1,40 @@ +# MinGW static client kit + +`libopenace32.a` or `libopenace64.a` is the combined implementation archive. +It contains the OpenADS engine, its bundled dependencies, the matching static +C++/GCC/pthread runtime, and compiled Harbour wrappers. `libace32.a` and +`libace64.a` are DLL import libraries, not substitutes. + +Use your matching Harbour VM and ADS RDD. Rebuild the ADS driver against the +supplied `ace.h` (cdecl for MinGW). Link the implementation archive after that +RDD and keep Windows system libraries `ws2_32` and `psapi`. Do not compile a +second `oads_hb.c`, add another runtime archive, or add an ACE DLL import library. +Keep only one implementation archive visible in linker search directories. + +The release runs `tools/scripts/test_harbour_static_mingw.sh` before staging +the combined archive, compiler/hash manifest and runtime notices. The script +is repository-only: it needs the source tree, packager, pinned Harbour source, +and a matching MSYS2 compiler. A downloaded kit is not a source-build tree. +The smoke rejects ACE, C++, GCC and pthread runtime DLL imports. + +## Profiles + +`matching` requires the same compiler for runtime and wrapper objects. The +standard release retains its existing MSYS2 compiler route. It does not change +the owner's compiler. Its current static configuration disables TLS and HTTP; +no TLS-enabled static kit is claimed by this change. + +`qt492-x86` checks pinned i686 GCC10.2 runtime and Qt MinGW4.9.2 wrapper/link +compiler. It changes only BigObj containers, not machine code. The executable +TLS-exit bridge records the callback before CRT startup and registers cleanup +in the normal CRT constructor phase, avoiding the old CRT exit-lock deadlock. +It must not be reused for DLLs or unrelated toolchains. The matching-toolchain release smoke does not exercise this legacy profile. +Qualify it separately on the exact compiler pair and application before use. + +The legacy profile also needs the exact compiler-distribution runtime notices +under `share/licenses`. Missing notices stop packaging; do not substitute a +newer compiler's notices. See `static-runtime-notices.md` before distribution. + +Static linking removes the ACE DLL dependency. It does not prevent executable +patching, injected code or a rebuilt application. A passing smoke is not +production approval, a Vouch pass, or permission to merge to main. diff --git a/docs/static-runtime-notices.md b/docs/static-runtime-notices.md new file mode 100644 index 00000000..8e3cde86 --- /dev/null +++ b/docs/static-runtime-notices.md @@ -0,0 +1,36 @@ +# Static runtime redistribution review + +The combined kit now redistributes `libstdc++.a`, `libgcc.a`, `libgcc_eh.a` +and `libwinpthread.a`. The legacy executable profile also copies selected +MinGW CRT compatibility objects. Treat this archive as a distribution of those +components, not just an OpenADS build output. + +Packaging copies the exact installed compiler's GCC GPLv3 text and Runtime +Library Exception, MinGW runtime notices and winpthreads license into +`runtime-notices/`, and hashes them in the manifest. A missing notice stops +packaging. Keep that directory with the archive and retain applicable notices +when distributing applications built from it. Existing OpenADS LICENSE/NOTICE +files and bundled engine dependency obligations are unchanged. + +GCC's documentation describes libstdc++ as GPLv3 with the GCC Runtime Library +Exception 3.1. The exception permits eligible Target Code combinations with +independent modules under their chosen terms. This is not a blanket statement +that redistribution of the runtime itself has no source obligations. Before +public distribution, preserve the exact runtime package/source versions and +check the applicable corresponding-source or source-offer route. Do not +claim that the combined archive is licensed only under OpenADS's license. +No compiler executable, profiling runtime or libquadmath is included here. + +The MSYS2 winpthreads package identifies MIT and BSD-3-Clause-Clear terms. +MinGW advises retaining its runtime notices with binary packages. We copy +all those runtime notices rather than guessing which individual notices +apply. Legacy Winlibs distributions need their own exact-version copies. +This review is a packaging checklist, not legal advice or final production +redistribution clearance. + +Sources inspected October 13, 2026: +- https://gcc.sourceware.org/onlinedocs/libstdc++/manual/license.html +- https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-gcc/PKGBUILD +- https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-crt/PKGBUILD +- https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-winpthreads/PKGBUILD +- https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/COPYING.MinGW-w64/COPYING.MinGW-w64.txt diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4c9d30de..cd891ccc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -613,6 +613,7 @@ target_link_libraries(oads_imac_test PRIVATE openads_ace) find_package(Python3 COMPONENTS Interpreter QUIET) if(Python3_Interpreter_FOUND) add_test(NAME mingw_import_parser COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/mingw_import_parser_test.py) + add_test(NAME static_client_packaging COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/static_client_packaging_test.py) endif() # The security default must be tested in new processes, not after a unit test diff --git a/tests/static_client_packaging_test.py b/tests/static_client_packaging_test.py new file mode 100644 index 00000000..49dad305 --- /dev/null +++ b/tests/static_client_packaging_test.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python3 +"""Host-independent packaging failure gates, with explicitly synthetic tool output.""" +import hashlib +import importlib.util +import json +from pathlib import Path +import sys +import tempfile +import unittest +from unittest.mock import patch + +ROOT = Path(__file__).resolve().parents[1] +spec = importlib.util.spec_from_file_location('static_packager', ROOT / 'tools/scripts/package_static_client.py') +packager = importlib.util.module_from_spec(spec) +spec.loader.exec_module(packager) + + +class PackagingGates(unittest.TestCase): + def setUp(self): + self.temp = tempfile.TemporaryDirectory() + self.addCleanup(self.temp.cleanup) + self.root = Path(self.temp.name).resolve() + self.runtime = self.root / 'runtime' + self.link = self.runtime + for name in ('ar', 'objcopy', 'nm', 'gcc'): + path = self.runtime / 'bin' / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text('synthetic tool, never executed') + self.notices = ('gcc/COPYING3', 'gcc/COPYING.RUNTIME', 'crt/COPYING.MinGW-w64-runtime.txt', 'winpthreads/COPYING') + for name in self.notices: + path = self.runtime / 'share/licenses' / name + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text('SYNTHETIC TEST NOTICE ' + name) + for name in ('libstdc++.a', 'libgcc.a', 'libgcc_eh.a', 'libwinpthread.a'): + (self.runtime / name).write_bytes(b'!\nsynthetic runtime') + self.engine = self.root / 'engine.a' + self.engine.write_bytes(b'!\nsynthetic engine') + self.glue = self.root / 'glue.c' + self.glue.write_text('synthetic wrapper') + self.output = self.root / 'kit/libopenace32.a' + self.target = 'i686-w64-mingw32' + self.missing_exports = False + self.empty_exports = False + self.missing_runtime = False + self.target_mismatch = False + + def fake_run(self, *args, cwd=None, text=True, input=None): + tool, *options = [str(a) for a in args] + if options == ['-dumpmachine']: + if self.target_mismatch and Path(tool).parent.parent.resolve() == self.link.resolve(): + return 'x86_64-w64-mingw32\n' + return self.target + '\n' + if options == ['-dumpversion']: + return '15.2.0\n' + if options and options[0].startswith('-print-file-name='): + name = options[0].split('=', 1)[1] + if self.missing_runtime: + return str(self.root / 'absent.a') + '\n' + return str(self.runtime / name) + '\n' + if Path(tool).name == 'ar' and options == ['-M']: + candidate = Path(input.splitlines()[0].removeprefix('create ')) + candidate.write_bytes(b'!\nSYNTHETIC COMBINED ARCHIVE') + return '' + if Path(tool).name == 'gcc' and '-c' in options: + Path(options[options.index('-o') + 1]).write_bytes(b'SYNTHETIC OBJECT') + return '' + if Path(tool).name == 'nm': + if options[0] == '-u': + return '' if self.empty_exports else ' U _AdsProbe\n' + return '' if self.missing_exports else '0000 T _AdsProbe\n' + if Path(tool).name == 'ar' and options[0] in ('r', 's'): + return '' + raise AssertionError(('unexpected synthetic-tool call', args)) + + def execute(self, profile='matching'): + argv = ['package_static_client.py', '--engine', str(self.engine), + '--runtime-root', str(self.runtime), '--link-root', str(self.link), + '--harbour-include', str(self.root), '--glue', str(self.glue), + '--ace-include', str(self.root), '--output', str(self.output), + '--profile', profile] + with patch.object(sys, 'argv', argv), patch.object(packager, 'run', self.fake_run), patch.object(packager.shutil, 'which', return_value=None), patch('builtins.print'): + packager.main() + + def test_matching_profiles_record_archive_and_all_notice_hashes(self): + for target in ('i686-w64-mingw32', 'x86_64-w64-mingw32'): + self.target = target + self.execute() + manifest = json.loads(self.output.with_suffix('.manifest.json').read_text()) + self.assertEqual(manifest['runtime_target'], target) + self.assertEqual(manifest['archive_sha256'], hashlib.sha256(self.output.read_bytes()).hexdigest()) + self.assertEqual(manifest['engine_sha256'], hashlib.sha256(self.engine.read_bytes()).hexdigest()) + self.assertEqual(len(manifest['runtime_notice_sha256']), 4) + for name, digest in manifest['runtime_notice_sha256'].items(): + self.assertEqual(digest, hashlib.sha256((self.output.parent / 'runtime-notices' / name).read_bytes()).hexdigest()) + + def test_missing_notice_stops_packaging(self): + (self.runtime / 'share/licenses' / self.notices[0]).unlink() + with self.assertRaisesRegex(SystemExit, 'Missing exact runtime notice'): + self.execute() + self.assertFalse(self.output.exists()) + + def test_missing_runtime_stops_packaging(self): + self.missing_runtime = True + with self.assertRaisesRegex(SystemExit, 'Missing static runtime'): + self.execute() + self.assertFalse(self.output.exists()) + + def test_missing_wrapper_export_keeps_existing_archive(self): + self.output.parent.mkdir() + self.output.write_bytes(b'previous archive') + self.missing_exports = True + with self.assertRaisesRegex(SystemExit, 'Missing implementation exports'): + self.execute() + self.assertEqual(self.output.read_bytes(), b'previous archive') + + def test_no_wrapper_requirements_is_not_success(self): + self.empty_exports = True + with self.assertRaisesRegex(SystemExit, 'Missing implementation exports'): + self.execute() + + def test_matching_profile_rejects_different_compiler_roots(self): + self.link = self.root / 'other' + (self.link / 'bin').mkdir(parents=True) + (self.link / 'bin/gcc').write_text('synthetic tool') + with self.assertRaisesRegex(SystemExit, 'same runtime and link compiler'): + self.execute() + + def test_architecture_mismatch_stops_before_output(self): + self.link = self.root / 'other' + (self.link / 'bin').mkdir(parents=True) + (self.link / 'bin/gcc').write_text('synthetic tool') + self.target_mismatch = True + with self.assertRaisesRegex(SystemExit, 'architecture mismatch'): + self.execute() + self.assertFalse(self.output.exists()) + + def test_windows_drive_paths_convert_for_msys_python(self): + with patch.object(packager, 'NATIVE_WINDOWS', False), patch.object(packager.shutil, 'which', return_value='cygpath'), patch.object(packager, 'run', return_value='/d/build/engine.a\n') as call: + self.assertEqual(packager.host_path('D:/build/engine.a').as_posix(), '/d/build/engine.a') + call.assert_called_once_with('cygpath', '-u', 'D:/build/engine.a') + + def test_mri_stdin_paths_convert_to_native_drive_paths(self): + with patch.object(packager.shutil, 'which', return_value='cygpath'), patch.object(packager, 'run', return_value='D:/build/kit.a\n') as call: + self.assertEqual(packager.mri_path('/d/build/kit.a'), 'D:/build/kit.a') + call.assert_called_once_with('cygpath', '-m', '/d/build/kit.a') + + def test_legacy_profile_rejects_unpinned_compiler(self): + with self.assertRaisesRegex(SystemExit, 'requires pinned'): + self.execute('qt492-x86') + + +if __name__ == '__main__': + unittest.main(verbosity=2) diff --git a/tools/scripts/package_static_client.py b/tools/scripts/package_static_client.py new file mode 100644 index 00000000..480fd4e5 --- /dev/null +++ b/tools/scripts/package_static_client.py @@ -0,0 +1,169 @@ +#!/usr/bin/env python3 +"""Build one MinGW implementation/runtime/Harbour-glue archive. +The RDD and Harbour VM remain caller-owned. No compiler is downloaded here. +""" +import argparse +import hashlib +import json +import os +import re +import pathlib +import shutil +import subprocess +import tempfile + +NATIVE_WINDOWS = os.name == 'nt' + + +def run(*args, cwd=None, text=True, input=None): + return subprocess.check_output([str(a) for a in args], cwd=cwd, text=text, input=input) + + +def host_path(value): + # MSYS Python uses POSIX paths; native Python uses drive paths. The + # shell helper may supply either. Do not interpret D:/... as relative. + value = str(value) + if not NATIVE_WINDOWS and re.match(r'^[A-Za-z]:[\\/]', value): + if not shutil.which('cygpath'): + raise SystemExit('Windows drive path requires native Python or cygpath') + value = run('cygpath', '-u', value).strip() + return pathlib.Path(value) + + +def mri_path(value): + # ar reads MRI paths from stdin, where MSYS argv conversion cannot help. + value = str(value) + if shutil.which('cygpath'): + value = run('cygpath', '-m', value).strip() + return value.replace('\\', '/') + + +def tool(root, name): + for suffix in ('', '.exe'): + p = host_path(root) / 'bin' / (name + suffix) + if p.is_file(): + return p.resolve() + raise SystemExit('Missing compiler tool: ' + name) + + +def main(): + p = argparse.ArgumentParser(description=__doc__) + p.add_argument('--engine', required=True) + p.add_argument('--runtime-root', required=True) + p.add_argument('--link-root', required=True) + p.add_argument('--harbour-include', required=True) + p.add_argument('--glue', required=True) + p.add_argument('--ace-include', required=True) + p.add_argument('--output', required=True) + p.add_argument('--profile', choices=('matching', 'qt492-x86'), default='matching') + a = p.parse_args() + out = host_path(a.output).resolve() + out.parent.mkdir(parents=True, exist_ok=True) + engine = host_path(a.engine).resolve() + engine_digest = hashlib.sha256(engine.read_bytes()).hexdigest() + ar, objcopy, nm = [tool(a.runtime_root, n) for n in ('ar', 'objcopy', 'nm')] + gcc = tool(a.runtime_root, 'gcc') + link_gcc = tool(a.link_root, 'gcc') + triple = run(gcc, '-dumpmachine').strip() + link_triple = run(link_gcc, '-dumpmachine').strip() + version = run(gcc, '-dumpversion').strip() + link_version = run(link_gcc, '-dumpversion').strip() + if triple != link_triple: + raise SystemExit('Runtime/link architecture mismatch') + old = a.profile == 'qt492-x86' + if old: + if triple != 'i686-w64-mingw32' or version != '10.2.0' or link_version != '4.9.2': + raise SystemExit('qt492-x86 requires pinned i686 GCC10.2 runtime and GCC4.9.2 linker') + elif host_path(a.runtime_root).resolve() != host_path(a.link_root).resolve(): + raise SystemExit('matching profile requires the same runtime and link compiler') + # Copy notices from the exact installed runtime, not a newer web version. + notice_root = host_path(a.runtime_root) / 'share' / 'licenses' + notice_files = { + 'gcc/COPYING3': 'gcc-COPYING3.txt', + 'gcc/COPYING.RUNTIME': 'gcc-COPYING.RUNTIME.txt', + 'crt/COPYING.MinGW-w64-runtime.txt': 'MinGW-w64-runtime.txt', + 'winpthreads/COPYING': 'winpthreads-COPYING.txt', + } + # Legacy compiler distributions may keep these in a different directory. + # Do not substitute unrelated versions or silently ship without notices. + notices = out.parent / 'runtime-notices' + notices.mkdir(exist_ok=True) + for source, dest in notice_files.items(): + source_file = notice_root / source + if not source_file.is_file(): + raise SystemExit('Missing exact runtime notice: ' + str(source_file)) + shutil.copyfile(source_file, notices / dest) + archives = [engine] + for name in ('libstdc++.a', 'libgcc.a', 'libgcc_eh.a', 'libwinpthread.a'): + f = host_path(run(gcc, '-print-file-name=' + name).strip()).resolve() + if not f.is_file(): + raise SystemExit('Missing static runtime: ' + name) + archives.append(f) + with tempfile.TemporaryDirectory(prefix='openads-kit-', dir=out.parent) as tmp: + tmp = pathlib.Path(tmp).resolve() + if any(' ' in str(f) for f in archives + [tmp]): + raise SystemExit('GNU ar MRI needs space-free packaging paths') + candidate = tmp / 'libopenace.a' + mri = 'create ' + mri_path(candidate) + '\n' + for i, f in enumerate(archives): + staged = tmp / ('input%d.a' % i) + shutil.copyfile(f, staged) + mri += 'addlib ' + mri_path(staged) + '\n' + run(ar, '-M', input=mri + 'save\nend\n') + converted = [] + if old: + names = run(ar, 't', candidate).splitlines() + # Preserve MRI member ordering; replace only BigObj units. + for name in dict.fromkeys(names): + run(ar, 'x', candidate, name, cwd=tmp) + f = tmp / name + data = f.read_bytes() + if data[:4] == b'\x00\x00\xff\xff' and data[4:6] == b'\x02\x00': + if names.count(name) != 1: + raise SystemExit('Ambiguous duplicate BigObj member: ' + name) + converted_file = tmp / (name + '.normal') + run(objcopy, '-O', 'pe-i386', f, converted_file) + converted_file.replace(f) + run(ar, 'r', candidate, f) + converted.append(name) + for lib, name in ( + ('libmingw32.a', 'lib32_libmingw32_a-cxa_thread_atexit.o'), + ('libmingw32.a', 'lib32_libmingw32_a-tls_atexit.o'), + ('libmsvcrt.a', 'lib32_libmsvcrt_os_a-acrt_iob_func.o'), + ('libmsvcrt.a', 'dembbs01050.o'), + ('libmsvcrt.a', 'dembbh.o'), + ('libmsvcrt.a', 'dembbt.o'), + ): + libfile = host_path(run(gcc, '-print-file-name=' + lib).strip()).resolve() + run(ar, 'x', libfile, name, cwd=tmp) + run(ar, 'r', candidate, tmp / name) + bridge = pathlib.Path(__file__).with_name('qt492_tls_exit_bridge.c') + run(link_gcc, '-c', bridge, '-o', tmp / 'crt_compat.o') + run(ar, 'r', candidate, tmp / 'crt_compat.o') + glue = host_path(a.glue).resolve() + run(link_gcc, '-c', glue, '-I' + a.harbour_include, + '-I' + a.ace_include, + '-o', tmp / 'oads_hb.o') + run(ar, 'r', candidate, tmp / 'oads_hb.o') + # Fail closed on unresolved application wrapper names. + required = {l.split()[-1] for l in run(nm, '-u', tmp / 'oads_hb.o').splitlines() + if l.split() and l.split()[-1].startswith(('_Ads', '_OAds', 'Ads', 'OAds'))} + defined = {l.split()[-1] for l in run(nm, '--defined-only', candidate).splitlines() + if len(l.split()) >= 3} + if not required or required - defined: + raise SystemExit('Missing implementation exports: ' + repr(sorted(required - defined))) + run(ar, 's', candidate) + candidate.replace(out) + manifest = {'profile': a.profile, 'runtime_target': triple, 'runtime_version': version, + 'link_version': link_version, 'engine_sha256': engine_digest, + 'archive_sha256': hashlib.sha256(out.read_bytes()).hexdigest(), + 'bytes': out.stat().st_size, 'converted_bigobj': converted, + 'glue_exports_verified': sorted(required), + 'runtime_notice_sha256': {f.name: hashlib.sha256(f.read_bytes()).hexdigest() + for f in sorted(notices.iterdir()) if f.is_file()}} + out.with_suffix('.manifest.json').write_text(json.dumps(manifest, indent=2) + '\n') + print(json.dumps(manifest, indent=2)) + + +if __name__ == '__main__': + main() diff --git a/tools/scripts/qt492_tls_exit_bridge.c b/tools/scripts/qt492_tls_exit_bridge.c new file mode 100644 index 00000000..aac88774 --- /dev/null +++ b/tools/scripts/qt492_tls_exit_bridge.c @@ -0,0 +1,17 @@ +/* Old MinGW executable startup compatibility: TLS callbacks run before + * the CRT is ready. Record the modern cleanup callback there; register + * its adapter only from the old CRT's constructor phase. */ +#include +#include +int __mingw_module_is_dll = 0; +static void (WINAPI *tls_exit_callback)(void *, DWORD, void *); +static void run_tls_exit(void) { + if (tls_exit_callback) tls_exit_callback(NULL, DLL_PROCESS_DETACH, NULL); + tls_exit_callback = NULL; +} +void _register_thread_local_exe_atexit_callback(void (WINAPI *callback)(void *, DWORD, void *)) { + tls_exit_callback = callback; +} +static void __attribute__((constructor)) register_tls_exit_after_crt(void) { + if (tls_exit_callback && atexit(run_tls_exit) != 0) abort(); +} diff --git a/tools/scripts/test_harbour_static_mingw.sh b/tools/scripts/test_harbour_static_mingw.sh new file mode 100644 index 00000000..b51817df --- /dev/null +++ b/tools/scripts/test_harbour_static_mingw.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# Run within the matching MSYS2 MinGW environment, from repository root. +set -euo pipefail +archive="$1" +bits="$2" +case "$bits" in 32) comp=mingw;; 64) comp=mingw64;; *) exit 2;; esac +archive="$(realpath "$archive")" +root="$(pwd)" +HB="$RUNNER_TEMP/harbour-static-$bits" +ref=4ec2e154ed92757418bc30af571ab90240ab3209 +if [ ! -d "$HB/src/.git" ]; then + mkdir -p "$HB" + git clone --depth 1 https://github.com/harbour/core.git "$HB/src" +fi +git -C "$HB/src" fetch --depth 1 origin "$ref" +git -C "$HB/src" checkout --detach "$ref" +make -C "$HB/src" -j"$(nproc)" install HB_PLATFORM=win HB_COMPILER="$comp" \ + HB_INSTALL_PREFIX="$HB/install" HB_BUILD_CONTRIBS=no HB_BUILD_3RDEXT=no +hbmk="$(find "$HB/install" -iname hbmk2.exe -type f | head -1)" +test -n "$hbmk" +work="$RUNNER_TEMP/harbour-static-smoke-$bits" +mkdir -p "$work" +# Explicit stock RDD objects avoid rddads.hbc's automatic DLL import libs. +for unit in ads1 adsfunc adsmgmnt adsx; do + gcc -c "$HB/src/contrib/rddads/$unit.c" -I"$HB/src/include" \ + -I"$HB/src/contrib/rddads" -I"$root/include/openads" -o "$work/$unit.o" +done +# Package runtime and Harbour wrappers once, using this exact compiler. +# Keep the raw CMake archive for native C++ smoke tests; publish the kit archive. +runtime_root="$(dirname "$(dirname "$(command -v gcc)")")" +kit="$root/build/static-kit-$bits" +mkdir -p "$kit" +python tools/scripts/package_static_client.py --profile matching \ + --engine "$(cygpath -m "$archive")" \ + --runtime-root "$(cygpath -m "$runtime_root")" \ + --link-root "$(cygpath -m "$runtime_root")" \ + --harbour-include "$(cygpath -m "$HB/src/include")" \ + --ace-include "$(cygpath -m "$root/include/openads")" \ + --glue "$(cygpath -m "$root/contrib/oads_hb/oads_hb.c")" \ + --output "$(cygpath -m "$kit/libopenace$bits.a")" +"$hbmk" "$root/tests/smoke/harbour_static_ace.prg" \ + "$work/ads1.o" "$work/adsfunc.o" "$work/adsmgmnt.o" "$work/adsx.o" \ + "$kit/libopenace$bits.a" \ + -comp="$comp" -I"$root/include/openads" -I"$HB/src/contrib/rddads" \ + -lws2_32 -lpsapi -ldflag=-static -o"$work/harbour-static-smoke.exe" +objdump -p "$work/harbour-static-smoke.exe" > "$work/imports.txt" +if grep -Ei 'DLL Name:.*(openace[0-9]*|ace32|ace64|libstdc\+\+.*|libgcc.*|libwinpthread.*)\.dll' "$work/imports.txt"; then + echo 'Harbour static smoke unexpectedly imports an ACE DLL' >&2 + exit 1 +fi +cd "$work" +./harbour-static-smoke.exe