-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
125 lines (100 loc) · 3.55 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{
description = "zig-budoux flake";
inputs = {
zig2nix.url = "github:Cloudef/zig2nix";
};
outputs = { zig2nix, ... }: let
flake-utils = zig2nix.inputs.flake-utils;
in (flake-utils.lib.eachDefaultSystem (system: let
# Zig flake helper
# Check the flake.nix in zig-flake project for more options:
# <https://github.com/Cloudef/mach-flake/blob/master/flake.nix>
env = zig2nix.outputs.zig-env.${system} {
zig = zig2nix.outputs.packages.${system}.zig.master.bin;
};
in rec {
# nix build .
packages.default = env.package {
src = env.pkgs.lib.cleanSource ./.;
};
# nix run .
apps.default = apps.test;
# nix run .#build
apps.build = env.app [] "zig build \"$@\"";
# nix run .#test
apps.test = env.app [ env.pkgs.gcc env.pkgs.clang ] ''
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
zig build
echo "testing zig"
zig build test -- "$@"
echo "testing gcc"
gcc src/test.c zig-out/lib/libbudoux.a -o "$tmpdir/test"
"$tmpdir/test"
echo "testing clang"
clang src/test.c zig-out/lib/libbudoux.a -o "$tmpdir/test"
"$tmpdir/test"
'';
# nix run .#docs
apps.docs = env.app [] "zig build docs -- \"$@\"";
# nix run .#deps
apps.deps = env.showExternalDeps;
# nix run .#zon2json
apps.zon2json = env.app [env.zon2json] "zon2json \"$@\"";
# nix run .#zon2json-lock
apps.zon2json-lock = env.app [env.zon2json-lock] "zon2json-lock \"$@\"";
# nix run .#zon2nix
apps.zon2nix = env.app [env.zon2nix] "zon2nix \"$@\"";
# nix develop
devShells.default = env.mkShell {};
# nix run .#readme
apps.readme = let
project = "zig-budoux";
in env.app [] (builtins.replaceStrings ["`"] ["\\`"] ''
cat <<EOF
# ${project}
[Budoux](https://github.com/google/budoux) for Zig (and C)
---
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
Project is tested on zig version $(zig version)
## Example
### Zig
```zig
const budoux = @import("zig-budoux");
var model = try budoux.init(allocator, .ja);
defer model.deinit(allocator);
var iter = model.iterator("今日は天気です。");
try std.testing.expectEqualSlices(u8, "今日は", iter.next().?);
try std.testing.expectEqualSlices(u8, "天気です。", iter.next().?);
```
### C
```c
#include <budoux.h>
BudouxModel model = budoux_init(budoux_model_ja);
BudouxChunkIterator iter = budoux_iterator_init(model, "今日は天気です。");
BudouxChunk chunk;
chunk = budoux_iterator_next(&iter); // 今日は
chunk = budoux_iterator_next(&iter); // 天気です。
budoux_deinit(model);
```
> [!NOTE]
> zig-budoux does not allocate any strings, thus it won't add any html markup or zero width spaces.
> However with `model.iterator` it is simple to construct strings for your needs.
> To parse html you need to bring your own html parser.
## Depend
`build.zig.zon`
```zig
.zig_budoux = .{
.url = "https://github.com/Cloudef/zig-budoux/archive/{COMMIT}.tar.gz",
.hash = "{HASH}",
},
```
`build.zig`
```zig
const zig_budoux = b.dependency("zig_budoux", .{}).module("zig-budoux");
exe.root_module.addImport("zig-budoux", zig_budoux);
```
EOF
'');
}));
}