#Help understanding this linking code / code base

1 messages · Page 1 of 1 (latest)

brazen sedge
#

I'm trying to use cudaz but I don't understand how the linking works here - https://github.com/akhildevelops/cudaz/blob/304adc4ad82f14689aa1d311bd601da30372b729/example/increment/build.zig#L11
I don't see a module that lines up with that value. There is no file called cudaz.zig or even Cudaz type somewhere.
In build.zig:

    // Point to cudaz dependency
    const cudaz_dep = b.dependency("cudaz", .{});

    // Fetch and add the module from cudaz dependency
    const cudaz_module = cudaz_dep.module("cudaz");
    exe.root_module.addImport("cudaz", cudaz_module);

I haven't seen a dependency linked like this. I tried to copy/paste this code and it complains there is no addImport in root_module.

This module gets imported here - https://github.com/akhildevelops/cudaz/blob/304adc4ad82f14689aa1d311bd601da30372b729/example/increment/src/main.zig#L2 - but I don't understand where the other values are coming from:

const Cuda = @import("cudaz");
const CuDevice = Cuda.Device;
const CuCompile = Cuda.Compile;
const CuLaunchConfig = Cuda.LaunchConfig;

Where is Device, Compile, LaunchConfig coming from? My running theory is that cudaz is some sort of synthetic module created in build.zig. Please correct my understanding.

dapper creek
#

the module comes from the build.zig.zon. The build system fetches deps from that and exposes them through b.depedency

brazen sedge
#

If I try to build the example from the project I get this error:

error: expected type 'zig.CrossTarget', found 'zig.system.NativeTargetInfo'
    const exe = b.addExecutable(.{ .name = "main", .root_source_file = .{ .path = "src/main.zig" }, .target = b.host });
                                                                                                    ~~~~~~~~^~~~~~~~
/home/kevinedey/.asdf/installs/zig/0.12.0-dev/lib/std/zig/system/NativeTargetInfo.zig:1:1: note: struct declared here
const std = @import("../../std.zig");
^~~~~
/home/kevinedey/.asdf/installs/zig/0.12.0-dev/lib/std/zig/CrossTarget.zig:1:1: note: struct declared here
//! Contains all the same data as `Target`, additionally introducing the concept of "the native target".
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    runBuild__anon_6849: /home/kevinedey/.asdf/installs/zig/0.12.0-dev/lib/std/Build.zig:1883:37
    steps__anon_6672: /home/kevinedey/.asdf/installs/zig/0.12.0-dev/lib/build_runner.zig:969:29
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
#

Has the build system changed to make this way obsolete?

dapper creek
#

build system changes quite frequently. Need to see what zig version the project was written under

brazen sedge
#

What's the equivalent new syntax?

brazen sedge
#

@solemn meteor - is this your library?

brazen sedge
#

Trying zig version 0.10.0 and 0.11.0 didn't work either.

brazen sedge
#

I'm kind of tearing my hair out with this one. Progressing with different errors.

/home/kevinedey/Code/Personal/cudaz/build.zig:67:51: error: no field named 'root_source_file' in struct 'Build.CreateModuleOptions'
    const cudaz_module = b.addModule("cudaz", .{ .root_source_file = .{ .path = "src/lib.zig" } });
                                                  ^~~~~~~~~~~~~~~~
/home/kevinedey/.asdf/installs/zig/0.12.0-dev/lib/std/Build.zig:860:33: note: struct declared here
pub const CreateModuleOptions = struct {

But searching through the source CreateModuleOptions doesn't exist. Module.CreateOptions does exist though and these values do seem to line up so.... huh?

dapper creek
#

source for master branch?

brazen sedge
#

Yes

#

Should I be on a different branch?

#

I'm working with 0.12.0-dev on my machine.

#

Should I go get the latest?

dapper creek
#

-dev is normally "the latest" unless your commit is pretty old

brazen sedge
#
cudaz zig version                                          
0.12.0-dev.1845+21ae64852
➜  cudaz zig build                                            
/home/kevinedey/Code/Personal/cudaz/build.zig:67:51: error: no field named 'root_source_file' in struct 'Build.CreateModuleOptions'
    const cudaz_module = b.addModule("cudaz", .{ .root_source_file = .{ .path = "src/lib.zig" } });
                                                  ^~~~~~~~~~~~~~~~
/home/kevinedey/.asdf/installs/zig/0.12.0-dev/lib/std/Build.zig:860:33: note: struct declared here
pub const CreateModuleOptions = struct {
                                ^~~~~~
referenced by:
    runBuild__anon_6851: /home/kevinedey/.asdf/installs/zig/0.12.0-dev/lib/std/Build.zig:1883:37
    steps__anon_6672: /home/kevinedey/.asdf/installs/zig/0.12.0-dev/lib/build_runner.zig:969:29
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
#

I refetched latest and it's the same.

dapper creek
#

your zig looks like its too old. Thats there on master in Module.zig, meanwhile yours is pointing to code in Build.zig

brazen sedge
#

Does anyone in the Zig community use version managers like asdf, rtx (mise), etc?

dapper creek
#

i personally just have a script to pull down latest into a folder which is symlinked to somewhere in PATH

brazen sedge
#

I'm wondering if it's asdf linking error pointing to the wrong one.

dapper creek
#

probably. heard some people use zigup too

brazen sedge
#

Finally working. Not sure how old that version of Zig was that I was using. Also, not sure if the asdf plugin is broken as it didn't get the right thing but it seemed like it worked properly when it didn't. I patched it so all good now.