#importing, running examples raylib 0.12dev version WSL2 ubuntu windows 11

1 messages · Page 1 of 1 (latest)

noble vapor
#

Ubuntu 22.04.4

I can run/build/init. I just cant import
I get this weird message already mentioned in github issues:

All your codebase are belong to us.
Run `zig build test` to run the tests.```
#
install transitive failure
└─ install raylib-example transitive failure
   └─ zig build-exe raylib-example Debug native transitive failure
      ├─ zig build-lib raygui Debug native transitive failure
      │  └─ zig build-lib raylib Debug native failure
      └─ zig build-lib raylib Debug native (+1 more reused dependencies)
error: the following build command failed with exit code 1:
/home/joe/td/raylib/raylib-zig/raylib-example/zig-cache/o/4cc65830e3ac586ba943015441152c1f/build /home/joe/zig-linux-x86_64-0.12.0-dev.3125+a7a5f4cf4/zig /home/joe/td/raylib/raylib-zig/raylib-example /home/joe/td/raylib/raylib-zig/raylib-example/zig-cache /home/joe/.cache/zig --seed 0x5ebbc77b -Z73dc07f0791d8dce```
#
compact dragon
#

Can you be a bit more specific on what you mean by "import"?
Do you mean "using @import" ?
If so, on what and in what file?

#

That strange message is I think what the default zig init produces in the generates main.zig.

#

It's a hello world message essentially, IIRC

noble vapor
# compact dragon Can you be a bit more specific on what you mean by "import"? Do you mean "using ...

use-pgcd.zig

const std = @import("std");
const c = @cImport(@cInclude("pgcd.c")); // No need to have a .h

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();
    const args = try std.process.argsAlloc(allocator);
    defer std.process.argsFree(allocator, args);

    if (args.len != 3) {
        std.debug.print("Usage: find-pgcd L R\n", .{});
        return error.WrongArgs;
    }

    var l = try std.fmt.parseInt(u32, args[1], 10);
    var r = try std.fmt.parseInt(u32, args[2], 10);

    std.debug.print("PGCD({d},{d}) = {d}\n", .{ l, r, c.pgcd(l, r) });
}

const expect = @import("std").testing.expect;

fn expectIdentical(i: u32) !void {
    try expect(c.pgcd(i, i) == i);
}

test "identical" {
    try expectIdentical(1);
    try expectIdentical(7);
    try expectIdentical(18);
}

test "primes" {
    try expect(c.pgcd(4, 13) == 1);
}

test "pgcdexists" {
    try expect(c.pgcd(15, 35) == 5);
}

test "pgcdlower" {
    try expect(c.pgcd(15, 5) == 5);
}
#

pgcd.c

unsigned int pgcd(unsigned int l, unsigned int r) {
    while (l != r) {
        if (l > r) {
            l = l - r;
        } else {
            r = r - l;
        }
    }
    return l;
}
#
/home/joe/zi/test_ziggit/build.zig:4:34: 
const exe = b.addExecutable(.{
                                 ^
/home/joe/zig-linux-x86_64-0.12.0-dev.3125+a7a5f4cf4/lib/std/Build.zig:638:31: 
note: struct 'Build.ExecutableOptions' declared here
pub const ExecutableOptions = struct {
                                  ^
referenced by:
runBuild__anon_8909: /home/joe/zig-linux-x86_64-0.12.0-dev.3125+a7a5f4cf4/lib/std/Build.zig:1992:27
main: /home/joe/zig-linux-x86_64-0.12.0-dev.3125+a7a5f4cf4/lib/build_runner.zig:310:29
remaining reference traces hidden; use '-freference-trace' to see all reference traces
#

i really tested a few other examples but either there is an error or weird output message i mentioned at the start of this post

#

if there is an easy import/include test if it works let me know, i really think i cant do stuff on wsl

#

oh zig build install worked but the same output

compact dragon
#

It seems to me that your build.zig needs fixing.

#

Generally, you do something like

const optimize = b.standardOptimzeOptions();

const exe = b.addExecutable(.{
    .target = optimize,
    ...
};
compact dragon
#

zig run does not use build.zig.

noble vapor
#

hmm

compact dragon
#

zig build run

noble vapor
#

sorry i post ss

compact dragon
#

Wait

#

So zig build run works

#

But zig build doesn't?

noble vapor
#

zig build produces no output

#

didnt work before becaue i didnt do zig build install

#

oh no

#

i was not in the directory ( i was testing something else before )

#

sorry

#

please take a look if this works on your end:

#

ill try how it works on windows 11 without wsl

civic maple
# noble vapor

This is a successful run of the example main.zig file generated by zig init. Look in src/main.zig and you will find the weird message. What were you expecting to see?

compact dragon
#

zig build will produce no output if it succeeds.

noble vapor
compact dragon
#

It's ultimately the file in the build.zig that matters.

#

Double check that is that main.zig

noble vapor
#

build.zig

const std = @import("std");
const raylib_build = @import("libs/raylib/src/build.zig");
pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    const raylib = raylib_build.addRaylib(b, target, optimize, .{});
    const exe = b.addExecutable(.{
        .name = "hello",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });
    exe.linkLibC();
    exe.linkLibrary(raylib);
    exe.addIncludePath("raylib/src");
    exe.install();
    const run_cmd = exe.run();
    run_cmd.step.dependOn(b.getInstallStep());
    if (b.args) |args| {
        run_cmd.addArgs(args);
    }
    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);
    const exe_tests = b.addTest(.{
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });
    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&exe_tests.step);
}```
#

why is it so hard

#

seems like there is no working import/cImport/include for my machine

noble vapor
compact dragon
#

Yeah was going to say

#

That looks fine enough to me

noble vapor
#

nvm it didnt work

compact dragon
noble vapor
#

well yk i have no idea how to fix copy paste different tabs and formatting on wsl ill just give ss

#

@compact dragon

compact dragon
#

Ah-ha!

#

That's actually the same thing I just fixed on my project

#

Basically

noble vapor
#

lol

compact dragon
#

That's Raylib's build.zig not being up to date enough for master zig

noble vapor
#

0.12 version?

compact dragon
#

Go into raylib/src/build.zig and change the declaration of srclib to just be

const srcdir = "src";
#

(I vendored raylib, so I can just do that)

#

[Edit: correct path lol]

noble vapor
#

ah... i forgot to even clone raylib but lets see if it changes sometihng on windows

compact dragon
#

[Edit: correct variable name lol]

noble vapor
#
const srcdir = struct {
    fn getSrcDir() []const u8 {
        return std.fs.path.dirname(@src().file).?;
    }
}.getSrcDir();```


->

```ts
const srcdir = "src";

?

compact dragon
#

Indeed

noble vapor
#

oh not in this directory ig

#

@compact dragon

#

what is this rcore.c?

#
0.12.0-dev.3125+a7a5f4cf4```
compact dragon
compact dragon
# noble vapor

That makes me think that it didn't actually use the file you changed

noble vapor
#

lets clear cache then

#

no

#

idk probably im doing just something really dumb

#

oh right

#

it fetches probably from the github repo

#

not the local file

#

well

#

can you give me some code i can test on?

#

all the code ive found is outdated (for raylib)

compact dragon
#

When I said I vendored it

#

I mean that I cloned the upstream Raylib repo

#

And then put this in my build.zig.zon:

.dependencies = .{
    .raylib = .{
        .path = "pkg/raylib",
    },
},

Where pkg is just a folder of my choosing

noble vapor
#
+ git submodule add https://github.com/raysan5/raylib.git 
or
- git clone https://github.com/raysan5/raylib.git
noble vapor
compact dragon
#

I used git subtree
Something like git subtree add --prefix pkg/raylib https://github.com/raysan5/raylib.git master

noble vapor
#

i really just want to import "a" library, raylib may be too challenging

#

becasue it seems like nothing is working

#

the most minimal test

compact dragon
#

You should have a build.zig.zon next to your build.zig

noble vapor
#
    .name = "zigraylib",
    .version = "0.0.1",
    .dependencies = .{
        .raylib = .{
            .url = "https://github.com/raysan5/raylib/archive/e52ae870f297961b9ac23d2e6eca4937a24ac6c0.tar.gz",
            .hash = "1220b9dc848ba1359453ce8a68fa844bcbc2cacda462b47498f12d3fd932c63390ee",
        },
    },
    .paths = .{
        "build.zig",
        "build.zig.zon",
        "README.md",
        "src",
    },
}```
compact dragon
#

If you want to vendor raylib

#

Then change use .path instead of .url, and remove .hash

#

Or yeah - that is what zigraylib's build.zig.zon looks like

#

I started out using some sort of helper zig package for raylib, but it wasn't that great, so I switched to just using upstream raylib

noble vapor
#

idk...

#

isnt there a working code for raylib

#

so i can just copy and test

#

dont you have a workign project

#

or something

#

@compact dragon

compact dragon
#

I do, but alas it's not public code.

noble vapor
#

hm

compact dragon
#

And I've already told you the important parts anyhow

#

The only part I don't quite remember is the exact git subtree command I used

compact dragon
#

Might be main instead of master - I forget what name they use

noble vapor
#

ok ill just wont import stuff

#

my use for zig isnt that big

#

and this is too complicated and time consuming

#

thank you for your help

compact dragon
#

Alright o7

halcyon goblet
#

lol

#

I would absolutly recommend against using git submodules

#

in this case it's a case of updating the dependency

noble vapor
#

oh

#

thank you so much, will try

#

@halcyon goblet it works... But how?

halcyon goblet
#

Basically, having the correct version of the import, and my config in build.zig

noble vapor
#

[SOLVED] Hey i cant seem to import anything on WSL on Windows 11