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

add support for zig module #3

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,50 @@ git submodule update --remote

### Package Manager

With an existing Zig project, adding Mailbox to it is easy:

1. Add mailbox to your `build.zig.zon`
2. Add mailbox to your `build.zig`

To add mailbox to `build.zig.zon` simply run the following in your terminal:

```sh
cd my-example-project
zig fetch --save=mailbox git+https://github.com/g41797/mailbox
```

and in your `build.zig.zon` you should find a new dependency like:

```zig
exe.addModule("mailbox", b.dependency("mailbox", .{}).module("mailbox"));
.{
.name = "My example project",
.version = "0.0.1",

.dependencies = .{
.mailbox = .{
.url = "git+https://github.com/g41797/mailbox#3f794f34f5d859e7090c608da998f3b8856f8329",
.hash = "122068e7811ec1bfc2a81c9250078dd5dafa9dca4eb3f1910191ba060585526f03fe",
},
},
.paths = .{
"",
},
}
```

Zig Package Manager was changed and old installation instructions are based on addModule (see above)
are wrong - [What happened to addModule?](https://ziggit.dev/t/what-happened-to-addmodule/2908)
Then, in your `build.zig`'s `build` function, add the following before
`b.installArtifact(exe)`:

```zig
const mailbox = b.dependency("mailbox", .{
.target = target,
.optimize = optimize,
});

I'll add installation via package manager later, after testing.
exe.root_module.addImport("mailbox", mailbox.module("mailbox"));
```

Opened new issue [Fix installation instructions](https://github.com/g41797/mailbox/issues/2)
From then on, you can use the Mailbox package in your project.

## Last warning
First rule of multithreading:
Expand Down
7 changes: 6 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});

_ = b.addModule("mailbox", .{
.root_source_file = b.path("src/mailbox.zig"),
.target = target,
.optimize = optimize,
});

// This declares intent for the library to be installed into the standard
// location when the user invokes the "install" step (the default step when
// running `zig build`).
b.installArtifact(lib);


// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const lib_unit_tests = b.addTest(.{
Expand Down
Loading