This article has examples in the following target languages:
- C
- C++
- Python
- Rust
- TypeScript
Every Lingua Franca program begins with a statement of this form:
The <name>
gives the name of some Lingua Franca target language, which is the language in which reactions are written. This is also the language of the program(s) generated by the Lingua Franca compiler. The target languages currently supported are C, C++, Python, TypeScript, and Rust. There is also a target CCpp that is just like the C target except that it uses a C++ compiler to compile the code, thereby allowing inclusion of C++ code.
Summary of Parameters
A target specification may have optional parameters, the names and values of which depend on which specific target you are using. Each parameter is a key-value pair, where the supported keys are a subset of the following:
- auth: A boolean specifying to apply authorization between RTI and federates when federated execution.
- build: A command to execute after code generation instead of the default compile command.
- build-type: One of Debug (the default), Release, RelWithDebInfo and MinSizeRel.
- cargo-dependencies: (Rust only) list of dependencies to include in the generated Cargo.toml file.
- cargo-features: (Rust only) List of string names of features to include.
- cmake-include: List of paths to cmake files to guide compilation.
- compiler: A string giving the name of the target language compiler to use.
- compiler-flags: An arrays of strings giving options to be passed to the target compiler.
- docker: A boolean to generate a Dockerfile.
- external-runtime-path: Specify a pre-compiled external runtime library located to link to instead of the default.
- export-dependency-graph: To export the reaction dependency graph as a dot graph (for debugging).
- fast: A boolean specifying to execute as fast as possible without waiting for physical time to match logical time.
- files: An array of paths to files or directories to be copied to the directory that contains the generated sources.
- logging: An indicator of how much information to print when executing the program.
- no-compile: If true, then do not invoke a target language compiler. Just generate code.
- no-runtime-validation: If true, disable runtime validation.
- protobufs: An array of .proto files that are to be compiled and included in the generated code.
- runtime-version: Specify which version of the runtime system to use.
- rust-include: (Rust only) A set of Rust modules in the generated project.
- scheduler: (C only) Specification of the scheduler to us.
- single-file-project: (Rust only) If true, enables single-file project layout.
- single-threaded: Specify to not use multithreading.
- timeout: A time value (with units) specifying the logical stop time of execution. See Termination.
- workers: If using multiple threads, how many worker threads to create.
Not all targets support all target parameters. The full set of target parameters supported by the target is:
For example:
This specifies to use compiler cc
instead of the default gcc
, to use optimization level 3, to execute as fast as possible, and to exit execution when logical time has advanced to 10 seconds. Note that all events at logical time 10 seconds greater than the starting logical time will be executed.
The comma on the last parameter is optional, as is the semicolon on the last line. A target may support overriding the target parameters on the command line when invoking the compiled program.
auth​
The detailed documentation is here.
This target does not currently support the auth
target option.
This target does not currently support the auth
target option.
This target does not currently support the auth
target option.
This target does not currently support the auth
target option.
build​
A command to execute after code generation instead of the default compile command. This is either a single string or an array of strings. The specified command(s) will be executed an environment that has the following environment variables defined:
LF_CURRENT_WORKING_DIRECTORY
: The directory in which the command is invoked.LF_SOURCE_DIRECTORY
: The directory containing the .lf file being compiled.LF_PACKAGE_DIRECTORY
: The directory for the root of the project or package (normally the directory above thesrc
directory).LF_SOURCE_GEN_DIRECTORY
: The directory in which generated files are placed.LF_BIN_DIRECTORY
: The directory into which to put binaries.
The command will be executed in the same directory as the .lf
file being compiled. For example, if you specify
then instead of invoking the C compiler after generating code, the code generator will invoke your compile.sh
script, which could look something like this:
#!/bin/bash
# Build the generated code.
cd ${LF_SOURCE_GEN_DIRECTORY}
cmake .
make
# Move the executable to the bin directory.
mv $1 ${LF_BIN_DIRECTORY}
# Invoke the executable.
${LF_BIN_DIRECTORY}/$1
# Plot the results, which have appeared in the src-gen directory.
gnuplot ${LF_SOURCE_DIRECTORY}/$1.gnuplot
open $1.pdf
The first few lines of this script do the same thing that is normally done when there is no build
option in the target. Specifically, they use cmake
to create a makefile, invoke make
, and then move the executable to the bin
directory. The next line, however, gives new functionality. It executes the compiled code! The final two lines assume that the program has produced a file with data to be plotted and use gnuplot
to plot the data. This requires, of course, that you have gnuplot
installed, and that there is a file called Foo.gnuplot
in the same directory as Foo.lf
. The file Foo.gnuplot
contains the commands to plot the data, and might look something like the following:
set title 'My Title'
set xrange [0:3]
set yrange [-2:2]
set xlabel "Time (seconds)"
set terminal pdf size 5, 3.5
set output 'Foo.pdf'
plot 'mydata1.data' using 1:2 with lines, \
'mydata2.data' using 1:2 with lines
This assumes that your program has written two files, mydata1.data
and mydata2.data
containing two columns, time and value.
This target does not currently support the build
target option.
This target does not currently support the build
target option.
This target does not currently support the build
target option.
This target does not currently support the build
target option.
build-type​
This target does not currently support the build-type
target option.
This target does not currently support the build-type
target option.
This parameter specifies how to compile the code. The following options are supported:
Debug
: Optimization is disabled and debug information is included in the executable.Release
: Optimization is enabled and debug information is missing.RelWithDebInfo
: Optimization with debug information.MinSizeRel
: Optimize for smallest size.
This defaults to Debug
.
This parameter specifies how to compile the code. The following options are supported:
Debug
: Optimization is disabled and debug information is included in the executable.Release
: Optimization is enabled and debug information is missing.RelWithDebInfo
: Optimization with debug information.MinSizeRel
: Optimize for smallest size.
This defaults to Debug
.
This parameter specifies how to compile the code. The following options are supported:
Debug
: Optimization is disabled and debug information is included in the executable.Release
: Optimization is enabled and debug information is missing.RelWithDebInfo
: Optimization with debug information.MinSizeRel
: Optimize for smallest size.
This defaults to Debug
.
cargo-dependencies​
This target does not support the cargo-dependencies
target option.
This target does not support the cargo-dependencies
target option.
This target does not support the cargo-dependencies
target option.
This target does not support the cargo-dependencies
target option.
This is a list of dependencies to include in the generated Cargo.toml file. The value of this parameter is a map of package name to dependency-spec.
Here is an example for defining dependencies: