Skip to content

Commit

Permalink
Merge pull request #2 from fjebaker/unicode
Browse files Browse the repository at this point in the history
Unicode
  • Loading branch information
fjebaker authored Aug 12, 2024
2 parents aee9910 + 30a5f62 commit 26261a6
Show file tree
Hide file tree
Showing 9 changed files with 523 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
with:
version: 0.13.0
- name: Build and test
run: zig build test
run: zig build test -Dunicode

32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file is for zig-specific build artifacts.

.zig-cache/
zig-out/
build/
build-*/
docgen_tmp/

# Compiled Object files
*.slo
*.lo
*.o
*.obj
*.elf
*.ko

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
43 changes: 37 additions & 6 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,52 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

_ = b.addModule("fuzzig", .{ .root_source_file = b.path("src/root.zig") });

const lib = b.addStaticLibrary(.{
.name = "fuzzig",
.root_source_file = b.path("src/root.zig"),
const zg = b.dependency("zg", .{
.target = target,
.optimize = optimize,
});

b.installArtifact(lib);
const with_unicode = b.option(
bool,
"unicode",
"Compile with unicode support (fetches additional dependencies)",
) orelse false;

const opts = b.addOptions();

opts.addOption(
bool,
"unicode",
with_unicode,
);

const mod = b.addModule("fuzzig", .{ .root_source_file = b.path("src/root.zig") });
mod.addOptions("options", opts);

if (with_unicode) {
mod.addImport("code_point", zg.module("code_point"));
mod.addImport("GenCatData", zg.module("GenCatData"));
mod.addImport("CaseData", zg.module("CaseData"));
mod.addImport("Normalize", zg.module("Normalize"));
mod.addImport("CaseFold", zg.module("CaseFold"));
}

const lib_unit_tests = b.addTest(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});

lib_unit_tests.root_module.addOptions("options", opts);

if (with_unicode) {
lib_unit_tests.root_module.addImport("code_point", zg.module("code_point"));
lib_unit_tests.root_module.addImport("GenCatData", zg.module("GenCatData"));
lib_unit_tests.root_module.addImport("CaseData", zg.module("CaseData"));
lib_unit_tests.root_module.addImport("Normalize", zg.module("Normalize"));
lib_unit_tests.root_module.addImport("CaseFold", zg.module("CaseFold"));
}

const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);

const test_step = b.step("test", "Run unit tests");
Expand All @@ -33,6 +62,8 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});

exe.root_module.addImport("fuzzig", mod);

const run_cmd = b.addRunArtifact(exe);
const benchmark_step = b.step("benchmark", "Run benchmarks.");
benchmark_step.dependOn(&run_cmd.step);
Expand Down
65 changes: 10 additions & 55 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,62 +1,17 @@
.{
.name = "fuzzig",
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",

// This field is optional.
// This is currently advisory only; Zig does not yet do anything
// with this value.
//.minimum_zig_version = "0.11.0",

// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.version = "0.1.0",
.dependencies = .{
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
//.example = .{
// // When updating this field to a new URL, be sure to delete the corresponding
// // `hash`, otherwise you are communicating that you expect to find the old hash at
// // the new URL.
// .url = "https://example.com/foo.tar.gz",
//
// // This is computed from the file contents of the directory of files that is
// // obtained after fetching `url` and applying the inclusion rules given by
// // `paths`.
// //
// // This field is the source of truth; packages do not come from a `url`; they
// // come from a `hash`. `url` is just one of many possible mirrors for how to
// // obtain a package matching this `hash`.
// //
// // Uses the [multihash](https://multiformats.io/multihash/) format.
// .hash = "...",
//
// // When this is provided, the package is found in a directory relative to the
// // build root. In this case the package's hash is irrelevant and therefore not
// // computed. This field and `url` are mutually exclusive.
// .path = "foo",
//},
.zg = .{
.url = "https://codeberg.org/dude_the_builder/zg/archive/v0.13.2.tar.gz",
.hash = "122055beff332830a391e9895c044d33b15ea21063779557024b46169fb1984c6e40",
},
},

// Specifies the set of files and directories that are included in this package.
// Only files and directories listed here are included in the `hash` that
// is computed for this package.
// Paths are relative to the build root. Use the empty string (`""`) to refer to
// the build root itself.
// A directory listed here means that all files within, recursively, are included.
.paths = .{
// This makes *all* files, recursively, included in this package. It is generally
// better to explicitly list the files and directories instead, to insure that
// fetching from tarballs, file system paths, and version control all result
// in the same contents hash.
"",
// For example...
//"build.zig",
//"build.zig.zon",
//"src",
//"LICENSE",
//"README.md",
"build.zig",
"build.zig.zon",
"src",
"LICENSE",
"README.md",
},
}
6 changes: 3 additions & 3 deletions src/main.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const std = @import("std");
const fuzzy = @import("root.zig");
const fuzzig = @import("fuzzig");
const bmark = @import("benchmarks.zig");

pub fn main() !void {
Expand All @@ -8,7 +8,7 @@ pub fn main() !void {

const alloc = gpa.allocator();

var finder = try fuzzy.Ascii.init(alloc, 6000, 500, .{});
var finder = try fuzzig.Ascii.init(alloc, 6000, 500, .{});
defer finder.deinit();

const scores = try alloc.alloc(i32, LINES.len);
Expand Down Expand Up @@ -47,7 +47,7 @@ pub fn main() !void {
result.printSummary();
}

pub fn runBmark(finder: *fuzzy.Ascii) void {
pub fn runBmark(finder: *fuzzig.Ascii) void {
const score = finder.score(
"hello world this is a short message about things" ** 100,
"short abut thns",
Expand Down
Loading

0 comments on commit 26261a6

Please sign in to comment.