From 10b899c5776921ec573c5ad3c5b099abaf7a2318 Mon Sep 17 00:00:00 2001 From: Jora Troosh Date: Thu, 18 Jul 2024 15:22:06 +0300 Subject: [PATCH] fix: update build --- .github/workflows/cd.yaml | 32 +++++++------------- .github/workflows/ci.yaml | 31 +++++--------------- .gitignore | 3 +- LICENSE.md => LICENSE | 0 README.md | 61 ++++++++++----------------------------- build.zig | 58 +++++++++++++++++-------------------- build.zig.zon | 8 ++--- example/gen.zig | 2 +- src/map_gen.zig | 2 +- 9 files changed, 67 insertions(+), 130 deletions(-) rename LICENSE.md => LICENSE (100%) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 324fd7e..9a53ffa 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -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 @@ -29,23 +15,25 @@ 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 }} @@ -53,4 +41,4 @@ jobs: steps: - name: Deploy artifact to GitHub Pages id: deployment - uses: actions/deploy-pages@v2 + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 21faad3..c304ff1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,16 +3,14 @@ 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: @@ -20,25 +18,12 @@ jobs: 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: @@ -46,7 +31,7 @@ jobs: 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 diff --git a/.gitignore b/.gitignore index 331e9d2..3389c86 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -kcov-output/ -zig-cache/ +.zig-cache/ zig-out/ diff --git a/LICENSE.md b/LICENSE similarity index 100% rename from LICENSE.md rename to LICENSE diff --git a/README.md b/README.md index ab51f9c..3a2c2ef 100644 --- a/README.md +++ b/README.md @@ -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`. -
+```sh +zig fetch --save https://github.com/tensorush/zig-quickphf/archive/.tar.gz +``` - build.zig.zon example +- Use `quickphf` dependency in `build.zig`. - ```zig - .{ - .name = "", - .version = "", - .dependencies = .{ - .quickphf = .{ - .url = "https://github.com/tensorush/quickphf/archive/.tar.gz", - .hash = "", - }, - }, - .paths = .{ - "src/", - "build.zig", - "README.md", - "LICENSE.md", - "build.zig.zon", - }, - } - ``` - - Set `` to `12200000000000000000000000000000000000000000000000000000000000000000` and build your package to find the correct value specified in a compiler error message. - -
- -2. Add `quickphf` as a module in your `build.zig`. - -
- - build.zig example - - ```zig - const quickphf = b.dependency("quickphf", .{}); - lib.root_module.addImport("quickphf", quickphf.module("quickphf")); - ``` - -
+```zig +const quickphf_dep = b.dependency("quickphf", .{ + .target = target, + .optimize = optimize, +}); +const quickphf_mod = quickphf_dep.module("quickphf"); +.root_module.addImport("quickphf", quickphf_mod); +``` @@ -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 diff --git a/build.zig b/build.zig index a1bf151..58117a1 100644 --- a/build.zig +++ b/build.zig @@ -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 @@ -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"); @@ -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/"; diff --git a/build.zig.zon b/build.zig.zon index de95830..89423c9 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -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", }, } diff --git a/example/gen.zig b/example/gen.zig index af5f837..8000a10 100644 --- a/example/gen.zig +++ b/example/gen.zig @@ -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"); diff --git a/src/map_gen.zig b/src/map_gen.zig index 27cae12..d7fc050 100644 --- a/src/map_gen.zig +++ b/src/map_gen.zig @@ -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});