Mojo target manual
The Mojo target compiles TypeScript into Mojo source and a Pixi project. Mojo performs the native build. The source remains TypeScript; you do not write a second implementation in Mojo.
A first function
import type { i32 } from "@tsonic/mojo/types.js";
export function add(left: i32, right: i32): i32 {
return left + right;
}
The native proof project produces:
def add(left: Int32, right: Int32) -> Int32:
return left + right
@tsonic/mojo/types.js is a virtual source module supplied by the target, not a
separate npm package. Ordinary TypeScript number uses Float64; i32 asks
for an exact native Int32.
Build a project
The Mojo target currently requires a source-workspace installation. Its npm
package is not published, and npm create tsonic -- --target mojo is not a
supported install route. The target repository
owns the source setup and pinned SDK instructions. C# and Rust use the published
project creator.
With the CLI and Mojo target installed in that workspace, put the function in
src/App.ts and use:
{
"entryPoint": "App.ts",
"rootDir": "src",
"outDir": "out",
"targets": [{
"id": "mojo",
"options": { "packageName": "example", "outputType": "lib" }
}]
}
Activate the pinned SDK before generation. The compiler is needed for native API queries and formatting, not just the final build.
./node_modules/.bin/tsonic build --project tsonic.json
pixi run --manifest-path out/mojo/pixi.toml build
This creates a library. See projects and output for applications and integration with an existing Pixi project.