selected := get-environment-variable("VPAC_TARGET_ARCH") arch := if string?(selected) { selected } else if memq(string->symbol("aarch64"), features()) { "aarch64" } else { "x86_64" } arm := string=?("aarch64", arch) revision := "c34a6707e1d8d3a23d0b1bfe6e6dbb16290e4f75" repo := string-append("vinix-", revision) support := string-append(repo, "/build-support") raw := string-append("https://raw.githubusercontent.com/vlang/vinix/", revision) defpkgbuild(vinix-desktop-init, #:pkgname, "vinix-desktop-init", #:pkgver, "20261128", #:pkgrel, if arm { 2 } else { 1 }, #:pkgdesc, "Vinix desktop PID 1 for the default release image", #:arch, [#:x86-64, #:aarch64], #:url, "https://github.com/vlang/vinix", #:license, "GPL-2.0-only", #:depends, ["busybox", "zsh", "vinix-filesystem"], #:provides, ["init"], #:conflicts, ["busybox-init"], #:source, if arm { list(string-append(repo, ".tar.gz::https://codeload.github.com/vlang/vinix/tar.gz/", revision), "check-init.py") } else { list(string-append(raw, "/build-support/init-amd64/desktop-init"), string-append(raw, "/LICENSE")) }, #:sha256sums, if arm { list("e57193f3e7f0f6f578c0dae03789bf0616c88c7b1fb87c11b141c760a97cce6e", "4457061065c264efa2308fbb8f8162395b5b96c838baddcc02af7430bd5dbbd9") } else { list("167b40c6491947b9ddb5330fa7cf1e02d5a636eb6569ee3d6c6150d4d0fd94a4", "8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643") }, #:build, fn() { if arm { init := string-append(support, "/init-aarch64") host-libraries := get-environment-variable("VINIX_HOST_LIBRARY_PATH") run("env", string-append("LIBRARY_PATH=", if string?(host-libraries) { host-libraries } else { "" }), string-append(support, "/run-v-tool.sh"), string-append(init, "/compile_init.v"), "desktop", string-append(srcdir(), "/desktop-init.c")) ; The raw syscall implementation supplies its own stdio and memory ABI. ; Use Clang's freestanding headers for stdint and stddef. run("clang", "--target=aarch64-linux-none", "-nostdlibinc", "-nostdlib", "-ffreestanding", "-O2", "-fno-stack-protector", "-fno-builtin", "-ffunction-sections", "-fdata-sections", "-I", init, "-c", "desktop-init.c", "-o", "desktop-init.o") run("clang", "--target=aarch64-linux-none", "-c", string-append(init, "/syscall_abi.S"), "-o", "syscall_abi.o") run("ld.lld", "-m", "aarch64elf", "--nostdlib", "-static", "--gc-sections", "-z", "max-page-size=16384", "-o", "desktop-init", "desktop-init.o", "syscall_abi.o") } }, #:check, fn() { if arm { run("python3", "check-init.py") } else { run("sh", "-n", "desktop-init") } }, #:package, fn() { run("install", "-Dm755", "desktop-init", string-append(pkgdir(), "/sbin/init")) if arm { run("install", "-Dm755", "desktop-init", string-append(pkgdir(), "/usr/libexec/vinix-desktop-init")) } license-file := if arm { string-append(repo, "/LICENSE") } else { "LICENSE" } run("install", "-Dm644", license-file, string-append(pkgdir(), "/usr/share/licenses/vinix-desktop-init/LICENSE")) })