Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[FYI]Regarding zig-network installation #95

Closed
g41797 opened this issue Oct 8, 2024 · 7 comments
Closed

[FYI]Regarding zig-network installation #95

g41797 opened this issue Oct 8, 2024 · 7 comments

Comments

@g41797
Copy link
Contributor

g41797 commented Oct 8, 2024

Add zig-network to build.zig.zon:

zig fetch --save=network git+https://github.com/ikskuh/zig-network

Import zig-network:

    const zig_network = b.dependency("network", .{
        .target = target,
        .optimize = optimize,
    });

    const lib = b.addStaticLibrary(..);
    lib.root_module.addImport("network", zig_network.module("network"));

    const lib_unit_tests = b.addTest(...);
    lib_unit_tests.root_module.addImport("network", zig_network.module("network"));
@payolin
Copy link

payolin commented Nov 24, 2024

Can you expand the arguments for b.addStaticLibrary ?
On zig version 0.13.0, trying @import("network") and building throws an error about the module not being found with this build.zig:

    const network_dep = b.dependency("network", .{
        .target = target,
        .optimize = optimize,
    });
    const network_lib = b.addStaticLibrary(.{ 
        .name = "network",
        .target = target,
        .optimize = optimize
    });
    network_lib.root_module.addImport("network", network_dep.module("network"));

I am unable to find up-to-date information on the package manager, so maybe I'm not filling the arguments correctly, or perhaps this is not up to date.

@g41797
Copy link
Contributor Author

g41797 commented Nov 24, 2024

May be build.zig will help

@illegitimate-egg
Copy link

@payolin Were you able to get this to work? Just going through this myself right now and whatever you ended up with could be useful

@payolin
Copy link

payolin commented Dec 1, 2024

@payolin Were you able to get this to work? Just going through this myself right now and whatever you ended up with could be useful

I have not. Running the build.zig g41797 provided (minus the mailbox and datetime libs) does not work, complaining that there is no module network available within module root.

I am looking into it further.

@illegitimate-egg
Copy link

Good news! I asked the guys on the zig discord server nicely and they outlined it better than I ever could.

polylokh (@polylokh_39446) @ 22:32 UTC 2024-12-01:
yeah there's a strong tendency to abbreviate examples, often dropping very brief imports.
here's a minimal build.zig:

const std = @import("std");

pub fn build(b: *std.Build) void {
    const optimize = b.standardOptimizeOption(.{});
    const target = b.standardTargetOptions(.{});
    const exe = b.addExecutable(.{
        .name = "hw11",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });
    const zig_network = b.dependency("network", .{
        .target = target,
        .optimize = optimize,
    });
    exe.root_module.addImport("network", zig_network.module("network"));
    b.installArtifact(exe);
}

all that's added there is the zig_network from that issue, which is added here to the single exe that's built
that build.zig, in a brand new zig init, just needs the same fetch from that example
and then if your main.zig is https://github.com/ikskuh/zig-network/blob/master/examples/echo.zig, it'll build.

$ zig build
$ ./zig-out/bin/hw11 1234
Client connected from 127.0.0.1:1234.
Client disconnected.

use nc localhost 1234 in another shell, type something, hit enter
for a server to report its own port instead of the peer port is a strange thing to do, but unrelated to your question

@g41797
Copy link
Contributor Author

g41797 commented Dec 6, 2024

@payolin Were you able to get this to work? Just going through this myself right now and whatever you ended up with could be useful

I have not. Running the build.zig g41797 provided (minus the mailbox and datetime libs) does not work, complaining that there is no module network available within module root.

I am looking into it further.

did you add dependencies to build.zig.zon via zig fetch?

@payolin
Copy link

payolin commented Dec 11, 2024

Alright, got it working, thanks @illegitimate-egg

@g41797 g41797 closed this as completed Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants