From dab3b916fe2680fb22049d464f698093bc4fb348 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 3 upstream commits These patches are required in order to integrate zig's crosscompilation features with xbps when using the zig build system. FIXME: following is only true for the --libc patch It has also landed in the 0.8.x branch upstream and will be included in the 0.8.1 release. --- .../0001-stage2-add-sysroot-link-option.patch | 120 ++++++++++++++++++ ...std-build-add-sysroot-general-option.patch | 61 +++++++++ ...03-zig-build-add-libc-general-option.patch | 65 ++++++++++ srcpkgs/zig/template | 3 +- 4 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 srcpkgs/zig/patches/0001-stage2-add-sysroot-link-option.patch create mode 100644 srcpkgs/zig/patches/0002-std-build-add-sysroot-general-option.patch create mode 100644 srcpkgs/zig/patches/0003-zig-build-add-libc-general-option.patch diff --git a/srcpkgs/zig/patches/0001-stage2-add-sysroot-link-option.patch b/srcpkgs/zig/patches/0001-stage2-add-sysroot-link-option.patch new file mode 100644 index 000000000000..76a4e8c90029 --- /dev/null +++ b/srcpkgs/zig/patches/0001-stage2-add-sysroot-link-option.patch @@ -0,0 +1,120 @@ +From 4f5376c9f934cba8172ba623f3e29792bf40f6bd Mon Sep 17 00:00:00 2001 +From: Isaac Freund +Date: Mon, 21 Jun 2021 22:45:43 +0200 +Subject: [PATCH 1/3] stage2: add --sysroot link option + +--- + src/Compilation.zig | 2 ++ + src/link.zig | 1 + + src/link/Elf.zig | 5 +++++ + src/main.zig | 11 ++++++++++- + 4 files changed, 18 insertions(+), 1 deletion(-) + +diff --git a/src/Compilation.zig b/src/Compilation.zig +index 4c015cb58..c89bf49e7 100644 +--- a/src/Compilation.zig ++++ b/src/Compilation.zig +@@ -613,6 +613,7 @@ pub const InitOptions = struct { + output_mode: std.builtin.OutputMode, + thread_pool: *ThreadPool, + dynamic_linker: ?[]const u8 = null, ++ sysroot: ?[]const u8 = null, + /// `null` means to not emit a binary file. + emit_bin: ?EmitLoc, + /// `null` means to not emit a C header file. +@@ -1271,6 +1272,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { + .module = module, + .target = options.target, + .dynamic_linker = options.dynamic_linker, ++ .sysroot = options.sysroot, + .output_mode = options.output_mode, + .link_mode = link_mode, + .object_format = ofmt, +diff --git a/src/link.zig b/src/link.zig +index fcb263f03..bb45d5d0e 100644 +--- a/src/link.zig ++++ b/src/link.zig +@@ -37,6 +37,7 @@ pub const Options = struct { + /// Not every Compilation compiles .zig code! For example you could do `zig build-exe foo.o`. + module: ?*Module, + dynamic_linker: ?[]const u8, ++ sysroot: ?[]const u8, + /// Used for calculating how much space to reserve for symbols in case the binary file + /// does not already have a symbol table. + symbol_count_hint: u64 = 32, +diff --git a/src/link/Elf.zig b/src/link/Elf.zig +index 5d99a4c3f..ee705bc1a 100644 +--- a/src/link/Elf.zig ++++ b/src/link/Elf.zig +@@ -1354,6 +1354,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { + man.hash.add(allow_shlib_undefined); + man.hash.add(self.base.options.bind_global_refs_locally); + man.hash.add(self.base.options.tsan); ++ man.hash.addOptionalBytes(self.base.options.sysroot); + + // We don't actually care whether it's a cache hit or miss; we just need the digest and the lock. + _ = try man.hit(); +@@ -1423,6 +1424,10 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { + + try argv.append("-error-limit=0"); + ++ if (self.base.options.sysroot) |sysroot| { ++ try argv.append(try std.fmt.allocPrint(arena, "--sysroot={s}", .{sysroot})); ++ } ++ + if (self.base.options.lto) { + switch (self.base.options.optimize_mode) { + .Debug => {}, +diff --git a/src/main.zig b/src/main.zig +index 9245f5fd8..662f3f64a 100644 +--- a/src/main.zig ++++ b/src/main.zig +@@ -371,6 +371,7 @@ const usage_build_generic = + \\ -T[script], --script [script] Use a custom linker script + \\ --version-script [path] Provide a version .map file + \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so) ++ \\ --sysroot [path] Set the system root directory (usually /) + \\ --version [ver] Dynamic library semver + \\ -fsoname[=name] (Linux) Override the default SONAME value + \\ -fno-soname (Linux) Disable emitting a SONAME +@@ -599,6 +600,7 @@ fn buildOutputType( + var link_eh_frame_hdr = false; + var link_emit_relocs = false; + var each_lib_rpath: ?bool = null; ++ var sysroot: ?[]const u8 = null; + var libc_paths_file: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIBC"); + var machine_code_model: std.builtin.CodeModel = .default; + var runtime_args_start: ?usize = null; +@@ -856,6 +858,10 @@ fn buildOutputType( + if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg}); + i += 1; + target_dynamic_linker = args[i]; ++ } else if (mem.eql(u8, arg, "--sysroot")) { ++ if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg}); ++ i += 1; ++ sysroot = args[i]; + } else if (mem.eql(u8, arg, "--libc")) { + if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg}); + i += 1; +@@ -1596,7 +1602,9 @@ fn buildOutputType( + want_native_include_dirs = true; + } + +- if (cross_target.isNativeOs() and (system_libs.items.len != 0 or want_native_include_dirs)) { ++ if (sysroot == null and cross_target.isNativeOs() and ++ (system_libs.items.len != 0 or want_native_include_dirs)) ++ { + const paths = std.zig.system.NativePaths.detect(arena, target_info) catch |err| { + fatal("unable to detect native system paths: {s}", .{@errorName(err)}); + }; +@@ -1873,6 +1881,7 @@ fn buildOutputType( + .is_native_os = cross_target.isNativeOs(), + .is_native_abi = cross_target.isNativeAbi(), + .dynamic_linker = target_info.dynamic_linker.get(), ++ .sysroot = sysroot, + .output_mode = output_mode, + .root_pkg = root_pkg, + .emit_bin = emit_bin_loc, +-- +2.32.0 + diff --git a/srcpkgs/zig/patches/0002-std-build-add-sysroot-general-option.patch b/srcpkgs/zig/patches/0002-std-build-add-sysroot-general-option.patch new file mode 100644 index 000000000000..a2c6d4a9f047 --- /dev/null +++ b/srcpkgs/zig/patches/0002-std-build-add-sysroot-general-option.patch @@ -0,0 +1,61 @@ +From 86604ddfc99e39fdb15a36c176d07b3bc0092c5d Mon Sep 17 00:00:00 2001 +From: Isaac Freund +Date: Mon, 21 Jun 2021 22:52:52 +0200 +Subject: [PATCH 2/3] std/build: add --sysroot general option + +--- + lib/std/build.zig | 5 +++++ + lib/std/special/build_runner.zig | 7 +++++++ + 2 files changed, 12 insertions(+) + +diff --git a/lib/std/build.zig b/lib/std/build.zig +index 572f2b2be..e28ca9485 100644 +--- a/lib/std/build.zig ++++ b/lib/std/build.zig +@@ -57,6 +57,7 @@ pub const Builder = struct { + exe_dir: []const u8, + h_dir: []const u8, + install_path: []const u8, ++ sysroot: ?[]const u8 = null, + search_prefixes: ArrayList([]const u8), + installed_files: ArrayList(InstalledFile), + build_root: []const u8, +@@ -2597,6 +2598,10 @@ pub const LibExeObjStep = struct { + } + } + ++ if (builder.sysroot) |sysroot| { ++ try zig_args.appendSlice(&[_][]const u8{ "--sysroot", sysroot }); ++ } ++ + for (builder.search_prefixes.items) |search_prefix| { + try zig_args.append("-L"); + try zig_args.append(try fs.path.join(builder.allocator, &[_][]const u8{ +diff --git a/lib/std/special/build_runner.zig b/lib/std/special/build_runner.zig +index c6185ef09..5c259b22a 100644 +--- a/lib/std/special/build_runner.zig ++++ b/lib/std/special/build_runner.zig +@@ -87,6 +87,12 @@ pub fn main() !void { + warn("Expected argument after {s}\n\n", .{arg}); + return usageAndErr(builder, false, stderr_stream); + }; ++ } else if (mem.eql(u8, arg, "--sysroot")) { ++ const sysroot = nextArg(args, &arg_idx) orelse { ++ warn("Expected argument after --sysroot\n\n", .{}); ++ return usageAndErr(builder, false, stderr_stream); ++ }; ++ builder.sysroot = sysroot; + } else if (mem.eql(u8, arg, "--search-prefix")) { + const search_prefix = nextArg(args, &arg_idx) orelse { + warn("Expected argument after --search-prefix\n\n", .{}); +@@ -189,6 +195,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void + \\ -h, --help Print this help and exit + \\ --verbose Print commands before executing them + \\ -p, --prefix [path] Override default install prefix ++ \\ --sysroot [path] Set the system root directory (usually /) + \\ --search-prefix [path] Add a path to look for binaries, libraries, headers + \\ --color [auto|off|on] Enable or disable colored error messages + \\ +-- +2.32.0 + diff --git a/srcpkgs/zig/patches/0003-zig-build-add-libc-general-option.patch b/srcpkgs/zig/patches/0003-zig-build-add-libc-general-option.patch new file mode 100644 index 000000000000..edc8fde3ca63 --- /dev/null +++ b/srcpkgs/zig/patches/0003-zig-build-add-libc-general-option.patch @@ -0,0 +1,65 @@ +From 7fc2e41f158b1ef65f80fb94abd35871e36c2b9c Mon Sep 17 00:00:00 2001 +From: Isaac Freund +Date: Sun, 13 Jun 2021 04:49:54 +0000 +Subject: [PATCH 3/3] 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 e28ca9485..c8f02d8a7 100644 +--- a/lib/std/build.zig ++++ b/lib/std/build.zig +@@ -59,6 +59,7 @@ pub const Builder = struct { + install_path: []const u8, + sysroot: ?[]const u8 = null, + search_prefixes: ArrayList([]const u8), ++ libc_file: ?[]const u8 = null, + installed_files: ArrayList(InstalledFile), + build_root: []const u8, + cache_root: []const u8, +@@ -2378,6 +2379,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 5c259b22a..d1154add0 100644 +--- a/lib/std/special/build_runner.zig ++++ b/lib/std/special/build_runner.zig +@@ -99,6 +99,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", .{}); +@@ -197,6 +203,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void + \\ -p, --prefix [path] Override default install prefix + \\ --sysroot [path] Set the system root directory (usually /) + \\ --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 96e728b572c966840870d8a2c4165774ae4f19ca 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..69dea4ca555a --- /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 \ + --sysroot "${XBPS_CROSS_BASE}" \ + --libc xbps_zig_libc.txt \ + -Dtarget=$zig_target -Dcpu=$zig_cpu \ + -Drelease-safe --prefix /usr install +} + +do_install() { + cp -r zig-out/* "${DESTDIR}" +} From fb852ac1b9c3b0abb739531e5e34e64e2be895eb 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 +}