Skip to content

Commit

Permalink
fix: update build
Browse files Browse the repository at this point in the history
  • Loading branch information
tensorush committed Jul 18, 2024
1 parent d777210 commit 10b899c
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 130 deletions.
32 changes: 10 additions & 22 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,9 @@ name: Continuous Delivery
on:
push:
branches: [main]
paths: ["**.zig"]

pull_request:
branches: [main]
paths: ["**.zig"]

workflow_dispatch:

permissions:
pages: write
contents: read
id-token: write

concurrency:
group: pages
cancel-in-progress: false

jobs:
emit:
runs-on: ubuntu-latest
Expand All @@ -29,28 +15,30 @@ jobs:
uses: actions/checkout@v4

- name: Set up Zig
uses: goto-bus-stop/setup-zig@v2
uses: mlugg/setup-zig@v1

- name: Emit docs
run: |
zig build docs
rm -rf zig-out/docs/src/std/
- name: Run `doc`
run: zig build doc

- name: Upload artifact for GitHub Pages
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v3
with:
path: zig-out/docs/
path: zig-out/doc/

deploy:
needs: emit

runs-on: ubuntu-latest

permissions:
pages: write
id-token: write

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Deploy artifact to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
31 changes: 8 additions & 23 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,35 @@ name: Continuous Integration
on:
push:
branches: [main]
paths: ["**.zig"]

pull_request:
branches: [main]
paths: ["**.zig"]

workflow_dispatch:

jobs:
example_test:
example:
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Zig
uses: goto-bus-stop/setup-zig@v2
uses: mlugg/setup-zig@v1

- name: Run example test
run: zig build example_test
- name: Run `example`
run: zig build example

- name: Set up kcov
run: sudo apt install kcov

- name: Generate coverage
run: zig build cov

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
directory: kcov-output
fail_ci_if_error: true
verbose: true

lints:
fmt:
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Zig
uses: goto-bus-stop/setup-zig@v2
uses: mlugg/setup-zig@v1

- name: Run lints
run: zig build lints
- name: Run `fmt`
run: zig build fmt
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
kcov-output/
zig-cache/
.zig-cache/
zig-out/
File renamed without changes.
61 changes: 16 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,30 @@
# :lizard: :world_map: zig quickphf
# zig-quickphf

[![CI][ci-shd]][ci-url]
[![CD][cd-shd]][cd-url]
[![DC][dc-shd]][dc-url]
[![CC][cc-shd]][cc-url]
[![LC][lc-shd]][lc-url]

## Zig port of the [QuickPhf library](https://github.com/dtrifuno/quickphf) created by [Darko Trifunovski](https://github.com/dtrifuno).
## Zig port of [quickphf library](https://github.com/dtrifuno/quickphf) for generating static hash maps.

### :rocket: Usage

1. Add `quickphf` as a dependency in your `build.zig.zon`.
- Add `quickphf` dependency to `build.zig.zon`.

<details>
```sh
zig fetch --save https://github.com/tensorush/zig-quickphf/archive/<git_tag_or_commit_hash>.tar.gz
```

<summary><code>build.zig.zon</code> example</summary>
- Use `quickphf` dependency in `build.zig`.

```zig
.{
.name = "<name_of_your_package>",
.version = "<version_of_your_package>",
.dependencies = .{
.quickphf = .{
.url = "https://github.com/tensorush/quickphf/archive/<git_tag_or_commit_hash>.tar.gz",
.hash = "<package_hash>",
},
},
.paths = .{
"src/",
"build.zig",
"README.md",
"LICENSE.md",
"build.zig.zon",
},
}
```
Set `<package_hash>` to `12200000000000000000000000000000000000000000000000000000000000000000` and build your package to find the correct value specified in a compiler error message.
</details>
2. Add `quickphf` as a module in your `build.zig`.
<details>
<summary><code>build.zig</code> example</summary>
```zig
const quickphf = b.dependency("quickphf", .{});
lib.root_module.addImport("quickphf", quickphf.module("quickphf"));
```
</details>
```zig
const quickphf_dep = b.dependency("quickphf", .{
.target = target,
.optimize = optimize,
});
const quickphf_mod = quickphf_dep.module("quickphf");
<compile>.root_module.addImport("quickphf", quickphf_mod);
```

<!-- MARKDOWN LINKS -->

Expand All @@ -61,7 +34,5 @@
[cd-url]: https://github.com/tensorush/zig-quickphf/blob/main/.github/workflows/cd.yaml
[dc-shd]: https://img.shields.io/badge/click-F6A516?style=for-the-badge&logo=zig&logoColor=F6A516&label=docs&labelColor=black
[dc-url]: https://tensorush.github.io/zig-quickphf
[cc-shd]: https://img.shields.io/codecov/c/github/tensorush/zig-quickphf?style=for-the-badge&labelColor=black
[cc-url]: https://app.codecov.io/gh/tensorush/zig-quickphf
[lc-shd]: https://img.shields.io/github/license/tensorush/zig-quickphf.svg?style=for-the-badge&labelColor=black
[lc-url]: https://github.com/tensorush/zig-quickphf/blob/main/LICENSE.md
[lc-url]: https://github.com/tensorush/zig-quickphf/blob/main/LICENSE
58 changes: 26 additions & 32 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const root_source_file = std.Build.LazyPath.relative("src/lib.zig");
const root_source_file = b.path("src/lib.zig");
const version = std.SemanticVersion{ .major = 0, .minor = 1, .patch = 0 };

// Dependencies
Expand Down Expand Up @@ -33,16 +33,16 @@ pub fn build(b: *std.Build) void {
lib_step.dependOn(&lib_install.step);
b.default_step.dependOn(lib_step);

// Docs
const docs_step = b.step("docs", "Emit docs");
// Documentation
const doc_step = b.step("doc", "Emit documentation");

const docs_install = b.addInstallDirectory(.{
const doc_install = b.addInstallDirectory(.{
.install_dir = .prefix,
.install_subdir = "docs",
.install_subdir = "doc",
.source_dir = lib.getEmittedDocs(),
});
docs_step.dependOn(&docs_install.step);
b.default_step.dependOn(docs_step);
doc_step.dependOn(&doc_install.step);
b.default_step.dependOn(doc_step);

// Example
const example_step = b.step("example", "Run example");
Expand All @@ -52,42 +52,36 @@ pub fn build(b: *std.Build) void {
.target = target,
.version = version,
.optimize = optimize,
.root_source_file = std.Build.LazyPath.relative("example/main.zig"),
.root_source_file = b.path(EXAMPLE_DIR ++ "main.zig"),
});
example.root_module.addImport("quickphf", quickphf_mod);

const example_run = b.addRunArtifact(example);
example_step.dependOn(&example_run.step);

// Example test
const example_test_step = b.step("example_test", "Run example test");

const example_test = b.addTest(.{
.target = target,
.root_source_file = std.Build.LazyPath.relative("example/test.zig"),
.root_source_file = b.path(EXAMPLE_DIR ++ "test.zig"),
});
example_test.root_module.addImport("quickphf", quickphf_mod);
example_test.step.dependOn(example_step);
example_test.step.dependOn(&example_run.step);

const example_test_run = b.addRunArtifact(example_test);
example_test_step.dependOn(&example_test_run.step);
b.default_step.dependOn(example_test_step);

// Coverage
const cov_step = b.step("cov", "Generate coverage");

const cov_run = b.addSystemCommand(&.{ "kcov", "--clean", "--include-pattern=src/", "kcov-output" });
cov_run.addArtifactArg(example_test);
cov_step.dependOn(&cov_run.step);
b.default_step.dependOn(cov_step);

// Lints
const lints_step = b.step("lints", "Run lints");

const lints = b.addFmt(.{
.paths = &.{ "src/", "example/", "build.zig" },
example_step.dependOn(&example_test_run.step);
b.default_step.dependOn(example_step);

// Formatting checks
const fmt_step = b.step("fmt", "Run formatting checks");

const fmt = b.addFmt(.{
.paths = &.{
"src/",
"build.zig",
EXAMPLE_DIR,
},
.check = true,
});
lints_step.dependOn(&lints.step);
b.default_step.dependOn(lints_step);
fmt_step.dependOn(&fmt.step);
b.default_step.dependOn(fmt_step);
}

const EXAMPLE_DIR = "example/";
8 changes: 4 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
.version = "0.1.0",
.dependencies = .{
.quickdiv = .{
.url = "https://github.com/tensorush/zig-quickdiv/archive/dfa61d4.tar.gz",
.hash = "1220b6901435076ea1817105df24d0f4cde730aa45ff301c05870b7107526ba53ab6",
.url = "https://github.com/tensorush/zig-quickdiv/archive/54d77f5.tar.gz",
.hash = "12209702843d4162084c666cae57284dfe6977b89dff0fdb0a0dbaf2fd0c78501f7a",
},
},
.paths = .{
"src/",
"example/",
"build.zig",
"README.md",
"LICENSE.md",
"build.zig.zon",
"LICENSE",
"README.md",
},
}
2 changes: 1 addition & 1 deletion example/gen.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Static hash map generated with [QuickPhf](https://github.com/tensorush/zig-quickphf).
//! Static hash map generated with [quickphf](https://github.com/tensorush/zig-quickphf).

const quickphf = @import("quickphf");

Expand Down
2 changes: 1 addition & 1 deletion src/map_gen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn MapGen(comptime K: type, comptime V: type, comptime NUM_ENTRIES: u64) typ
var buf_writer = std.io.bufferedWriter(file.writer());
const writer = buf_writer.writer();

try writer.writeAll("//! Static hash map generated with [QuickPhf](https://github.com/tensorush/zig-quickphf).\n\n");
try writer.writeAll("//! Static hash map generated with [quickphf](https://github.com/tensorush/zig-quickphf).\n\n");
try writer.writeAll("const quickphf = @import(\"quickphf\");\n\n");
try writer.print("pub const {s} = quickphf.Map({s}, {s}).init(\n", .{ name, @typeName(K), @typeName(V) });
try writer.print(" {d},\n", .{self.phf.seed});
Expand Down

0 comments on commit 10b899c

Please sign in to comment.