| 1 | // Build the two release X11 bridges from the pinned Vinix modules. |
| 2 | module main |
| 3 | |
| 4 | import os |
| 5 | |
| 6 | fn run(command string, args []string) ! { |
| 7 | path := os.find_abs_path_of_executable(command)! |
| 8 | mut child := os.new_process(path) |
| 9 | child.set_args(args) |
| 10 | child.run() |
| 11 | child.wait() |
| 12 | defer { child.close() } |
| 13 | if child.code != 0 { |
| 14 | return error('${command} failed with exit status ${child.code}') |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | fn compile_bridge(name string, binary string, arch string, root string) ! { |
| 19 | os.mkdir_all('${name}-build/${name}')! |
| 20 | os.write_file('${name}-build/v.mod', "Module { name: 'x11_bridge' }\n")! |
| 21 | os.write_file('${name}-build/entry.v', 'module main\nimport ${name} as _\n')! |
| 22 | for file in ['core', 'native'] { |
| 23 | os.cp('${name}-${file}.v', '${name}-build/${name}/${file}.v')! |
| 24 | } |
| 25 | mut flags := ['-shared', '-no-builtin', '-no-closures', '-os', 'vinix', '-arch', arch, |
| 26 | '-target-libc-headers', '-gc', 'none', '-manualfree'] |
| 27 | mut libs := ['-lXtst', '-lX11', '-lXext', '-lxcb'] |
| 28 | if name == 'winehost' { |
| 29 | os.cp('winehost-package.v', 'winehost-build/winehost/package.v')! |
| 30 | os.mkdir_all('winehost-build/x11auth')! |
| 31 | os.cp('auth.v', 'winehost-build/x11auth/auth.v')! |
| 32 | flags << ['-d', 'x11_host_libc'] |
| 33 | libs << '-lXdamage' |
| 34 | } |
| 35 | flags << ['-o', '${binary}.c', '${name}-build'] |
| 36 | run('v', flags)! |
| 37 | mut cc := ['-std=gnu11', '-O2', '-D__vinix__', '-DVINIX_XINPUT_V_RUNTIME=1', '-I.', |
| 38 | '-ffreestanding', '-fno-builtin', '-fwrapv', '-fno-strict-aliasing', '-static-libgcc', |
| 39 | '-Wl,-rpath-link,${root}/usr/lib', '-Wl,-rpath-link,${root}/lib', '${binary}.c'] |
| 40 | cc << libs |
| 41 | cc << ['-o', binary] |
| 42 | run('vinix-cc', cc)! |
| 43 | } |
| 44 | |
| 45 | fn release_config(script string, marker string, name string) ! { |
| 46 | start := "<< '${marker}'\n" |
| 47 | end := '\n${marker}\n' |
| 48 | if script.count(start) != 1 { |
| 49 | return error('expected a single ${marker} configuration in the Vinix release script') |
| 50 | } |
| 51 | body := script.all_after(start) |
| 52 | if !body.contains(end) { |
| 53 | return error('unterminated ${marker} configuration') |
| 54 | } |
| 55 | os.write_file(name, body.all_before(end) + '\n')! |
| 56 | } |
| 57 | |
| 58 | fn build() ! { |
| 59 | target := os.getenv_opt('VPAC_TARGET_ARCH') or { os.uname().machine } |
| 60 | arch := match target { |
| 61 | 'x86_64' { 'amd64' } |
| 62 | 'aarch64' { 'arm64' } |
| 63 | else { return error('unsupported X11 bridge target ${target}') } |
| 64 | } |
| 65 | root := os.getenv('VPAC_MAKEPKG_ROOT') |
| 66 | compile_bridge('xinputcore', 'vinix-xinput', arch, root)! |
| 67 | compile_bridge('winehost', 'vinix-wine-host', arch, root)! |
| 68 | script := os.read_file('build-x11-aarch64.sh')! |
| 69 | release_config(script, 'XORGEOF', 'xorg.conf')! |
| 70 | release_config(script, 'XINITEOF', 'xinitrc')! |
| 71 | } |
| 72 | |
| 73 | fn main() { |
| 74 | build() or { |
| 75 | eprintln(err) |
| 76 | exit(1) |
| 77 | } |
| 78 | } |
| 79 | |