Skip to content
New issue

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

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

Already on GitHub? # to your account

Build issue on Ubuntu #14

Open
mikemadden42 opened this issue Oct 3, 2024 · 12 comments
Open

Build issue on Ubuntu #14

mikemadden42 opened this issue Oct 3, 2024 · 12 comments
Assignees
Labels
bug Something isn't working Linux

Comments

@mikemadden42
Copy link

Does anyone else see this build issue on Ubuntu?

$ zig build
...
...
+- install DOOM-fire
   +- zig build-exe DOOM-fire Debug native 1 errors
/home/hulk/opt/zig-linux-x86_64-0.13.0/lib/std/c.zig:1677:12: error: dependency on libc must be explicitly specified in the build command
error: the following command failed with 1 compilation errors:
/home/hulk/opt/zig-linux-x86_64-0.13.0/zig build-exe -ODebug -Mroot=/home/hulk/src/DOOM-fire-zig/src/main.zig --cache-dir /home/hulk/src/DOOM-fire-zig/.zig-cache --global-cache-dir /home/hulk/.cache/zig --name DOOM-fire --listen=-
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
+- install DOOM-fire transitive failure
   +- zig build-exe DOOM-fire Debug native 1 errors
error: the following build command failed with exit code 1:
/home/hulk/src/DOOM-fire-zig/.zig-cache/o/465c6d43a52f00a87203cf9a087d4a87/build /home/hulk/opt/zig-linux-x86_64-0.13.0/zig /home/hulk/src/DOOM-fire-zig /home/hulk/src/DOOM-fire-zig/.zig-cache /home/hulk/.cache/zig --seed 0xa793b191 -Zc2b19a024407fa82
$ zig version
0.13.0
$ lsb_release -sir
Ubuntu
22.04
@sweetbbak
Copy link

you have to add exe.linkLibC(); to the build.zig file, but it also adds a segfault

thread 1670123 panic: index out of bounds: index 51135, len 6552
/home/sweet/repos/DOOM-fire-zig/src/main.zig:623:39: 0x103e193 in showDoomFire (DOOM-fire)
                spread_px = screen_buf[doFire_idx];
                                      ^
/home/sweet/repos/DOOM-fire-zig/src/main.zig:695:17: 0x103b5e9 in main (DOOM-fire)
    showDoomFire();
                ^
/usr/lib/zig/std/start.zig:524:37: 0x103b0fe in main (DOOM-fire)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x71a86cc38e07 in ??? (libc.so.6)
Unwind information for `libc.so.6:0x71a86cc38e07` was not available, trace may be incomplete

???:?:?: 0x71a86cc38ecb in ??? (libc.so.6)
???:?:?: 0x103ad44 in ??? (???)
zsh: IOT instruction (core dumped)  ./zig-out/bin/DOOM-fire

@const-void
Copy link
Owner

Thanks for reporting! I will do some sleuthing.

@const-void const-void self-assigned this Oct 13, 2024
@mikemadden42
Copy link
Author

Thanks @const-void . The follow diff fixes the build issues I hit on Ubuntu. I'm not sure if this also works on macOS & other supported platforms.

index 2c1639c..29ece06 100644
--- a/build.zig
+++ b/build.zig
@@ -22,6 +22,8 @@ pub fn build(b: *std.Build) void {
         .optimize = optimize,
     });
 
+    exe.linkLibC();
+
     // This declares intent for the executable to be installed into the
     // standard location when the user invokes the "install" step (the default
     // step when running `zig build`).
diff --git a/src/main.zig b/src/main.zig
index b2864e3..167136b 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -5,6 +5,7 @@
 //
 const builtin = @import("builtin");
 const std = @import("std");
+const libc = @import("libc");
 
 const allocator = std.heap.page_allocator;

@kruthers64
Copy link

FYI, someone fixed the linux build and crash in a fork. At least this worked for me on Linux Mint 20.3, building w/ zig 0.13.0:

https://github.com/moderation/DOOM-fire-zig

@const-void const-void added the bug Something isn't working label Jan 3, 2025
@const-void const-void pinned this issue Jan 3, 2025
@const-void
Copy link
Owner

const-void commented Jan 3, 2025

Using multipass on OSX, adding LibC to compilation with a release mode results in a successful / operational DOOM-fire-zig. However, when in debug mode, there is a panic but alas, my very lazy error handling is not being very helpful. This will take me a moment or two to think about ... how should errors be handled and reported.

@const-void const-void reopened this Jan 3, 2025
@const-void
Copy link
Owner

const-void commented Jan 5, 2025

This is fascinating. The lldb operatable variant has been stashed in the error-handling branch if anyone wants to check it out.

Building debug in OSX Multipass (zig build run -Doptimize=Debug) there is an array panic that is quite interesting:

    while (ok) {

        //update fire buf
        doFire_x = 0;
        while (doFire_x < FIRE_W) : (doFire_x += 1) {
            doFire_y = 0;
            while (doFire_y < FIRE_H) : (doFire_y += 1) {
                doFire_idx = doFire_y * FIRE_W + doFire_x;

                //spread fire
                spread_px = screen_buf[doFire_idx];//<--BOOM, HERE
                
                ...blah blah blah...

            }
        }

Somehow, doFire_x is far exceeding FIRE_H, causing the resulting doFire_idx to exceed array limits (20k and change).

lldb-DOOM-fire-zig

Building release in OSX Multipass (zig build run -Doptimize=ReleaseFast) (or any other mode), there is no panic.

I am not at all sure why this is...yet. doFire_X value of 1230769 doesn't jump out as a bounds or wrapping issue. I can't imagine the while condition is a problem...however the scope is so limited, just the particular while block snipped above.

On the surface, it seems...quite simple. Perhaps multipass or zig or libc or the M1 ARM chipset is some factor. The debug vs release mode is a strong clue something else is happening, and it just so happens to be exhibited here. However, this is a single-threaded process...so...more investigation is needed!

The error-handling branch is available for any who wishes to try and see!

  $ git fetch origin
  $ git checkout error-handling

or

$ git clone -b error-handling  https://github.com/const-void/DOOM-fire-zig.git

@sweetbbak
Copy link

I wonder if using a saturating operator would help prevent that? +%= or +|= etc... It might cause weird rendering issues though. I'll check it out since now I am curious

@const-void
Copy link
Owner

Adding a few choice std.debug.print ...

std.debug.print("\n\nN: x = {d}, y = {d}\n", .{ doFire_x, doFire_y }); //++
while (doFire_x < FIRE_W) : (doFire_x = doFire_x + 1) {
  doFire_y = 0;
  while (doFire_y < FIRE_H) : (doFire_y += 1) {
    std.debug.print("{d},{d} ", .{ doFire_x, doFire_y }); // ++

    doFire_idx = doFire_y * FIRE_W + doFire_x; 

    //spread fire
    spread_px = screen_buf[doFire_idx] ;// BOOM

then: zig build run 2>err.txt =>

N: x = 0, y = 0 #new screen - first screen

0,0 0,1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 0,10 0,11 0,12 0,13 0,14 0,15 0,16 0,17 0,18 0,19 0,20 0,21 0,22 0,23 0,24 0,25 0,26 0,27 0,28 0,29 0,30 0,
31 0,32 0,33 0,34 0,35 0,36 0,37 0,38 0,39 0,40 0,41 0,42 0,43 0,44 0,45 0,46 0,47 0,48 0,49 0,50 0,51
"thread 1041596 panic: index out of bounds: index 316659348806830, len 7644" #/BOOM

I can't quite imagine how x=0, y=51 gets mangled so badly. Adding additional debug statements prevents the panic, so clearly something else is overriding the pointer boundary. -j1 doesn't change things.

I am wondering if OSX M* + ubuntu multipass + zig 0.13 + libc is too much...something about the build from a system pov is a mismatch. I may need to investigate a proper ubuntu build...somehow???

@sweetbbak
Copy link

good ol' fashion printf debugging lmao Im using Linux and everything seems fine on the error handling branch.

@const-void
Copy link
Owner

Folded into main....may not be perfect, but hopefully still better!

@WalterClementsJr
Copy link

Hello, I checked out error-handling branch, still no avail.
Running zig build on Fedora 40, zig 0.13.0:

install
└─ install DOOM-fire
   └─ zig build-exe DOOM-fire Debug native 1 errors
src/main.zig:205:45: error: expected type 'i32', found 'fs.File'
                const lldb_rv = std.c.ioctl(lldb_tty_nix, TIOCGWINSZ, @intFromPtr(&lldb_winsz));
                                            ^~~~~~~~~~~~
/usr/lib/zig/std/fs/File.zig:1:1: note: struct declared here
/// The OS-specific file descriptor or file handle.
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/lib/zig/std/c.zig:1677:30: note: parameter type declared here
pub extern "c" fn ioctl(fd: c.fd_t, request: c_int, ...) c_int;
                            ~^~~~~
referenced by:
    initTermSize: src/main.zig:227:19
    initTerm: src/main.zig:233:9
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
error: the following command failed with 1 compilation errors:
/usr/bin/zig build-exe -ODebug -Mroot=/home/walker/projects/DOOM-fire-zig/src/main.zig -lc --cache-dir /home/walker/projects/DOOM-fire-zig/.zig-cache --global-cache-dir /home/walker/.cache/zig --name DOOM-fire --listen=- 
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install DOOM-fire transitive failure
   └─ zig build-exe DOOM-fire Debug native 1 errors
error: the following build command failed with exit code 1:
/home/walker/projects/DOOM-fire-zig/.zig-cache/o/99794b4aa7a839a86d3af8d61170cd7f/build /usr/bin/zig /home/walker/projects/DOOM-fire-zig /home/walker/projects/DOOM-fire-zig/.zig-cache /home/walker/.cache/zig --seed 0xf87ecb0b -Z4f04df39f627b546

@const-void
Copy link
Owner

Hello, I checked out error-handling branch, still no avail. Running zig build on Fedora 40, zig 0.13.0:

Thank you! Could you try main? This glitch might be fixed now.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working Linux
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

5 participants