-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Log masks | ||
run: echo "::add-mask::$NAME_MASK" | ||
|
||
- uses: actions/checkout@v4 | ||
- uses: mlugg/setup-zig@v1 | ||
with: | ||
version: master | ||
|
||
- name: Run zig fmt | ||
if: matrix.os == 'self-hosted' | ||
run: zig fmt --check . | ||
|
||
- name: Run module tests | ||
run: zig build test --summary all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This sets the `.gitignore` to be a *whitelist* by default. | ||
**/** | ||
!*/ | ||
|
||
|
||
# Whitelist | ||
!*.md | ||
!LICENSE-MIT | ||
!.gitignore | ||
!build.zig | ||
!build.zig.zon | ||
!.github/**/*.yml | ||
|
||
!*.zig | ||
|
||
# Blacklist (overrides Whitelist) | ||
**/zig-out/** | ||
**/zig-cache/** | ||
**/.zig-cache/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) void { | ||
const target = b.standardTargetOptions(.{}); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
|
||
const lib = b.option( | ||
std.builtin.LinkMode, | ||
"lib", | ||
"Build an exportable C library.", | ||
); | ||
|
||
const mod = b.addModule("serialport", .{ | ||
.root_source_file = b.path("src/serialport.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
|
||
const test_step = b.step("test", "Run unit tests"); | ||
|
||
const mod_unit_tests = b.addTest(.{ | ||
.root_source_file = b.path("src/serialport.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
const run_mod_unit_tests = b.addRunArtifact(mod_unit_tests); | ||
test_step.dependOn(&run_mod_unit_tests.step); | ||
|
||
if (lib) |l| { | ||
// Library Artifact | ||
{ | ||
const library = if (l == .static) b.addStaticLibrary(.{ | ||
.name = "serialport", | ||
.root_source_file = b.path("src/lib.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}) else b.addSharedLibrary(.{ | ||
.name = "serialport", | ||
.root_source_file = b.path("src/lib.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
library.root_module.addImport("serialport", mod); | ||
b.installArtifact(library); | ||
} | ||
// Library Tests | ||
{ | ||
const lib_unit_tests = b.addTest(.{ | ||
.root_source_file = b.path("src/lib.zig"), | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
lib_unit_tests.root_module.addImport("serialport", mod); | ||
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); | ||
test_step.dependOn(&run_lib_unit_tests.step); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.{ | ||
.name = "serialport", | ||
.version = "0.0.0", | ||
.minimum_zig_version = "0.11.0", | ||
.dependencies = .{}, | ||
.paths = .{ | ||
"build.zig", | ||
"build.zig.zon", | ||
"src", | ||
"LICENSE-MIT", | ||
"README.md", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//! By convention, root.zig is the root source file when making a library. If | ||
//! you are making an executable, the convention is to delete this file and | ||
//! start with main.zig instead. | ||
const std = @import("std"); | ||
const testing = std.testing; | ||
|
||
export fn add(a: i32, b: i32) i32 { | ||
return a + b; | ||
} | ||
|
||
test "basic add functionality" { | ||
try testing.expect(add(3, 7) == 10); | ||
} |
Empty file.