|
| 1 | +--- |
| 2 | +slug: packages |
| 3 | +title: Guide to Creating and Publishing a Package |
| 4 | +authors: [vinzbarbuto] |
| 5 | +tags: [packages, packaging, lingua franca, docs] |
| 6 | +--- |
| 7 | + |
| 8 | +The Lingua Franca (LF) [Package Explorer](/docs/tools/code-extension#package-explorer) is a powerful feature within the Lingua Franca VS Code extension, built to streamline package management for developers. Supporting both local and remote sources, the Package Explorer enables effortless listing and management of packages—whether defined locally by developers or installed through the Lingo Package Manager. This integration aligns with the Lingua Franca community’s vision for a collaborative and reusable ecosystem. Developers can create and publish their own packages, enabling others to easily incorporate these resources into their projects. This collaborative model not only enhances programmability and accelerates product development but also simplifies the design of complex Lingua Franca applications. |
| 9 | + |
| 10 | +{/* truncate */} |
| 11 | + |
| 12 | +In this guide, we’ll walk you through the essential steps to create and publish a package to the community repository, covering: |
| 13 | + |
| 14 | +1. [**Creating a New Package**](#creating-a-package) |
| 15 | + Get started by setting up your package with the required files and directory structure to meet Lingua Franca standards. |
| 16 | + |
| 17 | +2. [**Configuring the `Lingo.toml` File**](#configuring-the-lingotoml-file) |
| 18 | + Set up the `Lingo.toml` configuration to ensure compatibility with the Lingo Package Manager, making your package easy to download and install. |
| 19 | + |
| 20 | +3. [**Publishing to the Community Repository**](#publishing-to-the-community-repository) |
| 21 | + Learn how to publish your package to the [Lingua Franca Community Package Repository](https://github.com/lf-pkgs) to share it with the broader community. |
| 22 | + |
| 23 | +By the end of this guide, you'll have a fully configured, shareable package ready to distribute within the Lingua Franca ecosystem. |
| 24 | + |
| 25 | +## Creating a New Package |
| 26 | +You can create a new [LF package](/docs/glossary/glossaryx#package) either manually by creating an [LF file](/docs/glossary/glossaryx#lf-file) or by using the [Lingo Package Manager](https://github.com/lf-lang/lingo). |
| 27 | + |
| 28 | +#### Option 1: Create a Project Using the Lingo Package Manager |
| 29 | +1. After [installing the Lingo Package Manager](https://www.lf-lang.org/docs/installation#lingo), create an empty directory to serve as the root of your new package. |
| 30 | +2. Open the folder in VS Code. |
| 31 | +3. Open the terminal in this folder and run the <kbd>lingo init</kbd> command. |
| 32 | + |
| 33 | +This will set up a new LF package with the following structure: |
| 34 | + |
| 35 | +``` |
| 36 | +├── . |
| 37 | +│ ├── src/ |
| 38 | +│ │ └── Main.lf |
| 39 | +└── └── Lingo.toml # Configuration file for current package |
| 40 | +``` |
| 41 | + |
| 42 | +#### Option 2: Create a New [LF File](/docs/glossary/glossaryx#lf-file) |
| 43 | +1. Go to <kbd>File > New File...</kbd> and select `New Lingua Franca File`. |
| 44 | +2. Save the file in a directory called `src` to ensure that generated code is placed in a parallel `src-gen` directory. For example, if your file is called `Foo.lf`, the directory structure after building will look like this: |
| 45 | + |
| 46 | +``` |
| 47 | +├── . |
| 48 | +│ ├── bin/ |
| 49 | +│ │ └── Foo |
| 50 | +│ ├── src/ |
| 51 | +│ │ └── Foo.lf |
| 52 | +│ ├── src-gen/ |
| 53 | +│ │ └── Foo/ |
| 54 | +... |
| 55 | +``` |
| 56 | + |
| 57 | +If you manually create the `Lingo.toml` file, place it adjacent to the `src` folder in the root directory of the package. This file serves as a configuration for the package, allowing you to specify the package name, version, and other metadata, including any dependencies you want to install. |
| 58 | + |
| 59 | +### Add `src/lib/` for Local Libraries |
| 60 | + |
| 61 | +To include local libraries, create a `lib` directory within the `src/` folder and place your LF files there. These files contain reusable reactors that can be used within the same package or, if published, in other packages via the Lingo Package Manager. This setup makes it easy to manage and reuse libraries across Lingua Franca projects. The `lib` directory should be placed alongside the `src` directory, organized as follows: |
| 62 | + |
| 63 | +``` |
| 64 | +├── . |
| 65 | +│ ├── src/ |
| 66 | +│ │ ├── lib/ |
| 67 | +│ │ │ ├── private/ |
| 68 | +│ │ │ │ └── AbstractLibraryFile.lf |
| 69 | +│ │ │ ├── LibraryFile_1.lf |
| 70 | +│ │ │ └── LibraryFile_2.lf |
| 71 | +│ │ └── Foo.lf |
| 72 | +... |
| 73 | +``` |
| 74 | + |
| 75 | +In LF, there is no visibility control, meaning you cannot mark a reactor or file as `private` as in other programming languages. The `private` directory serves this purpose by containing files meant solely for internal package use. Files in this directory are hidden in the Package Explorer within the VS Code extension, making them inaccessible to other packages. The `private` directory is useful for implementing design patterns like the Abstract Factory Pattern, which provides an interface for creating families of related objects without specifying concrete classes. For example, a developer might define an `AbstractLibraryFile.lf` containing abstract reactors and implement them in various ways within different files under the `lib` directory. |
| 76 | + |
| 77 | +### Must-Follow Guidelines |
| 78 | + |
| 79 | +When creating a new package, ensure that you follow these guidelines: |
| 80 | + |
| 81 | +- **README.md**: Include a `README.md` file in the root directory. This should provide an overview of the package, its purpose, a description of the LF files in the `lib/` folder, and relevant user information. The `README.md` is essential for publishing your package to the community repository and must be kept up to date. |
| 82 | + |
| 83 | +- **File Naming**: Use descriptive names for files in the `lib/` directory that reflect their purpose. For example, name a file containing a reactor for different sensors as `Sensor.lf`. |
| 84 | + |
| 85 | +- **Example LF Files**: Include example LF files in the `src/` directory to demonstrate how to use the reactors in the `lib/` directory. These examples should be well-documented with comments explaining the purpose and usage of each reactor. |
| 86 | + |
| 87 | +## Configuring the `Lingo.toml` File |
| 88 | + |
| 89 | +The `Lingo.toml` file is a configuration file that provides essential information about your package, such as its name, version, and dependencies. It ensures that your package is recognized and installed correctly by the Lingo Package Manager. The `Lingo.toml` file should include the following sections: |
| 90 | + |
| 91 | +- **`[package]`**: Specify the package name, description, and version. |
| 92 | + |
| 93 | +- **`[lib]`**: Define the package name, the target language used to implement the code, the main reactor (which could be one of the examples from the `src/` directory), and the platform used to build the package. |
| 94 | + |
| 95 | +Here's an example of a `Lingo.toml` file: |
| 96 | + |
| 97 | +```toml |
| 98 | +[package] |
| 99 | +name = "PackageName" |
| 100 | +version = "0.3.1" |
| 101 | + |
| 102 | +[properties] |
| 103 | + |
| 104 | +[lib] |
| 105 | +name = "PackageName" |
| 106 | +main = "./src/Main.lf" |
| 107 | +target = "Python" |
| 108 | +platform = "Native" |
| 109 | + |
| 110 | +[lib.properties] |
| 111 | + |
| 112 | +[dependencies] |
| 113 | +``` |
| 114 | + |
| 115 | +The `Lingo.toml` can also include additional sections for dependencies and other purpose-specific configurations, however, these are optional and can be added as needed. |
| 116 | + |
| 117 | +## Publishing to the Community Repository |
| 118 | + |
| 119 | +TBD |
0 commit comments