102 lines
11 KiB
Python
102 lines
11 KiB
Python
#!/usr/bin/env python3
|
|
"""Build an owned PE/Wine bridge; never installs it or starts game/services."""
|
|
import argparse,hashlib,json,subprocess
|
|
from pathlib import Path
|
|
from source_local_profile import endpoints
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
FOLDER=ROOT/'build/wine-wire'
|
|
LIBS=[Path('/usr/lib/wine/x86_64-windows')/name for name in ('libwinecrt0.a','libntdll.a','libkernel32.a','libmsvcrt.a')]
|
|
FLAGS=['--target=x86_64-pc-windows-msvc','-I/usr/include/wine','-I/usr/include/wine/windows','-I/usr/include/wine/msvcrt','-I'+str(ROOT/'native'),'-I'+str(ROOT/'native/nohelper'),'-I'+str(ROOT/'include'),'-O2','-Wall','-Wextra','-Werror','-ffreestanding','-fno-stack-protector','-funwind-tables']
|
|
def sha(path):return hashlib.sha256(path.read_bytes()).hexdigest()
|
|
def build(*,pe_only=False,output_directory=None,native_windows=False,backend_import_library=None,bridge_import_library=None,source_only_profile=0,source_local_auth_host=None,source_local_auth_port=None,source_local_realm_host=None,source_local_realm_port=None,self_locating_bundle=False):
|
|
if type(source_only_profile)is not int or source_only_profile not in (0,2,3,4,5):raise ValueError('Unsupported Source-only build profile')
|
|
local=endpoints(source_only_profile,source_local_auth_host,source_local_auth_port,source_local_realm_host,source_local_realm_port)
|
|
folder=Path(output_directory).resolve()if output_directory is not None else FOLDER
|
|
allowed_roots=(ROOT/'build',ROOT/'runtime/vm-build-share')
|
|
if not any(folder!=base and folder.is_relative_to(base) for base in allowed_roots)or folder.is_symlink():raise ValueError('Owned build or VM-share subdirectory required')
|
|
if self_locating_bundle and folder==FOLDER:raise ValueError('Self-locating candidates require a separate output directory')
|
|
if pe_only and folder==FOLDER:raise ValueError('PE-only candidates require a separate output directory')
|
|
if source_only_profile and folder==FOLDER:raise ValueError('Source-only candidates require a separate output directory')
|
|
folder.mkdir(exist_ok=True)
|
|
if native_windows and not pe_only:raise ValueError("Native Windows bridge requires --pe-only and a separate output directory")
|
|
if not pe_only:subprocess.run(['cmake','--build',str(ROOT/'build'),'--target','gateway_wine_wire','-j','4'],check=True,stdout=subprocess.DEVNULL)
|
|
source=ROOT/'native/wine_wire_windows.c';dll=folder/'GWNativeWire.dll';cache=folder/'pe-cache.json'
|
|
account=ROOT/'native/wine_wire_account.c'
|
|
listener=ROOT/'native/wine_wire_listener.c'
|
|
realm=ROOT/'native/wine_engine_realm.c'
|
|
pipe=ROOT/'native/wine_pipe_host.c'
|
|
policy=ROOT/'native/wine_channel_policy.c'
|
|
retirement=ROOT/'native/wine_session_retirement.c'
|
|
files=[source,account,listener,realm,pipe,policy,retirement,ROOT/'native/wine_account_ui_header.inc',ROOT/'native/wine_session_retirement.h',ROOT/'native/private_account_switch_gate.h',ROOT/'native/hotfix_request_split.h',ROOT/'native/wine_channel_policy.h',ROOT/'native/engine_realm_context.h',ROOT/'native/wine_pipe_host.h',ROOT/'native/wine_engine_realm.h',ROOT/'native/wine_wire_listener.h',ROOT/'native/wine_wire_host.h',ROOT/'native/wine_wire_abi.h',ROOT/'native/session.h',Path('/usr/include/wine/unixlib.h'),Path('/usr/include/wine/windows/winnt.h'),*LIBS]
|
|
files += [ROOT/'native/world_locator_fifo.h', ROOT/'native/engine_spell_locator_ready.h', ROOT/'native/engine_original_main_header.h', ROOT/'include/gateway/spellbook_hidden_readiness.h']
|
|
if self_locating_bundle:files += [ROOT/'native/wine_bundle_paths.c', ROOT/'native/wine_bundle_paths.h']
|
|
source_files=[ROOT/'native'/name for name in ('wine_source_profile.c','wine_source_profile.h','wine_source_resolver.c','wine_source_preflight.c','wine_source_preflight.h','wine_source_preflight.inc','wine_source_realm_consumer.inc','source_auth_detail.inc','source_auth_detail_contract.h','wine_source_login_readiness.c')]
|
|
files += [ROOT/'native/spell_hotfix_trace.h', ROOT/'native/source_creation_options.h']
|
|
source_libs=[Path('/usr/lib/wine/x86_64-windows/libws2_32.a')] if source_only_profile else []
|
|
if source_only_profile:files+=source_files+source_libs
|
|
export_definition=ROOT/'native/nohelper/wire_exports.def' if source_only_profile in (2,5) else None
|
|
if export_definition:files.append(export_definition)
|
|
files += [ROOT/'native/nohelper'/name for name in (
|
|
'wine_preopen_hook.private.h','wire_realm_observe.private.h',
|
|
'realm_diag_admission.private.h','wire_profile5_auto_realm.private.h',
|
|
'wine_preopen_hook.c','wire_profile5_auto_realm.c',
|
|
'wire_public_hash_v1.private.h','wire_public_addon_v1.private.h',
|
|
'account_identity_compare.private.h','owner-queue.private.inc',
|
|
'pipe_snapshot.private.inc','pipe_snapshot.private.h')]
|
|
imports=[Path(x).resolve()for x in (backend_import_library,bridge_import_library)if x is not None]
|
|
if imports and(not native_windows or len(imports)!=2 or not all(x.is_file()for x in imports)):raise ValueError('Both native backend/bridge import libraries required')
|
|
if source_only_profile==5 and native_windows and not imports:
|
|
raise ValueError('Profile5 native-Windows Wire requires explicit backend/bridge imports; the seven-row bundle uses Wine Unix-call mode')
|
|
files+=imports
|
|
flags=FLAGS+(['-DGW_NATIVE_WINDOWS=1'] if native_windows else [])+(['-DGW_NATIVE_LINKED_BACKEND=1']if imports else[])+(['-DGW_SOURCE_ONLY_PROFILE='+str(source_only_profile)] if source_only_profile else [])
|
|
if source_only_profile in (2,5):flags += ['-DGW_SOURCE_UI_CREATE_EXPERIMENT=1']
|
|
if self_locating_bundle:flags += ['-DGW_ENABLE_SELF_LOCATING_BUNDLE=1']
|
|
if local:flags += ['-DGW_SOURCE_LOCAL_AUTH_IPV4="'+local['auth_host']+'"','-DGW_SOURCE_LOCAL_AUTH_PORT='+str(local['auth_port']),'-DGW_SOURCE_LOCAL_REALM_IPV4="'+local['realm_host']+'"','-DGW_SOURCE_LOCAL_REALM_PORT='+str(local['realm_port'])]
|
|
key={'files':{str(p):sha(p) for p in files},'flags':flags,'compiler':subprocess.check_output(['clang','--version']).decode().splitlines()[0]}
|
|
if not(cache.exists() and dll.exists() and json.loads(cache.read_text())==key):
|
|
obj=folder/'wire.obj'
|
|
subprocess.run(['clang',*flags,'-c',str(source),'-o',str(obj)],check=True)
|
|
bundle_objs=[]
|
|
if self_locating_bundle:
|
|
bundle_obj=folder/'bundle-paths.obj'
|
|
subprocess.run(['clang',*flags,'-c',str(ROOT/'native/wine_bundle_paths.c'),'-o',str(bundle_obj)],check=True)
|
|
bundle_objs.append(str(bundle_obj))
|
|
account_obj=folder/'account.obj'
|
|
subprocess.run(['clang',*flags,'-c',str(account),'-o',str(account_obj)],check=True)
|
|
listener_obj=folder/'listener.obj'
|
|
subprocess.run(['clang',*flags,'-c',str(listener),'-o',str(listener_obj)],check=True)
|
|
direct_objs=[]
|
|
# Auto realm admission: profile 5 admits the pinned local singleton;
|
|
# profile 2 (play.octowow.st) admits the user's realm-screen choice.
|
|
for name in ('wine_preopen_hook',)+(('wire_profile5_auto_realm',) if source_only_profile in (2,5) else ()):
|
|
direct_obj=folder/(name+'.obj')
|
|
subprocess.run(['clang',*flags,'-c',str(ROOT/'native/nohelper'/(name+'.c')),'-o',str(direct_obj)],check=True)
|
|
direct_objs.append(str(direct_obj))
|
|
realm_obj=folder/'realm.obj'
|
|
subprocess.run(['clang',*flags,'-c',str(realm),'-o',str(realm_obj)],check=True)
|
|
pipe_obj=folder/'pipe.obj'
|
|
subprocess.run(['clang',*flags,'-c',str(pipe),'-o',str(pipe_obj)],check=True)
|
|
policy_obj=folder/'channel.obj'
|
|
retirement_obj=folder/'retirement.obj'
|
|
subprocess.run(['clang',*flags,'-c',str(policy),'-o',str(policy_obj)],check=True)
|
|
subprocess.run(['clang',*flags,'-c',str(retirement),'-o',str(retirement_obj)],check=True)
|
|
source_objs=[]
|
|
if source_only_profile:
|
|
for name in ('wine_source_profile','wine_source_resolver','wine_source_preflight','wine_source_login_readiness'):
|
|
extra=folder/(name+'.obj')
|
|
subprocess.run(['clang',*flags,'-c',str(ROOT/'native'/(name+'.c')),'-o',str(extra)],check=True)
|
|
source_objs.append(str(extra))
|
|
subprocess.run(['lld-link','/dll','/noentry','/nodefaultlib','/timestamp:0',*(['/def:'+str(export_definition)] if export_definition else []),'/out:'+str(dll),str(obj),*bundle_objs,str(account_obj),str(listener_obj),str(realm_obj),str(pipe_obj),str(policy_obj),str(retirement_obj),*direct_objs,*source_objs,*[str(p) for p in LIBS],*[str(p) for p in source_libs],*map(str,imports)],check=True)
|
|
cache.write_text(json.dumps(key,sort_keys=True)+'\n')
|
|
manifest={'pe_sha256':sha(dll),'abi':1,'platform':'native-Windows-LoadLibrary' if native_windows else 'Wine-Unix-call','original_client_modified':False}
|
|
if self_locating_bundle:manifest.update(self_locating_bundle=True,bundle_path_identity_verified=False)
|
|
if source_only_profile:manifest.update(source_only_profile=source_only_profile,source_only_host=local['auth_host'] if local else {2:'play.octowow.st',3:'praxis.go.ro',4:'127.0.0.1'}[source_only_profile],source_only_auth_port=local['auth_port'] if local else 3724,source_profile_is_authentication=False,source_login_native_acceptance=False)
|
|
if local:manifest['source_local_realm']=local
|
|
if not native_windows:manifest.update(unix_sha256=sha(ROOT/'build/libgateway_wine_wire.so'),core_sha256=sha(ROOT/'build/libgateway_native.so'))
|
|
else:manifest.update(backend='GWNativeBackend.dll',dispatch_export='gw_native_wire_dispatch',native_runtime_acceptance=False,startup_linked_dependencies=bool(imports))
|
|
(folder/'manifest.json').write_text(json.dumps(manifest,indent=2)+'\n')
|
|
return dll,(folder/'GWNativeBackend.dll' if native_windows else ROOT/'build/libgateway_wine_wire.so')
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser(description=__doc__);p.add_argument('--pe-only',action='store_true');p.add_argument('--native-windows',action='store_true');p.add_argument('--output-directory',type=Path);p.add_argument('--backend-import-library',type=Path);p.add_argument('--bridge-import-library',type=Path);p.add_argument('--source-only-profile',type=int,choices=(0,2,3,4,5),default=0);p.add_argument('--source-local-auth-host');p.add_argument('--source-local-auth-port',type=int);p.add_argument('--source-local-realm-host');p.add_argument('--source-local-realm-port',type=int);p.add_argument('--self-locating-bundle',action='store_true');a=p.parse_args()
|
|
build(pe_only=a.pe_only,output_directory=a.output_directory,native_windows=a.native_windows,backend_import_library=a.backend_import_library,bridge_import_library=a.bridge_import_library,source_only_profile=a.source_only_profile,source_local_auth_host=a.source_local_auth_host,source_local_auth_port=a.source_local_auth_port,source_local_realm_host=a.source_local_realm_host,source_local_realm_port=a.source_local_realm_port,self_locating_bundle=a.self_locating_bundle);print('Built own native Windows PE bridge; runtime acceptance pending.' if a.native_windows else 'Built own PE/Wine wire ABI; no installation, engine calls or services started.')
|