diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..db3cb54 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.zig-cache/ +/zig-out/ diff --git a/README.md b/README.md index e8451cc..21a64d0 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,2 @@ -# Thespian -Fast & flexible actors for Zig, C & C++ applications - -To build: -``` -./zig build -``` - -See `tests/*` for many interesting examples. +# Zig CBOR +A Fast & flexible cbor encoding, decoding and matching library for Zig diff --git a/build.zig b/build.zig index 52f1ec7..aab561e 100644 --- a/build.zig +++ b/build.zig @@ -1,128 +1,21 @@ const std = @import("std"); -const CrossTarget = std.zig.CrossTarget; - -const cppflags = [_][]const u8{ - "-DASIO_HAS_THREADS", - "-fcolor-diagnostics", - "-std=c++20", - "-Wall", - "-Wextra", - "-Werror", - "-Wpedantic", - "-Wno-deprecated-declarations", - "-Wno-unqualified-std-cast-call", - "-Wno-bitwise-instead-of-logical", //for notcurses - "-fno-sanitize=undefined", - "-gen-cdb-fragment-path", - ".cache/cdb", -}; - pub fn build(b: *std.Build) void { - const enable_tracy_option = b.option(bool, "enable_tracy", "Enable tracy client library (default: no)"); - const tracy_enabled = if (enable_tracy_option) |enabled| enabled else false; - - const options = b.addOptions(); - options.addOption(bool, "enable_tracy", tracy_enabled); - - const options_mod = options.createModule(); - const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const mode = .{ .target = target, .optimize = optimize }; - - const asio_dep = b.dependency("asio", mode); - const tracy_dep = if (tracy_enabled) b.dependency("tracy", mode) else undefined; - - const lib = b.addStaticLibrary(.{ - .name = "thespian", - .target = target, - .optimize = optimize, - }); - if (tracy_enabled) { - lib.root_module.addCMacro("TRACY_ENABLE", "1"); - lib.root_module.addCMacro("TRACY_CALLSTACK", "1"); - } - lib.addIncludePath(b.path("src")); - lib.addIncludePath(b.path("include")); - lib.addCSourceFiles(.{ .files = &[_][]const u8{ - "src/backtrace.cpp", - "src/c/context.cpp", - "src/c/env.cpp", - "src/c/file_descriptor.cpp", - "src/c/file_stream.cpp", - "src/c/handle.cpp", - "src/c/instance.cpp", - "src/c/metronome.cpp", - "src/c/signal.cpp", - "src/c/timeout.cpp", - "src/c/trace.cpp", - "src/cbor.cpp", - "src/executor_asio.cpp", - "src/hub.cpp", - "src/instance.cpp", - "src/trace.cpp", - }, .flags = &cppflags }); - if (tracy_enabled) { - lib.linkLibrary(tracy_dep.artifact("tracy")); - } - lib.linkLibrary(asio_dep.artifact("asio")); - if (lib.rootModuleTarget().os.tag == .windows) { - lib.linkSystemLibrary("mswsock"); - lib.linkSystemLibrary("ws2_32"); - } - lib.linkLibCpp(); - b.installArtifact(lib); const cbor_mod = b.addModule("cbor", .{ .root_source_file = b.path("src/cbor.zig"), }); - const thespian_mod = b.addModule("thespian", .{ - .root_source_file = b.path("src/thespian.zig"), - .imports = &.{ - .{ .name = "cbor", .module = cbor_mod }, - }, - }); - thespian_mod.addIncludePath(b.path("include")); - thespian_mod.linkLibrary(lib); - const tests = b.addTest(.{ .root_source_file = b.path("test/tests.zig"), .target = target, .optimize = optimize, }); - - tests.root_module.addImport("build_options", options_mod); tests.root_module.addImport("cbor", cbor_mod); - tests.root_module.addImport("thespian", thespian_mod); - tests.addIncludePath(b.path("test")); - tests.addIncludePath(b.path("src")); - tests.addIncludePath(b.path("include")); - tests.addCSourceFiles(.{ .files = &[_][]const u8{ - "test/cbor_match.cpp", - "test/debug.cpp", - "test/endpoint_unx.cpp", - "test/endpoint_tcp.cpp", - "test/hub_filter.cpp", - "test/ip_tcp_client_server.cpp", - "test/ip_udp_echo.cpp", - "test/metronome_test.cpp", - "test/perf_cbor.cpp", - "test/perf_hub.cpp", - "test/perf_ring.cpp", - "test/perf_spawn.cpp", - "test/spawn_exit.cpp", - "test/tests.cpp", - "test/timeout_test.cpp", - }, .flags = &cppflags }); - tests.linkLibrary(lib); - tests.linkLibrary(asio_dep.artifact("asio")); - tests.linkLibCpp(); - b.installArtifact(tests); const test_run_cmd = b.addRunArtifact(tests); - const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&test_run_cmd.step); } diff --git a/build.zig.zon b/build.zig.zon index 261423a..89f37b7 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,20 +1,9 @@ .{ - .name = .thespian, - .version = "0.0.1", - .fingerprint = 0xe9ff00fd8e4e01a3, + .name = .cbor, + .version = "1.0.0", + .fingerprint = 0x1feaffc7fc04c445, - .dependencies = .{ - .asio = .{ - .url = "https://github.com/neurocyte/asio/archive/24d28864ec5aae6146d88a172288e3bf3f099734.tar.gz", - .hash = "asio-1.30.2-tLhDdyKA4QBqQFDrsuK_hO1HfqX-DQMl-Sku7yy4vUfM", - }, - .tracy = .{ - .url = "https://github.com/neurocyte/zig-tracy/archive/82f18a661af17089198fb7c489ef253f02b939b5.tar.gz", - .hash = "zig_tracy-0.0.3-5-cp3JZ2AAC6j-gWFhPKXyF6WASJpCzQeNy7Bi712t1a", - }, - }, .paths = .{ - "include", "src", "test", "build.zig", diff --git a/test/tests_cbor.zig b/test/tests.zig similarity index 100% rename from test/tests_cbor.zig rename to test/tests.zig