Changes
10 changed files (+248/-0)
-
-
@@ -24,3 +24,8 @@ charset = utf-8spelling_language = en-US trim_trailing_whitespace = true insert_final_newline = true # Formatting style used in `zig fmt`. It does not allow any customization. [*.{zig,zon}] indent_style = space indent_size = 4
-
-
.gitignore (new)
-
@@ -0,0 +1,18 @@# Copyright 2025 Shota FUJI # # Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. # You may not use, copy, modify, or distribute this file except according to those terms. You can # find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, # Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Apache License, Version # 2.0 at <https://www.apache.org/licenses/LICENSE-2.0> # # SPDX-License-Identifier: 0BSD OR Apache-2.0 # # === # This file contains project specific ignore rule. Do not put environment (OS, IDE) specific rules. # `zig build` cache .zig-cache # Files generated by `zig build` zig-out
-
-
.tool-versions (new)
-
@@ -0,0 +1,18 @@# Copyright 2025 Shota FUJI # # Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. # You may not use, copy, modify, or distribute this file except according to those terms. You can # find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, # Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Apache License, Version # 2.0 at <https://www.apache.org/licenses/LICENSE-2.0> # # SPDX-License-Identifier: 0BSD OR Apache-2.0 # # === # # This file declares versions of developer toolings. A compatible version manager such as asdf-vm # <https://asdf-vm.com/> and mise-en-place <https://mise.jdx.dev/> loads this file and can install, # configure, and activate the toolings easily. zig 0.14.0 dprint 0.49.0
-
-
build.zig (new)
-
@@ -0,0 +1,66 @@// Copyright 2025 Shota FUJI // // Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. // You may not use, copy, modify, or distribute this file except according to those terms. You can // find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, // Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Apache License, Version // 2.0 at <https://www.apache.org/licenses/LICENSE-2.0> // // SPDX-License-Identifier: 0BSD OR Apache-2.0 // // === // // This file defines how the steps and options for `zig build` command. See official documentation // <https://ziglang.org/learn/build-system/> for more info. const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode of the generated library file") orelse .static; // Exports Zig API, so other project depends on this library. const module = b.addModule("sood", .{ .root_source_file = b.path("src/lib.zig") }); // Library build (C API). const lib = b.addLibrary(.{ .linkage = linkage, .name = "sood", .root_module = b.createModule(.{ .root_source_file = b.path("src/c.zig"), .target = target, .optimize = optimize, }), }); b.installArtifact(lib); b.default_step.dependOn(&lib.step); // Install include/sood.h const install_header = b.addInstallFileWithDir(b.path("src/c.h"), .header, "sood.h"); b.getInstallStep().dependOn(&install_header.step); // Example (Zig) const example_zig_step = b.step("example-zig", "Build Zig example"); const example_zig = b.addExecutable(.{ .name = "example_zig", .root_source_file = b.path("examples/basic.zig"), .target = target, .optimize = optimize, }); example_zig.root_module.addImport("sood", module); example_zig_step.dependOn(&b.addInstallArtifact(example_zig, .{}).step); // Example (C) const example_c_step = b.step("example-c", "Build C example"); const example_c = b.addExecutable(.{ .name = "example_c", .target = target, .optimize = optimize, }); example_c.addCSourceFile(.{ .file = b.path("examples/basic.c") }); example_c.linkLibrary(lib); example_c.addIncludePath(.{ .cwd_relative = b.h_dir }); example_c_step.dependOn(&install_header.step); example_c_step.dependOn(&b.addInstallArtifact(example_c, .{}).step); }
-
-
dprint.jsonc (new)
-
@@ -0,0 +1,37 @@// Copyright 2025 Shota FUJI // // Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. // You may not use, copy, modify, or distribute this file except according to those terms. You can // find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, // Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Apache License, Version // 2.0 at <https://www.apache.org/licenses/LICENSE-2.0> // // SPDX-License-Identifier: 0BSD OR Apache-2.0 // // === // // This file is configuration for dprint <https://dprint.dev>, a code formatter tool. { "excludes": ["LICENSES/**/*"], "lineWidth": 100, "newLineKind": "lf", "useTabs": true, "exec": { "cwd": "${configDir}", "commands": [ { "command": "zig fmt --stdin", "exts": ["zig"], }, { "command": "zig fmt --zon --stdin", "exts": ["zon"], }, ], }, "plugins": [ "https://plugins.dprint.dev/exec-0.5.1.json@492414e39dea4dccc07b4af796d2f4efdb89e84bae2bd4e1e924c0cc050855bf", "https://plugins.dprint.dev/json-0.20.0.wasm", ], }
-
-
examples/basic.c (new)
-
@@ -0,0 +1,16 @@// Copyright 2025 Shota FUJI // // Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. // You may not use, copy, modify, or distribute this file except according to those terms. You can // find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, // Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Apache License, Version // 2.0 at <https://www.apache.org/licenses/LICENSE-2.0> // // SPDX-License-Identifier: 0BSD OR Apache-2.0 #include <stdio.h> #include <sood.h> int main(int argc, char **argv) { printf("%d\n", sood_add(1, 2)); }
-
-
examples/basic.zig (new)
-
@@ -0,0 +1,17 @@// Copyright 2025 Shota FUJI // // Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. // You may not use, copy, modify, or distribute this file except according to those terms. You can // find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, // Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Apache License, Version // 2.0 at <https://www.apache.org/licenses/LICENSE-2.0> // // SPDX-License-Identifier: 0BSD OR Apache-2.0 const std = @import("std"); const sood = @import("sood"); pub fn main() void { std.debug.print("{d}\n", .{sood.add(1, 2)}); }
-
-
src/c.h (new)
-
@@ -0,0 +1,35 @@// Copyright 2025 Shota FUJI // // Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. // You may not use, copy, modify, or distribute this file except according to those terms. You can // find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, // Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Apache License, Version // 2.0 at <https://www.apache.org/licenses/LICENSE-2.0> // // SPDX-License-Identifier: 0BSD OR Apache-2.0 // // === // // Header file for the C-compatible library file (compile artifact of `c.zig`). This file is hand- // written due to Zig compiler cannot generate header file for now. See more details at // <https://github.com/ziglang/zig/issues/9698>. And worse, as there is no check process/tool for // verifying C header file and ABI, you should carefully review the code here. Once Zig is capable // of automatically generating C header file, let's get rid of this file immediately. // <https://github.com/ziglang/zig/issues/20654> #ifndef SOOD_H #define SOOD_H #ifdef __cplusplus extern "C" { #endif #include <stdint.h> int32_t sood_add(int32_t a, int32_t b); #ifdef __cplusplus } #endif #endif // SOOD_H
-
-
src/c.zig (new)
-
@@ -0,0 +1,19 @@// Copyright 2025 Shota FUJI // // Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. // You may not use, copy, modify, or distribute this file except according to those terms. You can // find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, // Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Apache License, Version // 2.0 at <https://www.apache.org/licenses/LICENSE-2.0> // // SPDX-License-Identifier: 0BSD OR Apache-2.0 // // === // // C API. const sood = @import("lib.zig"); export fn sood_add(a: i32, b: i32) i32 { return sood.add(a, b); }
-
-
src/lib.zig (new)
-
@@ -0,0 +1,17 @@// Copyright 2025 Shota FUJI // // Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. // You may not use, copy, modify, or distribute this file except according to those terms. You can // find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, // Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Apache License, Version // 2.0 at <https://www.apache.org/licenses/LICENSE-2.0> // // SPDX-License-Identifier: 0BSD OR Apache-2.0 // // === // // Zig API. pub fn add(a: i32, b: i32) i32 { return a + b; }
-