| [ Web Proxy ] |
| Viewing: https://scriptc.dev/quickstart | [Back] [Original] |
Install the CLI from npm and compile your first binary in a couple of minutes.
--emit=ir|c|llvm|asm|obj. Assembly/object output uses the matching helper installed with scriptc and requires macOS 15+.$ npm install -g scriptcTo work from a clone instead (pnpm install && pnpm build in the repo, then pnpm scriptc from the repo directory), see the repository.
Write ordinary TypeScript:
const who: string = process.argv.length > 2 ? process.argv[2] : "world";
console.log(`hello, ${who}`);Compile and run in one step:
$ scriptc run hello.ts
hello, worldOr produce the executable:
$ scriptc build hello.ts -o hello
$ ./hello scriptc
hello, scriptc
$ ls -la hello
-rwxr-xr-x 1 you staff 329752 helloThat is a self-contained native binary no Node, no node_modules, no JavaScript engine. It starts in about 4ms where Node takes ~35ms to print the same line.
Note the process.argv.length guard in hello.ts: scriptc arrays are dense, so an out-of-bounds read like process.argv[2] with no third argument is a runtime trap, not undefined. This is one of the documented divergences; the compiler and runtime tell you rather than silently differing.
Ask the compiler how static your program is and what, precisely, isn't:
$ scriptc coverage hello.ts
statements analyzed 2
compile statically 2 (100%)
fully static this program has no dynamic remainder.For programs that import npm packages or use any, the report names each dynamic site and each blocker with an error code. See Coverage Reports.
npm packages run in an embedded JavaScript engine, opted in with --dynamic:
import pc from "picocolors";
function banner(text: string): string {
return pc.bold(pc.green(text));
}
const args = process.argv.slice(2);
console.log(banner("scriptc demo"));
console.log(`args: ${args.length}`);$ npm install picocolors
$ scriptc build cli.ts --dynamic -o demo
$ ./demo one two
scriptc demo
args: 2The package's JS is embedded into the binary at build time the executable never reads node_modules and runs from anywhere. See npm Dependencies for how the boundary works.
--emit, --backend llvm, and --sanitize.app.o from an external C or linker build.| Web Proxy Viewer | New URL | Original Page |