|
| 1 | +--- |
| 2 | +title: On-target Development |
| 3 | +description: Using VS Code for "on-target" development. |
| 4 | +--- |
| 5 | + |
| 6 | +# Develop Lingua Franca on Remote Targets |
| 7 | +Microsoft Visual Studio Code can be used to connect to a remote target or a virtual machine, which provides a convenient way of developing Lingua Franca applications "on target". The steps here are an alternative to cross-compilation or installing local toolchains, as the tools run natively on a remote target or virtual machine. |
| 8 | + |
| 9 | +A video that demonstrates on-target development is available here: |
| 10 | + |
| 11 | +<p align="center"> |
| 12 | +<iframe width="560" height="315" src="https://www.youtube.com/embed/yg_sudCyzV4?si=b--gaS0q9e9gbMv-" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; display:block;clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> |
| 13 | +</p> |
| 14 | + |
| 15 | +## Configure your Target |
| 16 | + |
| 17 | +You may [manually install Lingua Franca](./../installation), or, if you want to use a provisioning tool, see [xronos-inc/xronos_lfc_ansible](https://github.com/xronos-inc/xronos_lfc_ansible) for an Ansible script to install Lingua Franca tools on a remote target. |
| 18 | + |
| 19 | +If you would like to configure a virtual machine, see [xronos-inc/lfc-multipass](https://github.com/xronos-inc/lfc-multipass) for a cloud-init script to install Lingua Franca tools using multipass. |
| 20 | + |
| 21 | +Once you have your remote target, be it a virtual machine or a machine accessible over a network, you can connect to it using Visual Studio Code and the Remote SSH extension. |
| 22 | + |
| 23 | +## Install the Microsoft Remote-SSH extension |
| 24 | + |
| 25 | +Open VS Code, launch Quick Open (Ctrl + P) and enter: |
| 26 | + |
| 27 | +`ext install ms-vscode-remote.remote-ssh` |
| 28 | + |
| 29 | +After installation is complete you'll see the Remote SSH status bar icon: |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +## Connect VS Code to your remote system via SSH |
| 34 | + |
| 35 | +In VS Code, click on the "Remote SSH" status bar icon and select "Connect to Host..." then "Add New SSH Host". When prompted for the host, enter |
| 36 | + |
| 37 | +`ssh ubuntu@[remotehost]` |
| 38 | + |
| 39 | +where `remotehost` is the hostname or IP address of your remote target. |
| 40 | + |
| 41 | +A new VS Code window will open, and the address of your remote target should appear in the Remote SSH status bar: |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +## Install the Lingua Franca VS Code extension |
| 46 | + |
| 47 | +open VS Code, launch Quick Open (Ctrl + P) and enter: |
| 48 | + |
| 49 | +`ext install lf-lang.vscode-lingua-franca` |
| 50 | + |
| 51 | +## Run the Hello World Application |
| 52 | + |
| 53 | +In VS Code, create the folder `helloworld` on your remote target, then create a file within that folder called `helloworld.lf` with the following contents: |
| 54 | + |
| 55 | +```lf-cpp |
| 56 | +target Cpp |
| 57 | +
|
| 58 | +main reactor { |
| 59 | + reaction(startup) {= |
| 60 | + std::cout << "Hello World." << std::endl; |
| 61 | + =} |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +Similar hello world programs can be created for any of the supported target languages. |
| 66 | + |
| 67 | +Open `helloworld.lf`. You should see the visual rendering of the application on the right pane of Visual Studio. On remote targets with slow internet connections, or slower processors, this may take a few seconds for the first rendering. |
| 68 | + |
| 69 | +Build by pressing Ctrl + Shift + P followed by `Lingua Franca: Build and Run`. The program will be compiled and executed on your remote target with build output and terminal output visible within VS Code. |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | +## References |
| 74 | + |
| 75 | +- [How to set up Lingua Franca](./../installation) |
| 76 | +- [How to create a VSCode Linux remote environment](https://ubuntu.com/blog/how-to-create-a-vscode-linux-remote-environment) |
| 77 | +- [Remote development over SSH](https://code.visualstudio.com/docs/remote/ssh-tutorial) |
0 commit comments