The cshiftc command
cshiftc builds, runs, checks and publishes CShift programs. It works on a project (a folder with a cshift.json,
see projects and the build) or on single source files. cshiftc --help prints a short version of this
page.
cshiftc new hello a new projectcshiftc new game2d a 2D game with a window (asks a few questions)cshiftc run hello build it and run itcshiftc publish hello the program for the browser: hello/bin/hello.htmlCommands
Section titled “Commands”| Command | What it does |
|---|---|
cshiftc [options] a.cshift b.cshift |
compiles the files into one program, without a project |
cshiftc new <folder> |
creates a project: cshift.json, src/main.cshift, .gitignore |
cshiftc new game2d [folder] |
creates a 2D game with a window (System.Graphics), after a few questions |
cshiftc build [project] |
builds the project: bin/<name> (.exe on Windows) |
cshiftc run [project] [-- args] |
builds the project and runs it; the arguments after -- go to the program |
cshiftc publish [project | files] |
the program for the browser: one HTML file with everything in it |
cshiftc serve [project | files] |
publish on a local web server, built again when a file changes |
cshiftc test [project | files] [--filter <text>] |
builds the tests (test "name" { ... }) and runs each in a process of its own |
cshiftc check [project | files] |
reports the errors and generates nothing |
cshiftc query ... |
answers questions about the code as JSON (for editors) |
cshiftc doc [project | files] |
the doc comments as JSON |
project is a folder that has a cshift.json, or the path of the file itself. Without it, cshift.json is looked up
in the current folder and then in its parent folders, as git does. Options on the command line override the
project file.
Source files end in .cshift. .csh, the extension until 0.31, is still read.
cshiftc new hellocd hellocshiftc runThe project builds an executable from the files in src/. The app template
on GitHub is the same project with a CI workflow that builds it.
new game2d
Section titled “new game2d”cshiftc new game2dA 2D game: a window that shows a picture of pixels which the program draws, on Windows, Linux and in the browser.
cshiftc asks a few questions; Enter takes the answer in brackets:
Project name [game]: questProject folder [C:\Users\me\code\quest]:Audio: 1) None 2) System.Audio - sound output of the standard library (Windows, Linux, browser)Choice [1]: 2Size of the picture in pixels (width x height; the window scales it up) [320x180]:cshiftc run in the new folder opens the window: a rectangle that the arrow keys move, Esc or the close button
quits (with sound, Space beeps). It draws with System.Graphics of the standard library, so the
project has no dependencies and nothing to install:
src/main.cshift |
the game loop: Window, Input, a Canvas that draws the picture, ShowScaled shows it with sharp pixels at 60 frames a second |
src/Sound.cshift |
with System.Audio: beeps made by the program, refilled once a frame |
.github/workflows/build.yml |
builds the program for Windows and Linux and the page for the browser on GitHub, as artifacts of the run |
cshiftc build makes the program for the system it runs on (Linux needs no X11 headers: libX11 is loaded when the
window opens); cshiftc publish makes bin/<name>.html on any system, where the window is a <canvas>
(wasm.md).
The questions can be answered in advance, for scripts: a folder (the name is taken from it), --name <name>,
--audio none|system, --size <width>x<height>; --yes takes the defaults for the rest. The
folder must not exist or must be empty. (cshiftc new ./game2d makes an ordinary project in a folder named game2d.)
build and run
Section titled “build and run”cshiftc build the project in this folder (or above)cshiftc build demo-ui -O0 -g another project, without optimizations, with debug informationcshiftc run -- input.txt --verbose run it: the program gets input.txt and --verbosecshiftc hello.cshift -o hello single files: hello.exe on Windowscshiftc hello.cshift --run -- a b single files, built and run with the arguments a and bThe output is bin/<name> (output in cshift.json, -o on the command line). run passes the exit code of the
program on.
The target decides what is built:
| Option | The program |
|---|---|
| (none) | a native program for this computer: Windows, Linux or macOS, with LLVM (clang optimizes and links) |
--backend wasm |
a WebAssembly module for WASI, with CShift’s own backend; nothing else is needed (WebAssembly) |
--target wasm32-wasi |
a WebAssembly module with LLVM (needs clang, wasi-libc and wasm-ld) |
--target m68k-amigaos |
an AmigaOS program, with CShift’s own 68000 backend (the Amiga) |
cshiftc build --backend wasm -o program.wasmnode tests/wasi-run.mjs program.wasm # or: wasmtime --dir . program.wasmcshiftc build demo-ui --target m68k-amigaos # an Amiga program: copy it to the Amiga, or to an emulator's drivepublish
Section titled “publish”cshiftc publish the project in this folder -> bin/<name>.htmlcshiftc publish demo-snake -> demo-snake/bin/demo-snake.htmlcshiftc publish hello.cshift single files -> hello.htmlcshiftc publish -o page.html another name for the pagecshiftc publish --page my.html the program in a page of your own (or "page" in cshift.json)publish builds the program with the wasm backend and writes one HTML file that has everything in it: the
program, the runtime (web/cshift.js) and the files that the program reads ("assets" in
cshift.json). The page loads nothing else: it opens with a double click and can be put on any web server as it is.
The page shows the program’s console. A program with a window gets a <canvas> with the keyboard and the mouse:
System.Ui, and GLFW with OpenGL (WebGL 2), game loop and all. The details, and what does not
work in the browser, are in WebAssembly. A project can bring its
own page, with placeholders where the program goes (an own page).
--target and --backend cannot be changed for publish (it always builds --backend wasm); -O0 … -O3 and
-v can be given.
cshiftc serve http://localhost:8080/ (or the next free port)cshiftc serve demo-ui --open and open it in the browsercshiftc serve --port 3000 --host 0.0.0.0 reachable from other devices of the networkserve is publish that keeps going, like vite or ng serve. It builds the page and serves it. It watches the
files of the project and of its dependencies, and builds again when one changes. The page in the browser then
reloads itself. A failed build shows the compiler’s errors on the page until the next build works. Ctrl+C ends the
server.
| Option | |
|---|---|
--port <n> |
the port; by default the first free one from 8080 on |
--host <address> |
where the server listens: 127.0.0.1 (this computer only, the default) or 0.0.0.0 (every network) |
--open |
opens the page in the browser |
cshiftc test the tests of the project in the current directory (or above)cshiftc test path/to/projectcshiftc test a.cshift b.cshift the tests of single filescshiftc test --filter MinMax only the tests whose name contains the textBuilds the program’s tests (test "name" { ... }, without the program’s Main) into
obj/<name>-tests and runs every test in a process of its own: a panic ends only its test. Prints ok or FAIL per
test; for a failed one its place, the panic or error, and what it wrote. Exit code 0 when all passed, 1 otherwise. The
build options (-O, -g, --unchecked, …) apply; tests run on this computer, so --target and the wasm/m68k
backends are not possible here.
check, query and doc
Section titled “check, query and doc”These commands are used by editors and tools. They run the compiler’s front end and generate no program.
cshiftc check all errors of the project (up to 50), as file:line:column: error: textcshiftc query --at src/main.cshift 12 8 the name at line 12, column 8: its type, documentation, definitioncshiftc query --at src/main.cshift 12 8 --references the places where it is usedcshiftc query --at src/main.cshift 12 8 --rename the places that renaming it changes (or why it cannot be)cshiftc query --at src/main.cshift 12 9 --members what can follow 'name.'cshiftc query --outline src/main.cshift the declarations of the filecshiftc doc the documentation of the standard librarycshiftc doc mylib --require-docs -o api.json a library's documentation; every public declaration needs a doc commentquery writes JSON. With --overlay <file> <text file>, the text of <file> comes from <text file>, so an editor
can ask about text that is not saved yet. The VS Code extension uses check and
query. The format of doc is described in doc comments.
Options
Section titled “Options”| Option | |
|---|---|
-o <file> |
the output file |
-O0 … -O3 |
the optimization level (default -O2) |
-g |
debug information for gdb and lldb (debugging); best with -O0 |
--target <triple> |
the target: wasm32-wasi, m68k-amigaos, or a triple of clang (default: this computer) |
--backend <name> |
the code generator: llvm (the default), wasm or m68k (the default for AmigaOS) |
--run |
single files: run the program after building it (its arguments after --) |
-c |
an object file only, not linked |
--emit-llvm |
write the LLVM IR (.ll) instead of a program |
--emit-asm |
m68k backend: write the assembly (.s) instead of a program |
--unchecked |
integer overflow wraps around instead of ending the program with a panic |
--checked |
integer overflow panics (the default; overrides "unchecked": true in cshift.json) |
--gui |
Windows: a program of the GUI subsystem, without a console window (like "gui": true) |
--page <file> |
publish, serve: the page template instead of the built-in page (like "page") |
-l<name>, -L<dir> |
a library to link, a search path of the linker; file.a, file.o are linked as they are |
-I<dir>, -D<name>[=value] |
an include path, a macro for C headers (using X from "header.h", C interop) |
--ffi-api=<text> |
headers whose path contains <text> belong to the imported API |
--ndk <dir> |
the AmigaOS NDK, for libraries from SFD files |
--cc <program> |
the C compiler that links (default: CSHIFT_CC, the bundled toolchain, then clang) |
--stdlib <dir> |
use this standard library instead of the one built into cshiftc |
--arc-stats |
print the heap allocations and frees when the program ends (for debugging) |
-v |
verbose output |
--version |
print the version |
--clear-cache |
delete the toolchains that a standalone cshiftc has unpacked (all versions) |
-h, --help |
print the help |
Environment variables
Section titled “Environment variables”| Variable | |
|---|---|
CSHIFT_CC |
the C compiler that links (like --cc) |
CSHIFT_NDK |
the AmigaOS NDK (like --ndk) |
CSHIFT_WASI_SYSROOT |
the sysroot of WASI for --target wasm32-wasi (WebAssembly) |