Skip to content

Compiling simple programs

A Juvix file must declare a module whose name corresponds exactly to the name of the file. For example, a file Hello.juvix must declare a module Hello:

-- Hello world example. This is a comment.
module Hello;

-- Import the standard library prelude, including the 'String' type
open import Stdlib.Prelude;

main : String;
main := "Hello world!";

A file compiled to an executable must define the zero-argument function main of type IO which is evaluated when running the program.

To compile the file Hello.juvix type juvix compile Hello.juvix. Typing juvix compile --help will list all options to the compile command.

Compilation targets

Since version 0.3 Juvix supports three compilation targets. The targets are specified with the -t option: juvix compile -t target file.juvix.

  1. native. This is the default. Produces a native 64bit executable for your machine.
  2. wasm32-wasi. Produces a WebAssembly binary which uses the WASI runtime.
  3. geb. Produces a GEB input file.

Compilation options

To see all compilation options type juvix compile --help. The most commonly used options are:

  • -t target: specify the target,
  • -g: generate debug information and runtime assertions,
  • -o file: specify the output file.

Juvix projects

A Juvix project is a collection of Juvix modules inside one main project directory containing a juvix.yaml metadata file. The name of each module must coincide with the path of the file it is defined in, relative to the project's root directory. For example, if the file is root/Data/List.juvix then the module must be called Data.List, assuming root is the project's directory.

To interactively initialize a Juvix project in the current directory, use juvix init.

To check that Juvix is correctly detecting your project's root, you can run the command juvix dev root File.juvix.

See also: Modules Reference.