skargo: merge bin and test into a single binary in dev mode#1123
Draft
skargo: merge bin and test into a single binary in dev mode#1123
Conversation
Preparation for merging bin and test targets into a single binary in dev mode (#1121). Adds: - should_merge_tests(): determines if a unit should include tests - generate_dispatcher(): creates a .sk file that dispatches between user's main and test harness based on SKTEST env var Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When should_merge_tests applies (BinTarget, dev profile, tests exist), the skc() method now: - Includes test source files in the compilation - Generates a dispatcher file that routes to user main or test harness based on the SKTEST environment variable - Exports SkargoDispatch.main as skip_main instead of the user's entry The fingerprint also accounts for test source file mtimes so changes to test files trigger recompilation of the merged binary. Part of #1121. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
In dev mode when tests exist, BinTarget units now also pull in DevelopmentDep dependencies (e.g., sktest) so that test code compiles correctly in the merged binary. Part of #1121. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When in dev mode with a single bin target and tests, skargo test now builds the bin target (which includes test code in merged mode) and runs it with SKTEST=1 to trigger the test harness dispatcher. Falls back to the existing separate test binary behavior for release mode, multi-bin packages, or lib-only packages. Part of #1121. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Use a top-level __skargo_dispatch function instead of a module-scoped one to avoid name resolution issues (module function calling itself) - Only enable merged mode for single-bin packages, since multi-bin packages can't benefit (skargo test wouldn't know which bin to use) Part of #1121. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.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.
Summary
Closes #1121.
[[bin]]target and test sources,skargo buildnow produces a single merged binary containing both app and test codeSKTESTenv var at runtime to route to either the user'smain()or the test harness (SKTest.main)skargo testsetsSKTEST=1and reuses the already-built binary — no recompilation neededskargo runworks unchanged (noSKTESTset → routes to user's main)Files changed
skiplang/skargo/src/build_runner.sk—should_merge_tests()predicate,generate_dispatcher()method, modifiedskc()to include test sources + dispatcher, updated fingerprintingskiplang/skargo/src/build_context.sk—compute_deps()now includes dev dependencies for merged bin targetsskiplang/skargo/src/commands/test.sk—execTest()builds the bin target and runs it withSKTEST=1in merged modeTest plan
skargo buildon a single-bin+tests project produces a merged binarymain()SKTEST=1runs the test harnessskargo testreuses the merged binary (shows "Fresh", ~0.1s) and tests passskargo runroutes to user's main correctlyskargo buildon skargo itself (no tests) is unaffected🤖 Generated with Claude Code