Janet 1.39.1-e9c6678 Documentation
(Other Versions: 1.38.0 1.37.1 1.36.0 1.35.0 1.34.0 1.31.0 1.29.1 1.28.0 1.27.0 1.26.0 1.25.1 1.24.0 1.23.0 1.22.0 1.21.0 1.20.0 1.19.0 1.18.1 1.17.1 1.16.1 1.15.0 1.13.1 1.12.2 1.11.1 1.10.1 1.9.1 1.8.1 1.7.0 1.6.0 1.5.1 1.5.0 1.4.0 1.3.1 )

Building Projects

Building projects with jpm

Once you have the project on your machine, building the various artifacts should be pretty simple.

Global install

sudo jpm deps
jpm build
jpm test
sudo jpm install

(On Windows, sudo is not required. Use of sudo on POSIX systems depends on whether you installed janet to a directory owned by the root user.)

User local install

The JANET_TREE environment variable can be used to set the tree the jpm installs things to. By default, running janet from the command line separately will not use modules in the custom tree, so you will likely want to modify JANET_PATH as well.

export JANET_TREE=$HOME/.local/jpm_tree
jpm deps
jpm build
jpm test
jpm install
# alternative: jpm --tree=$HOME/.local/jpm_tree deps

Project local install

JPM also has some flags to install dependencies to a tree local to a project. Dependencies will be installed to ./jpm_tree/lib (and binaries installed to ./jpm_tree/bin) when passing the -l flag to jpm.

jpm -l deps
jpm -l build
jpm -l test
# Run a janet interpreter in the local environment with access to all dependencies installed.
jpm -l janet

Dependencies

jpm deps is a command that installs Janet libraries that the project depends on recursively. It will automatically fetch, build, and install all required dependencies for you. As of August 2019, this only works with git, which you need to have installed on your machine to install dependencies. If you don't have git you are free to manually obtain the requisite dependencies and install them manually with sudo jpm install.

Building

Next, we use the jpm build command to build artifacts. All built artifacts will be created in the build subdirectory of the current project. Therefore, it is probably a good idea to exclude the build directory from source control. For building executables and native modules, you will need to have a C compiler on your PATH where you run jpm build. For POSIX systems, the compiler is cc.

If you make changes to the source code after building once, jpm will try to only rebuild what is needed on a rebuild. If this fails for any reason, you can delete the entire build directory with jpm clean to reset things.

Windows

For Windows, the C compiler used by jpm is cl.exe, which is part of MSVC. You can get it with Visual Studio, or standalone with the C and C++ Build Tools from Microsoft. You will then need to run jpm build in a Developer Command Prompt, or source vcvars64.bat in your shell to add cl.exe to the PATH.

Testing

Once we have built our software, it is a good idea to test it to verify that it works on the current machine. jpm test will run all Janet scripts in the test directory of the project and return a non-zero exit code if any fail.

Installing

Finally, once we have built our software and tested that it works, we can install it on our system. For an executable, this means copying it to the bin directory, and for libraries it means copying them to the global syspath. You can optionally install into any directory if you don't want to pollute your system or you don't have permission to write to the directory where janet itself was installed. You can specify the path to install modules to via the --modpath option, and the path to install binaries to with the --binpath option. These need to be given before the subcommand install.