Skip to content

Commit 10cd018

Browse files
authored
Merge pull request #1 from pwndbg/zig0.16
Zig0.16
2 parents 5cad735 + 70dce15 commit 10cd018

File tree

12 files changed

+596
-211
lines changed

12 files changed

+596
-211
lines changed

.github/workflows/tests.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Tests
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
jobs:
9+
tests-linux:
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
attribute: [
14+
packages.aarch64-linux.pkgsCross.armv7l-hf-multiplatform.libdebuginfod-zig-static # arm32
15+
packages.aarch64-linux.pkgsCross.aarch64-multiplatform.libdebuginfod-zig-static # arm64
16+
packages.aarch64-linux.pkgsCross.gnu32.libdebuginfod-zig-static # x86_32
17+
packages.aarch64-linux.pkgsCross.gnu64.libdebuginfod-zig-static # x86_64
18+
packages.aarch64-linux.pkgsCross.riscv64.libdebuginfod-zig-static # riscv64
19+
packages.aarch64-linux.pkgsCross.s390x.libdebuginfod-zig-static # s390x
20+
packages.aarch64-linux.pkgsCross.powernv.libdebuginfod-zig-static # ppc64le
21+
packages.aarch64-linux.pkgsCross.ppc64.libdebuginfod-zig-static # ppc64
22+
packages.aarch64-linux.pkgsCross.loongarch64-linux.libdebuginfod-zig-static # loong64
23+
]
24+
runs-on: ubuntu-24.04-arm # aarch64-linux
25+
timeout-minutes: 30
26+
env:
27+
TMPDIR: /tmp
28+
steps:
29+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # @v3
30+
- uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # @v30
31+
with:
32+
nix_path: nixpkgs=channel:nixos-unstable
33+
34+
- name: build ${{ matrix.attribute }}
35+
run: nix build '.#${{ matrix.attribute }}' -L --accept-flake-config -o result
36+
37+
tests-darwin:
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
attribute: [
42+
packages.aarch64-darwin.static # arm64
43+
packages.x86_64-darwin.static # x86_64
44+
]
45+
runs-on: macos-15 # aarch64-darwin
46+
timeout-minutes: 30
47+
env:
48+
TMPDIR: /tmp
49+
steps:
50+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # @v3
51+
- uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # @v30
52+
with:
53+
nix_path: nixpkgs=channel:nixos-unstable
54+
55+
- name: build ${{ matrix.attribute }}
56+
run: nix build '.#${{ matrix.attribute }}' -L --accept-flake-config -o result

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ zig build -Dtarget=aarch64-macos -Doptimize=ReleaseSafe
2626

2727
# How to replace GDB debuginfod with this repo?
2828
```
29-
git clone https://github.com/pwndbg/debuginfod-zig
30-
cd debuginfod-zig
31-
zig build -Doptimize=ReleaseSafe -Dlinkage=dynamic
32-
cp ./zig-out/lib/libdebuginfo.so /usr/lib64/libdebuginfod.so.1
33-
```
34-
> NOTE1: please download zig 0.15.1 - https://ziglang.org/download/
29+
nix build github:pwndbg/debuginfod-zig/zig0.16#dynamic
30+
cp ./result/lib/libdebuginfo.so /usr/lib64/libdebuginfod.so.1
3531
36-
> NOTE2: `/usr/lib64/libdebuginfod.so.1` path depends on your distribution
32+
# OR use env `LD_PRELOAD`
33+
LD_PRELOAD=./result/lib/libdebuginfo.so /usr/bin/gdb
34+
```
35+
> NOTE1: `/usr/lib64/libdebuginfod.so.1` path depends on your distribution
3736
3837
## ENV's implemented:
3938
- DEBUGINFOD_URLS
@@ -43,11 +42,11 @@ cp ./zig-out/lib/libdebuginfo.so /usr/lib64/libdebuginfod.so.1
4342
- DEBUGINFOD_VERBOSE
4443
- DEBUGINFOD_PROGRESS
4544
- DEBUGINFOD_HEADERS_FILE
45+
- DEBUGINFOD_TIMEOUT
4646

4747
## ENV's not-implemented:
48-
- DEBUGINFOD_TIMEOUT (hard)
49-
- DEBUGINFOD_RETRY_LIMIT (easy)
5048
- DEBUGINFOD_IMA_CERT_PATH (hard?)
49+
- DEBUGINFOD_RETRY_LIMIT
5150

5251
## What is missing:
5352
- missing func debuginfod_find_metadata

build.zig

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,24 @@ const manifest = @import("build.zig.zon");
33

44
pub fn generatePkgconfig(b: *std.Build, version: std.SemanticVersion) !*std.Build.Step.InstallFile {
55
const allocator = b.allocator;
6-
const version_str = try std.fmt.allocPrint(allocator, "{d}.{d}", .{version.major, version.minor});
6+
const version_str = try std.fmt.allocPrint(allocator, "{d}.{d}", .{ version.major, version.minor });
77
const absolute_prefix = b.install_prefix;
88
if (!std.fs.path.isAbsolute(absolute_prefix)) {
99
@panic("Prefix must be absolute!");
1010
}
1111

12+
var threaded: std.Io.Threaded = .init(allocator);
13+
defer threaded.deinit();
14+
const io = threaded.io();
15+
1216
const input_file = try std.fs.cwd().openFile("upstream/libdebuginfod.pc.in", .{});
1317
defer input_file.close();
1418

1519
var aw = try std.Io.Writer.Allocating.initCapacity(allocator, 0);
1620
defer aw.deinit();
1721

1822
var buf: [0]u8 = undefined;
19-
var reader = input_file.reader(&buf);
23+
var reader = input_file.reader(io, &buf);
2024
_ = try reader.interface.stream(&aw.writer, .unlimited);
2125

2226
var text = try aw.toOwnedSlice();
@@ -26,7 +30,7 @@ pub fn generatePkgconfig(b: *std.Build, version: std.SemanticVersion) !*std.Buil
2630
text = try std.mem.replaceOwned(u8, allocator, text, "@VERSION@", version_str);
2731

2832
const tmp_dir = b.makeTempPath();
29-
const tmp_file = try std.fs.path.join(allocator, &.{tmp_dir, "libdebuginfod.pc"});
33+
const tmp_file = try std.fs.path.join(allocator, &.{ tmp_dir, "libdebuginfod.pc" });
3034
const out_file = try std.fs.cwd().createFile(tmp_file, .{});
3135
defer out_file.close();
3236
try out_file.writeAll(text);
@@ -69,7 +73,7 @@ pub fn build(b: *std.Build) !void {
6973
.root_module = lib_mod,
7074
.version = version,
7175
});
72-
if(linkage == .static) {
76+
if (linkage == .static) {
7377
lib.bundle_compiler_rt = true;
7478
lib.pie = true;
7579
}
@@ -82,7 +86,7 @@ pub fn build(b: *std.Build) !void {
8286
.root_module = lib_mod,
8387
});
8488
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
85-
89+
b.installArtifact(lib_unit_tests);
8690
const test_step = b.step("test", "Run unit tests");
8791
test_step.dependOn(&run_lib_unit_tests.step);
8892
}

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
// Tracks the earliest Zig version that the package considers to be a
3030
// supported use case.
31-
.minimum_zig_version = "0.15.1",
31+
.minimum_zig_version = "0.16.0",
3232

3333
// This field is optional.
3434
// Each dependency must either provide a `url` and `hash`, or a `path`.

flake.lock

Lines changed: 113 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
description = "debuginfo-zig";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6+
zig.url = "github:mitchellh/zig-overlay";
7+
};
8+
9+
outputs =
10+
inputs@{
11+
self,
12+
nixpkgs,
13+
zig,
14+
...
15+
}:
16+
let
17+
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
18+
lib = nixpkgs.lib;
19+
20+
fun_zig_0_16 =
21+
pkgs:
22+
(
23+
let
24+
dev_zig = zig.packages.${pkgs.stdenv.hostPlatform.system}."master-2025-11-02" // {
25+
meta = {
26+
platforms = pkgs.lib.platforms.all;
27+
broken = false;
28+
maintainers = [ ];
29+
};
30+
};
31+
dev_zig_hook = pkgs.zig.hook.override { zig = dev_zig; };
32+
in
33+
dev_zig // { hook = dev_zig_hook; }
34+
);
35+
36+
fun_libdebuginfod = pkgs: attrs: pkgs.callPackage ./pkg.nix attrs;
37+
38+
overlay = (
39+
final: prev: {
40+
dev_zig_0_16 = (fun_zig_0_16 prev);
41+
libdebuginfod-zig-static = (
42+
fun_libdebuginfod prev {
43+
flags = [ "-Dlinkage=static" ];
44+
}
45+
);
46+
libdebuginfod-zig-dynamic = (
47+
fun_libdebuginfod prev {
48+
flags = [ "-Dlinkage=dynamic" ];
49+
}
50+
);
51+
}
52+
);
53+
54+
fun_pkgs =
55+
system:
56+
import nixpkgs {
57+
inherit system;
58+
overlays = [
59+
overlay
60+
];
61+
};
62+
in
63+
{
64+
overlays.default = overlay;
65+
packages = forAllSystems (
66+
system:
67+
let
68+
pkgs = (fun_pkgs system);
69+
in
70+
{
71+
static = pkgs.libdebuginfod-zig-static;
72+
dynamic = pkgs.libdebuginfod-zig-dynamic;
73+
default = self.packages.${system}.dynamic;
74+
pkgsCross = pkgs.pkgsCross;
75+
}
76+
);
77+
develop = forAllSystems (
78+
system:
79+
let
80+
pkgs = (fun_pkgs system);
81+
in
82+
{
83+
default = pkgs.dev_zig_0_16;
84+
}
85+
);
86+
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-tree);
87+
};
88+
}

0 commit comments

Comments
 (0)