Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .github/workflows/main.yml

This file was deleted.

84 changes: 84 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Release

on:
workflow_run:
workflows: ["Test"]
types: [completed]
branches:
- main
workflow_dispatch:

jobs:
release:
strategy:
matrix:
os: [Linux]
runs-on: [self-hosted, "${{ matrix.os }}"]
defaults:
run:
shell: bash
if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions:
contents: write
steps:
- name: Log masks on Linux
if: matrix.os == 'Linux'
run: echo "::add-mask::$NAME_MASK"

- name: Log masks on Windows
if: matrix.os == 'Windows'
run: echo "::add-mask::$env:NAME_MASK"

- uses: actions/checkout@v4
with:
persist-credentials: false

- uses: mlugg/setup-zig@v2
with:
version: 0.15.2

- uses: actions/github-script@v7
id: parse-version
env:
SHA: "${{env.parentSHA}}"
with:
script: |
const script = require('./.github/workflows/zig-version.js');
await script({core});

- name: Check Existing Releases
id: check-version
run: |
echo "EXISTS=$( \
if gh release view ${VERSION} | grep -q "${VERSION}"; \
then echo "exists"; \
else echo ""; \
fi)" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build Windows
if: ${{ steps.check-version.outputs.EXISTS == '' }}
run: |
zig build \
-Doptimize=ReleaseSafe \
-Dtarget=x86_64-windows-msvc
zip -j "windows-${NAME}-${VERSION}.zip" \
"./zig-out/bin/${NAME}.exe" \
"./zig-out/bin/${NAME}.pdb"

- name: Build Linux
if: ${{ steps.check-version.outputs.EXISTS == '' }}
run: |
zig build -Doptimize=ReleaseSafe -Dtarget=x86_64-linux-gnu
zip -j "linux-${NAME}-${VERSION}.zip" \
"./zig-out/bin/${NAME}"

- name: Create release
if: ${{ steps.check-version.outputs.EXISTS == '' }}
run: |
gh release create --generate-notes "${VERSION}" \
windows-${NAME}-${VERSION}.zip \
linux-${NAME}-${VERSION}.zip
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43 changes: 43 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Test

on:
push:
branches:
- main
- chain_commands
pull_request:
branches:
- main
- chain_commands
workflow_dispatch:

jobs:
test:
strategy:
fail-fast: false
matrix:
os: [Linux, Windows]
runs-on: [self-hosted, "${{ matrix.os }}"]
steps:
- name: Log masks on Linux
if: matrix.os == 'Linux'
run: echo "::add-mask::$NAME_MASK"

- name: Log masks on Windows
if: matrix.os == 'Windows'
run: echo "::add-mask::$env:NAME_MASK"

- uses: actions/checkout@v4
with:
persist-credentials: false

- uses: mlugg/setup-zig@v2
with:
version: 0.16.0

- name: Run zig fmt
if: matrix.os == 'Linux'
run: zig fmt --check .

- name: Run tests
run: zig build test -Dmdfunc_mock -freference-trace --summary all
23 changes: 23 additions & 0 deletions .github/workflows/zig_version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const fs = require("fs").promises;

module.exports = async ({ core }) => {
// Parse `build.zig.zon` for version
let version;
const name = "mmc-cli";
const raw = await fs.readFile("./build.zig.zon");
const lines = raw.toString().split("\n");
lines.forEach((line) => {
line = line.trim();
if (line.startsWith(".version")) {
const parts = line.split("=");
const version_raw = parts[1];
const version_cleaned = version_raw
.replaceAll('"', "")
.replaceAll(",", "");
version = version_cleaned.trim();
}
});

core.exportVariable("NAME", name);
core.exportVariable("VERSION", version);
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ zig-out/**
zig-cache/**
.zig-cache/**
vendor/**
zig-pkg/**
48 changes: 36 additions & 12 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,39 @@ pub fn build(b: *std.Build) !void {
"Enable building a mock version of the MELSEC data link library.",
) orelse (target.result.os.tag != .windows);

const mcl = b.dependency("mcl", .{
const chrono = b.dependency("chrono", .{});
const build_zig_zon = b.createModule(.{
.root_source_file = b.path("build.zig.zon"),
.target = target,
.optimize = optimize,
});

const mmc_api = b.dependency("mmc_api", .{
.target = target,
.optimize = optimize,
.mdfunc = mdfunc_lib_path,
.mdfunc_mock = mdfunc_mock_build,
});
const network_dep = b.dependency("network", .{});
const chrono = b.dependency("chrono", .{});

const exe = b.addExecutable(.{
.name = "mmc-cli",
const imports: []const std.Build.Module.Import = &.{
.{ .name = "build.zig.zon", .module = build_zig_zon },
.{ .name = "chrono", .module = chrono.module("chrono") },
};

const mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
.error_tracing = true,
});

const exe = b.addExecutable(.{
.name = "mmc-cli",
.root_module = mod,
});
exe.root_module.addImport("network", network_dep.module("network"));
exe.root_module.addImport("mcl", mcl.module("mcl"));
exe.root_module.addImport("chrono", chrono.module("chrono"));

exe.root_module.addImport("mcl", mmc_api.module("mcl"));

b.installArtifact(exe);

Expand All @@ -51,14 +66,23 @@ pub fn build(b: *std.Build) !void {

// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
const mmc_api_mock = b.dependency("mmc_api", .{
.target = target,
.optimize = optimize,
.mdfunc = mdfunc_lib_path,
.mdfunc_mock = true,
});

const test_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = imports,
.error_tracing = true,
});
unit_tests.root_module.addImport("network", network_dep.module("network"));
unit_tests.root_module.addImport("mcl", mcl.module("mcl"));
unit_tests.root_module.addImport("chrono", chrono.module("chrono"));

const unit_tests = b.addTest(.{ .root_module = test_mod });
unit_tests.root_module.addImport("mcl", mmc_api_mock.module("mcl"));

const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
Expand Down
18 changes: 7 additions & 11 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
.{
.name = .mmc_cli,
.version = "0.2.4",
.fingerprint = 0x392c749893371ea5,
.minimum_zig_version = "0.14.0-dev.15+d4bc64038",
.fingerprint = 0x392c7498d8f608a5,
.minimum_zig_version = "0.16.0",
.dependencies = .{
.network = .{
.url = "https://github.com/mochalins/zig-network/archive/359fec9.tar.gz",
.hash = "12206c7cbba4130ac158f7759c81ae4186c3e9f914bc79b0544492d85405ba01aaa4",
},
.mcl = .{
.url = "https://github.com/pmotionf/mcl/archive/4d1d168.tar.gz",
.hash = "mcl-0.3.1-r3NKp28IAQBOCnJLpdmMJEe4ZfvikMnLzA2XPwjREj8I",
.mmc_api = .{
.url = "https://github.com/pmotionf/mmc-api/archive/6ab55a0.tar.gz",
.hash = "mmc_api-0.0.0-P5raRwlKMwC_S8UFqtWX1Pv6puh_FhSGH-D57eDzAqws",
},
.chrono = .{
.url = "https://github.com/pmotionf/chrono/archive/620de75.tar.gz",
.hash = "chrono-0.1.0-uVd76GvCAwAvWrHupKdlB_UrmfZHRuVP-P4Xi_G8hz3R",
.url = "https://github.com/aaumar25/chrono/archive/adfc771.tar.gz",
.hash = "chrono-0.1.0-uVd76BPDAwAyXqy0OAP1MvUyfk72pvv7e6bU7s2TqV0h",
},
},
.paths = .{""},
Expand Down
20 changes: 10 additions & 10 deletions src/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,24 @@ parsed: std.json.Parsed(Parse),

pub const Module = enum {
mcl,
return_demo2,
};

const ModuleConfig = union(Module) {
mcl: MclConfig,
return_demo2: ReturnDemo2Config,
};

const Parse = struct {
modules: []ModuleConfig,
};

pub fn parse(allocator: std.mem.Allocator, f: std.fs.File) !Config {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const a = arena.allocator();
const f_reader = f.reader();
var json_reader = std.json.reader(a, f_reader);

pub fn parse(io: std.Io, gpa: std.mem.Allocator, f: std.Io.File) !Config {
var file_buffer: [4096]u8 = undefined;
var file_reader = f.reader(io, &file_buffer);
var json_reader: std.json.Reader = .init(gpa, &file_reader.interface);
defer json_reader.deinit();
const _result = try std.json.parseFromTokenSource(
Parse,
allocator,
gpa,
&json_reader,
.{},
);
Expand All @@ -47,3 +43,7 @@ pub fn modules(self: *Config) []const ModuleConfig {
pub fn deinit(self: *Config) void {
self.parsed.deinit();
}

test {
std.testing.refAllDecls(@This());
}
Loading
Loading