| 1 | selected := get-environment-variable("VPAC_TARGET_ARCH") |
| 2 | arch := if string?(selected) { selected } else if memq(string->symbol("aarch64"), features()) { "aarch64" } else { "x86_64" } |
| 3 | arm := string=?("aarch64", arch) |
| 4 | revision := if arm { "7f173671b6d1f1a8ceda2c693eadbb0eb58c4aa4" } else { "c34a6707e1d8d3a23d0b1bfe6e6dbb16290e4f75" } |
| 5 | repo := string-append("vinix-", revision) |
| 6 | support := string-append(repo, "/build-support") |
| 7 | raw := string-append("https://raw.githubusercontent.com/vlang/vinix/", revision) |
| 8 | |
| 9 | defpkgbuild(vinix-desktop-init, |
| 10 | #:pkgname, "vinix-desktop-init", |
| 11 | #:pkgver, if arm { "20261130" } else { "20261128" }, |
| 12 | #:pkgrel, 1, |
| 13 | #:pkgdesc, "Vinix desktop PID 1 for the default release image", |
| 14 | #:arch, [#:x86-64, #:aarch64], |
| 15 | #:url, "https://github.com/vlang/vinix", |
| 16 | #:license, "GPL-2.0-only", |
| 17 | #:depends, ["busybox", "zsh", "vinix-filesystem"], |
| 18 | #:provides, ["init"], |
| 19 | #:conflicts, ["busybox-init"], |
| 20 | #:source, if arm { |
| 21 | list(string-append(repo, ".tar.gz::https://codeload.github.com/vlang/vinix/tar.gz/", revision), "check-init.py") |
| 22 | } else { |
| 23 | list(string-append(raw, "/build-support/init-amd64/desktop-init"), string-append(raw, "/LICENSE")) |
| 24 | }, |
| 25 | #:sha256sums, if arm { |
| 26 | list("4ee336414b9b1228be8f4ac8ea691914e71bf5ae34e9db40da66741ea4ffbded", |
| 27 | "84b1cce0288d66b83b3eb663fe80de1a1da2c1d429c002e4aabdf08d009692e4") |
| 28 | } else { |
| 29 | list("167b40c6491947b9ddb5330fa7cf1e02d5a636eb6569ee3d6c6150d4d0fd94a4", |
| 30 | "8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643") |
| 31 | }, |
| 32 | #:build, fn() { |
| 33 | if arm { |
| 34 | init := string-append(support, "/init-aarch64") |
| 35 | host-libraries := get-environment-variable("VINIX_HOST_LIBRARY_PATH") |
| 36 | run("env", string-append("LIBRARY_PATH=", if string?(host-libraries) { host-libraries } else { "" }), |
| 37 | string-append(support, "/run-v-tool.sh"), string-append(init, "/compile_init.v"), |
| 38 | "desktop", string-append(srcdir(), "/desktop-init.c")) |
| 39 | ; The raw syscall implementation supplies its own stdio and memory ABI. |
| 40 | ; Use Clang's freestanding headers for stdint and stddef. |
| 41 | run("clang", "--target=aarch64-linux-none", "-nostdlibinc", |
| 42 | "-nostdlib", "-ffreestanding", "-O2", |
| 43 | "-fno-stack-protector", "-fno-builtin", "-ffunction-sections", "-fdata-sections", |
| 44 | "-I", init, "-c", "desktop-init.c", "-o", "desktop-init.o") |
| 45 | run("clang", "--target=aarch64-linux-none", "-c", string-append(init, "/syscall_abi.S"), "-o", "syscall_abi.o") |
| 46 | run("ld.lld", "-m", "aarch64elf", "--nostdlib", "-static", "--gc-sections", "-z", "max-page-size=16384", |
| 47 | "-o", "desktop-init", "desktop-init.o", "syscall_abi.o") |
| 48 | run("v", "-os", "linux", "-arch", "arm64", "-gc", "none", "-manualfree", |
| 49 | "-d", "no_backtrace", "-d", "no_segfault_handler", "-o", "desktop-watchdog.c", |
| 50 | string-append(init, "/desktopwatch/main.v")) |
| 51 | run("vinix-cc", "-D_GNU_SOURCE", "-O2", "-static", "-fno-stack-protector", |
| 52 | "-o", "desktop-watchdog", "desktop-watchdog.c") |
| 53 | } |
| 54 | }, |
| 55 | #:check, fn() { |
| 56 | if arm { run("python3", "check-init.py") } else { run("sh", "-n", "desktop-init") } |
| 57 | }, |
| 58 | #:package, fn() { |
| 59 | run("install", "-Dm755", "desktop-init", string-append(pkgdir(), "/sbin/init")) |
| 60 | if arm { |
| 61 | run("install", "-Dm755", "desktop-init", string-append(pkgdir(), "/usr/libexec/vinix-desktop-init")) |
| 62 | run("install", "-Dm755", "desktop-watchdog", string-append(pkgdir(), "/usr/libexec/vinix-desktop-watchdog")) |
| 63 | } |
| 64 | license-file := if arm { string-append(repo, "/LICENSE") } else { "LICENSE" } |
| 65 | run("install", "-Dm644", license-file, string-append(pkgdir(), "/usr/share/licenses/vinix-desktop-init/LICENSE")) |
| 66 | }) |
| 67 | |