// Build the two release X11 bridges from the pinned Vinix modules. module main import os fn run(command string, args []string) ! { path := os.find_abs_path_of_executable(command)! mut child := os.new_process(path) child.set_args(args) child.run() child.wait() defer { child.close() } if child.code != 0 { return error('${command} failed with exit status ${child.code}') } } fn compile_bridge(name string, binary string, arch string, root string) ! { os.mkdir_all('${name}-build/${name}')! os.write_file('${name}-build/v.mod', "Module { name: 'x11_bridge' }\n")! os.write_file('${name}-build/entry.v', 'module main\nimport ${name} as _\n')! for file in ['core', 'native'] { os.cp('${name}-${file}.v', '${name}-build/${name}/${file}.v')! } mut flags := ['-shared', '-no-builtin', '-no-closures', '-os', 'vinix', '-arch', arch, '-target-libc-headers', '-gc', 'none', '-manualfree'] mut libs := ['-lXtst', '-lX11', '-lXext', '-lxcb'] if name == 'winehost' { os.cp('winehost-package.v', 'winehost-build/winehost/package.v')! os.mkdir_all('winehost-build/x11auth')! os.cp('auth.v', 'winehost-build/x11auth/auth.v')! flags << ['-d', 'x11_host_libc'] libs << '-lXdamage' } flags << ['-o', '${binary}.c', '${name}-build'] run('v', flags)! mut cc := ['-std=gnu11', '-O2', '-D__vinix__', '-DVINIX_XINPUT_V_RUNTIME=1', '-I.', '-ffreestanding', '-fno-builtin', '-fwrapv', '-fno-strict-aliasing', '-static-libgcc', '-Wl,-rpath-link,${root}/usr/lib', '-Wl,-rpath-link,${root}/lib', '${binary}.c'] cc << libs cc << ['-o', binary] run('vinix-cc', cc)! } fn release_config(script string, marker string, name string) ! { start := "<< '${marker}'\n" end := '\n${marker}\n' if script.count(start) != 1 { return error('expected a single ${marker} configuration in the Vinix release script') } body := script.all_after(start) if !body.contains(end) { return error('unterminated ${marker} configuration') } os.write_file(name, body.all_before(end) + '\n')! } fn build() ! { target := os.getenv_opt('VPAC_TARGET_ARCH') or { os.uname().machine } arch := match target { 'x86_64' { 'amd64' } 'aarch64' { 'arm64' } else { return error('unsupported X11 bridge target ${target}') } } root := os.getenv('VPAC_MAKEPKG_ROOT') compile_bridge('xinputcore', 'vinix-xinput', arch, root)! compile_bridge('winehost', 'vinix-wine-host', arch, root)! script := os.read_file('build-x11-aarch64.sh')! release_config(script, 'XORGEOF', 'xorg.conf')! release_config(script, 'XINITEOF', 'xinitrc')! } fn main() { build() or { eprintln(err) exit(1) } }