Skip to main content

Build And Test

Rule

Do not manually drive the repo with ad-hoc cmake commands for normal work.

Use morphc — the unified build system (scripts/morphc_build, invoked via morphc.bat on Windows or python3 -m scripts.morphc_build elsewhere):

morphc build                 :: smart incremental build
morphc build --test :: build once, then run full tests
morphc build --test "flow" :: build once, then run tests matching pattern
morphc build --test "a" --test "b" :: multiple filtered passes (one run per pattern)
morphc test :: build + run all tests
morphc test "flow" :: filtered tests (unit + behavior rules below)
morphc doctor :: diagnose environment
morphc fails :: show details of the last test failures

If a background build is already running, do not start morphc test. Wait for it to finish, or use morphc build --test ... so build and tests are serialized. (The driver detects active compiler/link processes on Windows and refuses test when they overlap the workspace.)

Optional env / flags

  • Toolchain: Usually no need to set LLVM_DIR or MORPH_TOOLCHAIN_BIN. The driver probes MSYS2 MinGW, LLVM, Ninja, and CMake. To force the MinGW bin directory, set MORPH_TOOLCHAIN_BIN (derived from config/branding.tomlMORPH_* when canonical = "morph").
  • morphc build --test extras: --test-unit-only, --test-timeout, --test-stop-on-fail, --test-expose N (behavior suite).
  • morphc test: --list, --unit-only, --timeout, --stop-on-fail, --expose, -j.

Typical auto-detected Windows paths (examples, not requirements):

  • C:\msys64\mingw64\bin\c++.exe
  • C:\msys64\mingw64\bin\ninja.exe
  • C:\msys64\mingw64\lib\cmake\llvm\LLVMConfig.cmake

Full pipeline

From repo root:

morphc build

This:

  • resolves workspace under %LOCALAPPDATA%\<vendor>\workspaces\<canonical>\ (e.g. %LOCALAPPDATA%\Morph\workspaces\morph\)
  • auto-detects toolchain (MSYS2, LLVM, Ninja)
  • hashes manifests (morph.toml, feature.toml, block.toml, domain.toml, relevant CMakeLists.txt, etc.) and reconfigures when needed
  • builds with Ninja (or fallback generator) and surfaces structured errors

Targeted tests

morphc test "PackageManager"
morphc test "flow"
morphc test --list
morphc test --unit-only

Filtered morphc test "pattern": if no C++ unit test names match, the driver skips the unit binary and runs behavior tests whose .mx sources match the pattern. With no pattern, unit tests run first and the behavior suite runs only after unit tests succeed. See scripts/morphc_build/test_runner.py for details.

Build targets

Pass CMake target names to morphc build -t (or -t "t1 t2"):

morphc build -t morphlang_unit_tests   :: unit test binary only
morphc build -t morphlang :: compiler CLI only

Other targets exist in CMakeLists.txt (e.g. morphlang-lsp, domain hosts). There is no ncon executable target in the current top-level CMake; do not document it unless it returns to the tree.

morphc run

morphc run path\to\File.mx -- arg1 arg2

Ensures the morphlang target is built, then runs morph run <file> with the staged compiler under the workspace bin directory (see scripts/morphc_build/cli.py::_cmd_run). Behavior matches the morph run CLI for that file/cwd.

Command summary

CommandDescription
morphc buildIncremental build
morphc build --cleanClean reconfigure + build
morphc build --debugDebug build
morphc build -t TARGETBuild specific target(s)
morphc build --test [PATTERN]After build, run tests (omit pattern = full suite); repeatable
morphc build --test --test-unit-onlyPost-build: C++ unit tests only
morphc testBuild + all tests
morphc test PATTERNBuild + filtered tests
morphc test --listList tests
morphc test --unit-onlySkip behavior suite
morphc failsLast failure details
morphc configureConfigure only
morphc configure --cleanWipe cache + configure
morphc cleanRemove workspace build dir + state snapshot
morphc doctorEnvironment diagnosis
morphc statusBuild state / history
morphc watchWatch + rebuild
morphc run FILEBuild compiler + morph run FILE

Aliases (examples): bbuild, ttest, rrun, wwatch, cfgconfigure, docdoctor, ststatus.

Smart reconfigure

The driver hashes CMake and morph manifest inputs (including under morphs/ and domains/) and triggers reconfigure when they change.

Logs

  • Build logs: %LOCALAPPDATA%\<WorkspaceVendor>\workspaces\<canonical>\logs\build_*.log
  • Test results: %LOCALAPPDATA%\<WorkspaceVendor>\workspaces\<canonical>\build-mingw\test-results\
  • Quick state: morphc status

For default branding (canonical = morph, vendor dir Morph), that is %LOCALAPPDATA%\Morph\workspaces\morph\....

Anti-pattern

Avoid unless you are changing the build system itself:

  • cmake -S . -B build / cmake --build ... for routine work
  • invoking Ninja directly against ad-hoc build dirs
  • relying on n.bat or raw build.sh when morphc is available

Cross-platform

MethodCommandNotes
morphcmorphc.bat … or python3 -m scripts.morphc_build …Preferred
Makemake / make test FILTER=…Delegates to scripts.morphc_build