Using Kanzi Rust API in Kanzi application

Create a Kanzi Rust application using a template

You can create a Kanzi Rust application using the template provided by the Kanzi Rust API package.

To create a Kanzi Rust application:

  1. In the Kanzi Studio New Project window choose the Application with Rust API template.

  2. Click Create.

Kanzi creates both Kanzi Studio and Kanzi application projects, placing the Rust module in the Application/src/MyProject_rust directory. The application includes a ready-made CMake utility that allows you to build the Rust module as part of the application build step.

Build a Kanzi Rust application

Before building your Kanzi application with the Rust module, make sure that the KANZI_HOME environment variable is set to the <KanziWorkspace> directory.

If you use a custom installation directory for the Kanzi Rust API package, set its location in the KANZI_RUST_HOME environment variable.

To build a Kanzi Rust application, you can either:

  • Use the Visual Studio Code build task provided by the template:

    1. Open the <MyProject>/Application directory in Visual Studio Code.

    2. Press Ctrl+Shift+B to run the build task.

  • Build the application from the command line with these steps:

    1. Navigate to the <MyProject>/Application directory.

    2. Configure the project and generate build files:

      cmake -B build_vs2019 -G "Visual Studio 16 2019" -A "x64"
      
    3. Build the application:

      cmake --build build_vs2019 --config "Release" --verbose
      

      This CMake command invokes the cargo command with the required settings to build the Rust module.

Debug a Kanzi Rust application

The recommended way to debug Kanzi Rust modules is to use Visual Studio Code. The project created from the template has launch tasks allowing you to debug both Rust and C++ code. To enable full debugging support, make sure you have installed the Rust and C++ extensions in Visual Studio Code.

To start debugging, open the project in Visual Studio Code and press F5.