Skip to content

skargo: merge bin and test into a single binary in dev mode#1123

Draft
mbouaziz wants to merge 5 commits intomainfrom
skargo-merge-bin-test
Draft

skargo: merge bin and test into a single binary in dev mode#1123
mbouaziz wants to merge 5 commits intomainfrom
skargo-merge-bin-test

Conversation

@mbouaziz
Copy link
Contributor

Summary

Closes #1121.

  • In dev mode, when a package has exactly one [[bin]] target and test sources, skargo build now produces a single merged binary containing both app and test code
  • A generated dispatcher function checks the SKTEST env var at runtime to route to either the user's main() or the test harness (SKTest.main)
  • skargo test sets SKTEST=1 and reuses the already-built binary — no recompilation needed
  • skargo run works unchanged (no SKTEST set → routes to user's main)
  • Multi-bin packages and release builds fall back to existing separate-binary behavior

Files changed

  • skiplang/skargo/src/build_runner.skshould_merge_tests() predicate, generate_dispatcher() method, modified skc() to include test sources + dispatcher, updated fingerprinting
  • skiplang/skargo/src/build_context.skcompute_deps() now includes dev dependencies for merged bin targets
  • skiplang/skargo/src/commands/test.skexecTest() builds the bin target and runs it with SKTEST=1 in merged mode

Test plan

  • skargo build on a single-bin+tests project produces a merged binary
  • Running the binary directly runs the user's main()
  • Running with SKTEST=1 runs the test harness
  • skargo test reuses the merged binary (shows "Fresh", ~0.1s) and tests pass
  • skargo run routes to user's main correctly
  • Multi-bin package (compiler) falls back to separate test binary
  • skargo build on skargo itself (no tests) is unaffected

🤖 Generated with Claude Code

mbouaziz and others added 5 commits February 27, 2026 18:01
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Faster iteration: merge bin and test

1 participant