From 54d77f5e81dc5c4b899bdea5a17abd70638def67 Mon Sep 17 00:00:00 2001 From: Jora Troosh Date: Thu, 18 Jul 2024 15:00:58 +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 | 42 ++++++++++++--------------- build.zig.zon | 4 +-- src/unsigned.zig | 6 +++- 8 files changed, 61 insertions(+), 118 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 0b53427..b400ed1 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: - tests: + test: 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 tests - run: zig build tests + - name: Run `test` + run: zig build test --summary all - - 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 fcd2808..6da5f78 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,30 @@ -# :lizard: :heavy_division_sign: zig quickdiv +# zig-quickdiv [![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 [QuickDiv library](https://github.com/dtrifuno/quickdiv) created by [Darko Trifunovski](https://github.com/dtrifuno). +## Zig port of [quickdiv library](https://github.com/dtrifuno/quickdiv) for optimized repeated division. ### :rocket: Usage -1. Add `quickdiv` as a dependency in your `build.zig.zon`. +- Add `quickdiv` dependency to `build.zig.zon`. -
+```sh +zig fetch --save https://github.com/tensorush/zig-quickdiv/archive/.tar.gz +``` - build.zig.zon example +- Use `quickdiv` dependency in `build.zig`. - ```zig - .{ - .name = "", - .version = "", - .dependencies = .{ - .quickdiv = .{ - .url = "https://github.com/tensorush/zig-quickdiv/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 `quickdiv` as a module in your `build.zig`. - -
- - build.zig example - - ```zig - const quickdiv = b.dependency("quickdiv", .{}); - lib.root_module.addImport("quickdiv", quickdiv.module("quickdiv")); - ``` - -
+```zig +const quickdiv_dep = b.dependency("quickdiv", .{ + .target = target, + .optimize = optimize, +}); +const quickdiv_mod = quickdiv_dep.module("quickdiv"); +.root_module.addImport("quickdiv", quickdiv_mod); +``` @@ -61,7 +34,5 @@ [cd-url]: https://github.com/tensorush/zig-quickdiv/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-quickdiv -[cc-shd]: https://img.shields.io/codecov/c/github/tensorush/zig-quickdiv?style=for-the-badge&labelColor=black -[cc-url]: https://app.codecov.io/gh/tensorush/zig-quickdiv [lc-shd]: https://img.shields.io/github/license/tensorush/zig-quickdiv.svg?style=for-the-badge&labelColor=black -[lc-url]: https://github.com/tensorush/zig-quickdiv/blob/main/LICENSE.md +[lc-url]: https://github.com/tensorush/zig-quickdiv/blob/main/LICENSE diff --git a/build.zig b/build.zig index d0294e3..80fa02c 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 }; // Module @@ -24,22 +24,23 @@ 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); - // Tests - const tests_step = b.step("tests", "Run tests"); + // Test suite + const tests_step = b.step("test", "Run test suite"); const tests = b.addTest(.{ .target = target, + .version = version, .root_source_file = root_source_file, }); @@ -47,21 +48,16 @@ pub fn build(b: *std.Build) void { tests_step.dependOn(&tests_run.step); b.default_step.dependOn(tests_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(tests); - cov_step.dependOn(&cov_run.step); - b.default_step.dependOn(cov_step); - - // Lints - const lints_step = b.step("lints", "Run lints"); + // Formatting checks + const fmt_step = b.step("fmt", "Run formatting checks"); - const lints = b.addFmt(.{ - .paths = &.{ "src/", "build.zig" }, + const fmt = b.addFmt(.{ + .paths = &.{ + "src/", + "build.zig", + }, .check = true, }); - lints_step.dependOn(&lints.step); - b.default_step.dependOn(lints_step); + fmt_step.dependOn(&fmt.step); + b.default_step.dependOn(fmt_step); } diff --git a/build.zig.zon b/build.zig.zon index 0d7097a..7a5ddcd 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -4,8 +4,8 @@ .paths = .{ "src/", "build.zig", - "README.md", - "LICENSE.md", "build.zig.zon", + "LICENSE", + "README.md", }, } diff --git a/src/unsigned.zig b/src/unsigned.zig index 6e16812..66341c1 100644 --- a/src/unsigned.zig +++ b/src/unsigned.zig @@ -82,7 +82,11 @@ pub fn Divisor(comptime T: type) type { } test Self { - var prng = std.rand.DefaultPrng.init(0); + var prng = std.Random.DefaultPrng.init(blk: { + var seed: u64 = undefined; + try std.posix.getrandom(std.mem.asBytes(&seed)); + break :blk seed; + }); const random = prng.random(); for (1..100_000) |_| {