From 7b4b59733cef0929a4afc3e9617ee6c50b2146e9 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 17 Jun 2021 16:13:02 +0000 Subject: [PATCH 1/3] zig: backport upstream commit fb0ecdb This patch is required in order to integrate zig's crosscompilation features with xbps when using the zig build system. It has also landed in the 0.8.x branch upstream and will be included in the 0.8.1 release. --- ...01-zig-build-add-libc-general-option.patch | 65 +++++++++++++++++++ srcpkgs/zig/template | 3 +- 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 srcpkgs/zig/patches/0001-zig-build-add-libc-general-option.patch diff --git a/srcpkgs/zig/patches/0001-zig-build-add-libc-general-option.patch b/srcpkgs/zig/patches/0001-zig-build-add-libc-general-option.patch new file mode 100644 index 000000000000..04a8e7adfb10 --- /dev/null +++ b/srcpkgs/zig/patches/0001-zig-build-add-libc-general-option.patch @@ -0,0 +1,65 @@ +From fd3c7ba42ec021917951a57e2f20f45ffe677368 Mon Sep 17 00:00:00 2001 +From: Isaac Freund +Date: Sun, 13 Jun 2021 04:49:54 +0000 +Subject: [PATCH] zig build: add --libc general option + +This new option sets a default libc paths file to be used for all +LibExeObjSteps. Setting LibExeObjStep.libc_file overrides this default. + +This is required to allow users to cross compile projects linking system +libraries without needing to patch the build.zig. +--- + lib/std/build.zig | 4 ++++ + lib/std/special/build_runner.zig | 7 +++++++ + 2 files changed, 11 insertions(+) + +diff --git a/lib/std/build.zig b/lib/std/build.zig +index 572f2b2be..366444235 100644 +--- a/lib/std/build.zig ++++ b/lib/std/build.zig +@@ -58,6 +58,7 @@ pub const Builder = struct { + h_dir: []const u8, + install_path: []const u8, + search_prefixes: ArrayList([]const u8), ++ libc_file: ?[]const u8 = null, + installed_files: ArrayList(InstalledFile), + build_root: []const u8, + cache_root: []const u8, +@@ -2377,6 +2378,9 @@ pub const LibExeObjStep = struct { + if (self.libc_file) |libc_file| { + try zig_args.append("--libc"); + try zig_args.append(builder.pathFromRoot(libc_file)); ++ } else if (builder.libc_file) |libc_file| { ++ try zig_args.append("--libc"); ++ try zig_args.append(libc_file); + } + + switch (self.build_mode) { +diff --git a/lib/std/special/build_runner.zig b/lib/std/special/build_runner.zig +index c6185ef09..2a0ca86d7 100644 +--- a/lib/std/special/build_runner.zig ++++ b/lib/std/special/build_runner.zig +@@ -93,6 +93,12 @@ pub fn main() !void { + return usageAndErr(builder, false, stderr_stream); + }; + builder.addSearchPrefix(search_prefix); ++ } else if (mem.eql(u8, arg, "--libc")) { ++ const libc_file = nextArg(args, &arg_idx) orelse { ++ warn("Expected argument after --libc\n\n", .{}); ++ return usageAndErr(builder, false, stderr_stream); ++ }; ++ builder.libc_file = libc_file; + } else if (mem.eql(u8, arg, "--color")) { + const next_arg = nextArg(args, &arg_idx) orelse { + warn("expected [auto|on|off] after --color", .{}); +@@ -190,6 +196,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void + \\ --verbose Print commands before executing them + \\ -p, --prefix [path] Override default install prefix + \\ --search-prefix [path] Add a path to look for binaries, libraries, headers ++ \\ --libc [file] Provide a file which specifies libc paths + \\ --color [auto|off|on] Enable or disable colored error messages + \\ + \\Project-Specific Options: +-- +2.32.0 + diff --git a/srcpkgs/zig/template b/srcpkgs/zig/template index baefd41af01e..4af7c098c384 100644 --- a/srcpkgs/zig/template +++ b/srcpkgs/zig/template @@ -1,7 +1,7 @@ # Template file for 'zig' pkgname=zig version=0.8.0 -revision=1 +revision=2 archs="x86_64* aarch64*" build_style=cmake make_cmd=make @@ -14,6 +14,7 @@ distfiles="https://ziglang.org/download/${version}/zig-${version}.tar.xz" checksum=03a828d00c06b2e3bb8b7ff706997fd76bf32503b08d759756155b6e8c981e77 nopie=yes nocross=yes +patch_args=-Np1 export CMAKE_GENERATOR="Unix Makefiles" From 2c382a3b61b67c9b64a2a47bc752bc300681be67 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 17 Jun 2021 16:20:30 +0000 Subject: [PATCH 2/3] build-styles: add zig-build We call this "zig-build" instead of just "zig" as this build-style relies on usage of the zig build system. In the future, other build systems such as meson may support zig code as well. Furthermore, the zig build system may be used to build C/C++ code as well, not just zig. --- common/build-style/zig-build.sh | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 common/build-style/zig-build.sh diff --git a/common/build-style/zig-build.sh b/common/build-style/zig-build.sh new file mode 100644 index 000000000000..9cf4a66a6a3d --- /dev/null +++ b/common/build-style/zig-build.sh @@ -0,0 +1,49 @@ +do_build() { + local zig_abi + local zig_target + local zig_cpu + + case $XBPS_TARGET_LIBC in + glibc) zig_abi="gnu";; + musl) zig_abi="musl";; + *) broken="Unknown target libc";; + esac + + case $XBPS_TARGET_MACHINE in + aarch64*|i686*|x86_64*) + zig_target="${XBPS_TARGET_MACHINE%-musl}-linux-${zig_abi}" zig_cpu="baseline";; + armv6l*) zig_target="arm-linux-${zig_abi}" zig_cpu="generic+v6";; + armv7l*) zig_target="arm-linux-${zig_abi}" zig_cpu="generic+v7a";; + ppc64le*) zig_target="powerpc64le-linux-${zig_abi}" zig_cpu="baseline";; + ppc64*) zig_target="powerpc64-linux-${zig_abi}" zig_cpu="baseline";; + ppcle*) zig_target="powerpcle-linux-${zig_abi}" zig_cpu="baseline";; + ppc*) zig_target="powerpc-linux-${zig_abi}" zig_cpu="baseline";; + *) broken="TODO: support more target machines for the zig build style";; + esac + + # Inform zig of the required libc include paths. + cat > xbps_zig_libc.txt <<-EOF + include_dir=${XBPS_CROSS_BASE}/usr/include + sys_include_dir=${XBPS_CROSS_BASE}/usr/include + crt_dir=${XBPS_CROSS_BASE}/usr/lib + msvc_lib_dir= + kernel32_lib_dir= + gcc_dir= + EOF + + # 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. + DESTDIR="zig-out" zig build \ + --search-prefix "${XBPS_CROSS_BASE}/usr" \ + --libc xbps_zig_libc.txt \ + -Dtarget=$zig_target -Dcpu=$zig_cpu \ + -Drelease-safe --prefix /usr install +} + +do_install() { + cp -r zig-out/* "${DESTDIR}" +} From e81d98f4509563dacdf6bf8e107b71df097813fd Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 17 Jun 2021 01:40:15 +0000 Subject: [PATCH 3/3] New package: rundird-0.1.1 --- srcpkgs/rundird/files/rundird/run | 2 ++ srcpkgs/rundird/template | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 srcpkgs/rundird/files/rundird/run create mode 100644 srcpkgs/rundird/template diff --git a/srcpkgs/rundird/files/rundird/run b/srcpkgs/rundird/files/rundird/run new file mode 100644 index 000000000000..df06fdb0fc88 --- /dev/null +++ b/srcpkgs/rundird/files/rundird/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec /usr/bin/rundird diff --git a/srcpkgs/rundird/template b/srcpkgs/rundird/template new file mode 100644 index 000000000000..c2c855164783 --- /dev/null +++ b/srcpkgs/rundird/template @@ -0,0 +1,17 @@ +# Template file for 'rundird' +pkgname=rundird +version=0.1.1 +revision=1 +build_style=zig-build +hostmakedepends="zig" +makedepends="pam-devel" +short_desc="Simple daemon + PAM module providing an XDG_RUNTIME_DIR" +maintainer="Isaac Freund " +license="GPL-3.0-or-later" +homepage="https://github.com/ifreund/rundird" +distfiles="${homepage}/archive/v${version}.tar.gz" +checksum=d3a848fba0016841385aab57298164ba8f30377799c217b6b6abf83ce1d2ca91 + +post_install() { + vsv rundird +}