Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype zig package manager integration #1395

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/cbuild/build_style/zig_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from cbuild.util import zig_build


def do_build(self):
zig_build.build(self, self.zig_build_args)


def do_install(self):
zig_build.install(self)


def use(tmpl):
tmpl.do_build = do_build
tmpl.do_install = do_install
5 changes: 5 additions & 0 deletions src/cbuild/build_style/zig_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from cbuild.util import zig_package


def use(tmpl):
tmpl.do_install = zig_package.install
3 changes: 3 additions & 0 deletions src/cbuild/core/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ def find(self, path, pattern, files=False):
("go_mod_dl", None, str, False, False, False),
("go_build_tags", [], list, False, False, False),
("go_check_tags", [], list, False, False, False),
# zig
("zig_build_args", [], list, False, False, False),
]

# a field priority list, the second element indicates whether
Expand Down Expand Up @@ -521,6 +523,7 @@ def find(self, path, pattern, files=False):
("make_check_env", True),
("make_check_wrapper", True),
("make_use_env", True),
("zig_build_args", True),
("cmake_dir", False),
("meson_dir", False),
("hostmakedepends", True),
Expand Down
54 changes: 54 additions & 0 deletions src/cbuild/util/zig_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
def build(pkg, extra_args=[]):
profile = pkg.profile()
sysroot = profile.sysroot
with open(pkg.cwd / "cbuild_zig_libc.txt", mode="w") as f:
f.write(
f"""include_dir={sysroot}/usr/include
sys_include_dir={sysroot}/usr/include
crt_dir={sysroot}/lib
msvc_lib_dir=
kernel32_lib_dir=
gcc_dir=

"""
)

zig_arch = None
zig_cpu = None
match profile.arch:
# TODO other architectures
case "x86_64" | "aarch64":
zig_arch = profile.arch
zig_cpu = "baseline"

# The Zig build system only has a single install step, there is no
# way to build artifacts for a given prefix and then install those artifacts
# to that prefix at some later time. Therefore, we build and install to the zig-out
# directory and later copy the artifacts to the destdir in do_install().
# We use zig-out to avoid path conflicts as it is the default install
# prefix used by the zig build system.
pkg.do(
"zig",
"build",
"-j" + str(pkg.make_jobs),
"--sysroot",
sysroot,
"--libc",
"cbuild_zig_libc.txt",
"--search-prefix",
"/usr",
"--prefix",
"/usr",
"--system",
sysroot / "usr/src/zig/packages",
"--release=safe",
ifreund marked this conversation as resolved.
Show resolved Hide resolved
f"-Dtarget={zig_arch}-linux-musl",
f"-Dcpu={zig_cpu}",
*extra_args,
env={"DESTDIR": "zig-out"},
)


def install(pkg):
for x in (pkg.cwd / "zig-out").iterdir():
pkg.install_files(x, ".")
18 changes: 18 additions & 0 deletions src/cbuild/util/zig_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def install(pkg):
zig_pkg_hash = (
pkg.do(
"zig",
"fetch",
"--global-cache-dir",
".zig-cache",
".",
capture_output=True,
)
.stdout.strip()
.decode("utf-8")
)

pkg.install_files(
".zig-cache/p/" + zig_pkg_hash,
"usr/src/zig/packages/",
)
30 changes: 30 additions & 0 deletions user/waylock/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
pkgname = "waylock"
pkgver = "1.2.0"
pkgrel = 0
build_style = "zig_build"
zig_build_args = ["-Dpie", "-Dstrip"]
hostmakedepends = [
"zig",
"pkgconf",
# TODO this should be wayland-progs, not wayland-devel but the
# wayland-scanner.pc file is in the wrong package
"wayland-devel",
"wayland-protocols",
]
makedepends = [
"libxkbcommon-devel",
"linux-pam-devel",
"wayland-devel",
"zig-wayland",
"zig-xkbcommon",
]
pkgdesc = "Small screenlocker for Wayland compositors"
maintainer = "Isaac Freund <[email protected]>"
license = "ISC"
url = "https://codeberg.org/ifreund/waylock"
source = f"https://codeberg.org/ifreund/waylock/releases/download/v{pkgver}/waylock-{pkgver}.tar.gz"
sha256 = "343fbb043bea54f5fd93e9fdb3ef441e6bfada60e8bf754d840a20e985689582"


def post_install(self):
self.install_license("LICENSE")
15 changes: 15 additions & 0 deletions user/zig-wayland/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pkgname = "zig-wayland"
pkgver = "0.2.0"
pkgrel = 0
build_style = "zig_package"
hostmakedepends = ["zig"]
pkgdesc = "Zig bindings for libwayland"
maintainer = "Isaac Freund <[email protected]>"
license = "MIT"
url = "https://codeberg.org/ifreund/zig-wayland"
source = f"{url}/archive/v{pkgver}.tar.gz"
sha256 = "831ce41cb0aad8da97de5e27125cbdd80454e5da8fd52aa78e918c0e0c784d70"


def post_install(self):
self.install_license("LICENSE")
15 changes: 15 additions & 0 deletions user/zig-xkbcommon/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pkgname = "zig-xkbcommon"
pkgver = "0.2.0"
pkgrel = 0
build_style = "zig_package"
hostmakedepends = ["zig"]
pkgdesc = "Zig bindings for xkbcommon"
maintainer = "Isaac Freund <[email protected]>"
license = "MIT"
url = "https://codeberg.org/ifreund/zig-xkbcommon"
source = f"{url}/archive/v{pkgver}.tar.gz"
sha256 = "7f9a04254e62daa795377181ae741cab31090a2393ee5e1a93b190ea0c39707d"


def post_install(self):
self.install_license("LICENSE")
Loading