Skip to content

(#238) Wrap a C library as a Logos core module#239

Open
cheny0 wants to merge 9 commits into
mainfrom
238-wrap-a-c-library-as-a-logos-core-module
Open

(#238) Wrap a C library as a Logos core module#239
cheny0 wants to merge 9 commits into
mainfrom
238-wrap-a-c-library-as-a-logos-core-module

Conversation

@cheny0

@cheny0 cheny0 commented May 7, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@cheny0 cheny0 self-assigned this May 7, 2026
@cheny0 cheny0 added area:core Docs related to Logos Core journeys. quality:stub Placeholder page. Title, status, and known gaps only. Not runnable. type:journey A user journey document (the primary deliverable). release:testnet-v0.2 Items for Testnet v0.1 release. status:doc-ready-for-review blocked-by:red-team labels May 7, 2026
@cheny0 cheny0 linked an issue May 7, 2026 that may be closed by this pull request
@fryorcraken fryorcraken requested review from jzaki and removed request for fryorcraken May 8, 2026 02:54

> [!TIP]
>
> If you don't have a C library, you can try the `libtictactoe.h` and `libtictactoe.c` from example [`libtictactoe`](https://github.com/fryorcraken/logos-module-tictactoe/tree/master/tictactoe/lib). Copy them into your `lib/` directory.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a trivial inlined .c and .h code would be less distracting from the goal.
This tip takes them to another repo to copy a specific .c/.h file code back, and it is it's own module repo too.
EDIT: later does do the inline calc example, seems more confusing to direct them away at this point. Perhaps move to later once they've done a bit more.

>
> Check out an [example](https://github.com/fryorcraken/logos-module-tictactoe/tree/master/tictactoe) of a working core module that wraps a small C library.

## Step 1: Scaffold the module project with external-lib support

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should clarify use of "Scaffold" as a verb here, since it's the same name as the tool

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That one's for LEZ, no connection to here. I'll add clarifying sentences here to make this more obvious.


## Step 1: Scaffold the module project with external-lib support

Use the `with-external-lib` variant of the module builder template. Compared to the plain template, its `metadata.json` is pre-populated with an `external_libraries` block and `extra_include_dirs`, and its `CMakeLists.txt` calls `logos_module()` with `EXTERNAL_LIBS`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explaining a specific attribute of a command before presenting the command or even mentioning module builder (perhaps they are assumed to know it if they're here).

Q_DECLARE_INTERFACE(<ModuleName>Interface, "org.logos.<ModuleName>Interface")
```

- Supported parameter and return types: `int`, `bool`, `QString`, `QByteArray`, `QVariant`, `QJsonArray`, `QStringList`, `LogosResult`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It quite mechanical around here, acting as both a how-to and a reference in one. If it's more of a tutorial type, can the person following the tutorial be primed to come across these elsewhere? Eg if these types are defined somewhere intuitive in this context. Or later, showing where the global logosAPI is defined.

```

- Use `nix build '.#lib'` to build only the plugin shared library.
- Use `nix build '.#include'` to build only the generated SDK headers.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read this in the original tutorial, and it'd be helpful to expand what this means.

nix build .#lgx
```

- Use `#lgx-portable` for a self-contained package with all dependencies bundled: `nix build .#lgx-portable`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be helpful to explain what "all dependencies" means in this context: wrapped lib, module deps, something more, ..?


1. Check the `result/` directory and confirm the `<module-name>-<version>.lgx` file is present.

#### Use the `nix bundle` command

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I'd read somewhere this path wasn't preferred, will see what khushboo responds to above.


```bash
mkdir <module-name> && cd <module-name>
nix flake init -t github:logos-co/logos-module-builder/tutorial-v1#with-external-lib

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will eventually update to v3 soon 🤞 To go with the basecamp release 0.1.2


#### Install a locally built `.lgx` package

1. Build the Logos Package Manager (`lgpm`) CLI.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of consecutive instructions (like a how-to), it could benefit with some context here.

./logos-basecamp/bin/logos-basecamp
```

- To find the data directory, check the log for `plugins directory`, or look for the directory containing `modules/` and `plugins/` at `~/Library/Application Support/Logos/` (macOS) or `~/.local/share/Logos/` (Linux).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each other time shows Linux first, only time macOS shown first

@kashepavadan

Copy link
Copy Markdown
Contributor

@iurimatias @dlipicar Has this process been updated compared to the original doc packet? I'm just noticing here: https://github.com/logos-co/logos-tutorial/blob/master/outputs/tutorial-wrapping-c-library.md that you don't have to replace Q_INVOKABLE functions in the updated tutorial. Are the changes major enough to warrant a full rewrite? What about the other module tutorials (the core module and QML + C++ ones have already been merged in)?

@iurimatias

Copy link
Copy Markdown
Member

@kashepavadan this is the correct version btw (tutorial-v3) https://github.com/logos-co/logos-tutorial/blob/releases/v3/outputs/tutorial-wrapping-c-library.md

that you don't have to replace Q_INVOKABLE not sure if the don't here was a typo, but yes you do need to replace the Q_INVOKABLE functions as the way to build modules changed completely and the QT way for modules is deprecated and will be removed.

@iurimatias

Copy link
Copy Markdown
Member

the apps writing has also changed and needs to be relooked at

@kashepavadan

Copy link
Copy Markdown
Contributor

@iurimatias I was referring to this step in the tutorial:

"In the interface header, replace the class name, interface ID, include guard, and placeholder Q_INVOKABLE virtual methods with one pure-virtual method per C function you want to expose."

Ok, understood. Can I just use the v3 release tutorials as doc packets to create the updated docs, or will more major changes be coming soon? If so, I'd rather wait until you reach a stable version.

@kashepavadan kashepavadan requested a review from a team June 10, 2026 19:42
@kashepavadan

Copy link
Copy Markdown
Contributor

@jzaki Completely updated the tutorial, please take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core Docs related to Logos Core journeys. blocked-by:red-team quality:stub Placeholder page. Title, status, and known gaps only. Not runnable. release:testnet-v0.2 Items for Testnet v0.1 release. status:doc-ready-for-review type:journey A user journey document (the primary deliverable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrap a C library as a Logos core module

4 participants