#Library types at build time.

1 messages · Page 1 of 1 (latest)

untold forge
#

Is there a way to use types from a library at build time? It makes sense that they are not available as the program wasn't yet build during the build script but is there still a way to access them or do I have to make my own exact copy of the type and then just bitCast/map them later to the library type?

swift pike
#

and u can import a dependency's build.zig in the depender's build.zig using @import("dep_name")

#

so for a package to expose types at build time, it should import the file where those types are defined in its build.zig, and create pub aliases for all the types it wants to expose

untold forge
#

I'm not quite sure how to do that from the explanation alone.

#

do you mean just do const rl = @import("raylib"); how I do it in runtime executed files?

#

I also gives me this error

src\map.zig:2:20: error: no module named 'raylib' available within module 'root.@build'
const rl = @import("raylib");
#

Does that mean I have to import it in the root file

swift pike
#

so for example if u have package foo that depends on package bar, and u want foo to be able to use Thing, defined in src/types.zig inside bar, u need this:

// inside bar's build.zig
pub const Thing = @import("src/types.zig").Thing;
// inside foo's build.zig
pub const bar = @import("bar");
// u can now use bar.Thing
untold forge
#

It's the raylib-zig bindings btw, not the C raylib.

swift pike
untold forge
#

I have this part in my build.zig, that's why I use raylib instead of raylib-zig

const raylib_deb = b.dependency("raylib_zig", .{
    .target = target,
    .optimize = optimize,
});

const raylib_artifact = raylib_deb.artifact("raylib");
const raylib = raylib_deb.module("raylib");
const raygui = raylib_deb.module("raygui");

exe.linkLibrary(raylib_artifact);
exe.root_module.addImport("raylib", raylib);
exe.root_module.addImport("raygui", raygui);
#

I mean it works everywhere else

swift pike
#

yea so u should @import("raylib_zig") cuz that's the dependency name

untold forge
#

but that still gives me the same error

swift pike
#

can u show me the exact error u get, and the contents of ur build.zig.zon?

untold forge
#

build.zig.zon:

.{
    .name = .minacare,

    .version = "0.0.0",

    .fingerprint = 0xe61924bbf625653f, // Changing this has security and trust implications.

    .minimum_zig_version = "0.15.1",

    .dependencies = .{
        .raylib_zig = .{
            .url = "git+https://github.com/raylib-zig/raylib-zig?ref=devel#178530d5f5e654d9eb1d7a79e3fbfbd931e26163",
            .hash = "raylib_zig-5.6.0-dev-KE8REKo6BQDt6jBeo3ODV5g9kzo2IRfJARkaN0kXtC2T",
        },
    },
    .paths = .{
        "build.zig",
        "build.zig.zon",
        "src",
    },
}
swift pike
#

raylib_zig not raylib-zig

#

it has to exactly match the name in ur build.zig.zon's dependencies struct

untold forge
#

my bad

#

I am looking through raylib-zig's build file and there is no public exposed constant for the raylib module. I guess that means I can't use it then without modifying the raylib-zig code.

swift pike
#

yea, u will need to modify the raylib-zig build.zig to expose the types u need at build time

untold forge
#

forking whole raylib-zig just to add pub const raylib_module = @import("lib/raylib.zig");

#

but that's how it is.

#

Thanks for the help