Repository navigation
refactor(main): port main from C to Zig - #169
Merged
Merged
Conversation
The program behind main() — subcommand dispatch, the one-shot CLI mode, the MCP server loop, the watcher callback, the parent-death watchdogs, signal handling and the Windows UTF-8 argv rebuild — moves to src/main.zig as cbm_main, declared in src/main.h. main() itself stays in a 3-line src/main.c that calls cbm_main: - the test runners link the same Zig library and define their own main(), so the library cannot define one; - the release version is a C define (scripts/build.sh passes -DCBM_VERSION via CFLAGS_EXTRA), and the Windows release links a Zig library that CI prebuilds without it. The Windows declarations the port needs (CommandLineToArgvW, Toolhelp, signal) are added to cbm_zig_c.h. Comments that pointed at main.c now point at main.zig. Signed-off-by: ata-sesli <atasesli@protonmail.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Ports
src/main.c, the last C module in the planned port order (internal/cbmis out of scope), to Zig. It follows the pattern used by the earlier ports.The program behind
main()moves tosrc/main.zigascbm_main, declared in the newsrc/main.h. That covers:climode;checkExportsincbm_zig.zigcheckscbm_mainagainst its header.Why
main()itself stays in Csrc/main.cshrinks from 857 lines to a short shim:int main(...) { return cbm_main(argc, argv, CBM_VERSION); }. Two constraints keep it in C:main. The test runners link the samelibcbm_zig.aand define their ownmain()intests/test_main.c. The Zig library is one object, so amainexported from it would clash with theirs.scripts/build.shpasses-DCBM_VERSIONthroughCFLAGS_EXTRA. The Windows release links a Zig library that CI prebuilds in a separate job without that define. Reading the version in C keeps--versioncorrect there.Keeping the shim means no changes to
build.zig, the Windows CI job orscripts/build.sh.Other changes
cbm_zig_c.h: includesmain.h. On Windows it also includesshellapi.h(CommandLineToArgvW),tlhelp32.h(parent PID lookup) andsignal.h.Makefile.cbm: listssrc/main.zigandsrc/main.has Zig library inputs.main.cnow point atmain.zig.Behavior
The port is meant to behave identically: same help text, exit codes, shutdown order and watchdog policy. One small difference: the
clipath now frees its argument buffer when server creation fails, where the C version leaked it.Verification
Run locally:
libcbm_zig.acompiles for native macOS,x86_64-linux-gnuandx86_64-windows-gnu, the last two with Zova.cbm_mainis exported and the library has nomainsymbol.zig fmt --check src build.zigpassed.scripts/check-build-sources.shpassed.Not run locally:
--version,cli, MCP stdio). CI is the check for those.clang-format(not installed here).Checklist
make -f Makefile.cbm test) — left to CImake -f Makefile.cbm lint-ci) — left to CI