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 dfa61d4 commit 54d77f5
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 118 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:
tests:
test:
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 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:
- 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: :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`.

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

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

```zig
.{
.name = "<name_of_your_package>",
.version = "<version_of_your_package>",
.dependencies = .{
.quickdiv = .{
.url = "https://github.com/tensorush/zig-quickdiv/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 `quickdiv` as a module in your `build.zig`.
<details>
<summary><code>build.zig</code> example</summary>
```zig
const quickdiv = b.dependency("quickdiv", .{});
lib.root_module.addImport("quickdiv", quickdiv.module("quickdiv"));
```
</details>
```zig
const quickdiv_dep = b.dependency("quickdiv", .{
.target = target,
.optimize = optimize,
});
const quickdiv_mod = quickdiv_dep.module("quickdiv");
<compile>.root_module.addImport("quickdiv", quickdiv_mod);
```

<!-- MARKDOWN LINKS -->

Expand All @@ -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
42 changes: 19 additions & 23 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 };

// Module
Expand All @@ -24,44 +24,40 @@ 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,
});

const tests_run = b.addRunArtifact(tests);
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);
}
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
.paths = .{
"src/",
"build.zig",
"README.md",
"LICENSE.md",
"build.zig.zon",
"LICENSE",
"README.md",
},
}
6 changes: 5 additions & 1 deletion src/unsigned.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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) |_| {
Expand Down

0 comments on commit 54d77f5

Please sign in to comment.