From 36caff38124673df3001aef0c720256ad97e3f05 Mon Sep 17 00:00:00 2001 From: Khushboo Mehta Date: Wed, 1 Apr 2026 12:21:06 +0200 Subject: [PATCH] some fixes after testing the tutorial --- logos-calc-module/flake.lock | 1 + .../CMakeLists.txt | 0 .../flake.lock | 0 .../flake.nix | 0 .../icons/calc.png | Bin .../interfaces/IComponent.h | 0 .../metadata.json | 0 .../src/calc_backend.cpp | 0 .../src/calc_backend.h | 0 .../src/calc_ui_cpp_interface.h | 0 .../src/calc_ui_cpp_plugin.cpp | 0 .../src/calc_ui_cpp_plugin.h | 0 .../src/qml/Main.qml | 0 tutorial-cpp-ui-app.md | 14 +++++++----- tutorial-qml-ui-app.md | 20 ++++++++++++++--- tutorial-wrapping-c-library.md | 21 +++++++++++------- 16 files changed, 40 insertions(+), 16 deletions(-) rename {logos-calc-cpp-ui => logos-calc-ui-cpp}/CMakeLists.txt (100%) rename {logos-calc-cpp-ui => logos-calc-ui-cpp}/flake.lock (100%) rename {logos-calc-cpp-ui => logos-calc-ui-cpp}/flake.nix (100%) rename {logos-calc-cpp-ui => logos-calc-ui-cpp}/icons/calc.png (100%) rename {logos-calc-cpp-ui => logos-calc-ui-cpp}/interfaces/IComponent.h (100%) rename {logos-calc-cpp-ui => logos-calc-ui-cpp}/metadata.json (100%) rename {logos-calc-cpp-ui => logos-calc-ui-cpp}/src/calc_backend.cpp (100%) rename {logos-calc-cpp-ui => logos-calc-ui-cpp}/src/calc_backend.h (100%) rename {logos-calc-cpp-ui => logos-calc-ui-cpp}/src/calc_ui_cpp_interface.h (100%) rename {logos-calc-cpp-ui => logos-calc-ui-cpp}/src/calc_ui_cpp_plugin.cpp (100%) rename {logos-calc-cpp-ui => logos-calc-ui-cpp}/src/calc_ui_cpp_plugin.h (100%) rename {logos-calc-cpp-ui => logos-calc-ui-cpp}/src/qml/Main.qml (100%) diff --git a/logos-calc-module/flake.lock b/logos-calc-module/flake.lock index 683e4c1..6ab210e 100644 --- a/logos-calc-module/flake.lock +++ b/logos-calc-module/flake.lock @@ -289,6 +289,7 @@ "original": { "owner": "logos-co", "repo": "logos-module-builder", + "rev": "b6cf87d30e2995e023496fcfc7f06e8127c6ac5b", "type": "github" } }, diff --git a/logos-calc-cpp-ui/CMakeLists.txt b/logos-calc-ui-cpp/CMakeLists.txt similarity index 100% rename from logos-calc-cpp-ui/CMakeLists.txt rename to logos-calc-ui-cpp/CMakeLists.txt diff --git a/logos-calc-cpp-ui/flake.lock b/logos-calc-ui-cpp/flake.lock similarity index 100% rename from logos-calc-cpp-ui/flake.lock rename to logos-calc-ui-cpp/flake.lock diff --git a/logos-calc-cpp-ui/flake.nix b/logos-calc-ui-cpp/flake.nix similarity index 100% rename from logos-calc-cpp-ui/flake.nix rename to logos-calc-ui-cpp/flake.nix diff --git a/logos-calc-cpp-ui/icons/calc.png b/logos-calc-ui-cpp/icons/calc.png similarity index 100% rename from logos-calc-cpp-ui/icons/calc.png rename to logos-calc-ui-cpp/icons/calc.png diff --git a/logos-calc-cpp-ui/interfaces/IComponent.h b/logos-calc-ui-cpp/interfaces/IComponent.h similarity index 100% rename from logos-calc-cpp-ui/interfaces/IComponent.h rename to logos-calc-ui-cpp/interfaces/IComponent.h diff --git a/logos-calc-cpp-ui/metadata.json b/logos-calc-ui-cpp/metadata.json similarity index 100% rename from logos-calc-cpp-ui/metadata.json rename to logos-calc-ui-cpp/metadata.json diff --git a/logos-calc-cpp-ui/src/calc_backend.cpp b/logos-calc-ui-cpp/src/calc_backend.cpp similarity index 100% rename from logos-calc-cpp-ui/src/calc_backend.cpp rename to logos-calc-ui-cpp/src/calc_backend.cpp diff --git a/logos-calc-cpp-ui/src/calc_backend.h b/logos-calc-ui-cpp/src/calc_backend.h similarity index 100% rename from logos-calc-cpp-ui/src/calc_backend.h rename to logos-calc-ui-cpp/src/calc_backend.h diff --git a/logos-calc-cpp-ui/src/calc_ui_cpp_interface.h b/logos-calc-ui-cpp/src/calc_ui_cpp_interface.h similarity index 100% rename from logos-calc-cpp-ui/src/calc_ui_cpp_interface.h rename to logos-calc-ui-cpp/src/calc_ui_cpp_interface.h diff --git a/logos-calc-cpp-ui/src/calc_ui_cpp_plugin.cpp b/logos-calc-ui-cpp/src/calc_ui_cpp_plugin.cpp similarity index 100% rename from logos-calc-cpp-ui/src/calc_ui_cpp_plugin.cpp rename to logos-calc-ui-cpp/src/calc_ui_cpp_plugin.cpp diff --git a/logos-calc-cpp-ui/src/calc_ui_cpp_plugin.h b/logos-calc-ui-cpp/src/calc_ui_cpp_plugin.h similarity index 100% rename from logos-calc-cpp-ui/src/calc_ui_cpp_plugin.h rename to logos-calc-ui-cpp/src/calc_ui_cpp_plugin.h diff --git a/logos-calc-cpp-ui/src/qml/Main.qml b/logos-calc-ui-cpp/src/qml/Main.qml similarity index 100% rename from logos-calc-cpp-ui/src/qml/Main.qml rename to logos-calc-ui-cpp/src/qml/Main.qml diff --git a/tutorial-cpp-ui-app.md b/tutorial-cpp-ui-app.md index e48c03e..a9f95cb 100644 --- a/tutorial-cpp-ui-app.md +++ b/tutorial-cpp-ui-app.md @@ -110,9 +110,8 @@ Create the icon directory and add a placeholder icon. The icon is displayed in t ```bash mkdir -p icons -# Copy any PNG here — or use a placeholder: -convert -size 64x64 xc:'#4a90d9' icons/calc.png 2>/dev/null \ - || printf '\x89PNG\r\n\x1a\n' > icons/calc.png +# Copy any PNG here — or generate a 64×64 placeholder: +echo "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAAeklEQVR4nO3PUQkAIBTAwFfPdtazjSH8OITBAtxm7fN1wwUNaEEDWtCAFjSgBQ1oQQNa0IAWNKAFDWhBA1rQgBY0oAUNaEEDWtCAFjSgBQ1oQQNa0IAWNKAFDWhBA1rQgBY0oAUNaEEDWtCAFjSgBQ1oQQNa0IAWPHYBic8hlloAWpEAAAAASUVORK5CYII=" | base64 -d > icons/calc.png ``` > **Naming convention:** Each entry in `dependencies` must match the `name` field in that module's own `metadata.json`. When adding a dependency as a flake input, the **input attribute name** must also match — e.g., `calc_module.url = "github:logos-co/logos-tutorial/tutorial-v1?dir=logos-calc-module"`. The URL can point to any repo, but the attribute name is how the builder resolves dependencies. @@ -623,8 +622,13 @@ nix build --override-input calc_module path:../logos-calc-module Inspect the output with `lm` (the module inspector from `logos-module`): ```bash -nix build 'github:logos-co/logos-module/337223f2a72710d8052ca750510cd25d33e05047#cli' --out-link ./lm-cli -./lm-cli/bin/lm ./result/lib/calc_ui_cpp_plugin.dylib +nix build 'github:logos-co/logos-module/337223f2a72710d8052ca750510cd25d33e05047#lm' --out-link ./lm-cli + +# Linux +./lm-cli/bin/lm ./result/lib/calc_ui_cpp_plugin.so + +# macOS +# ./lm-cli/bin/lm ./result/lib/calc_ui_cpp_plugin.dylib ``` You should see `createWidget` and `destroyWidget` in the methods list. diff --git a/tutorial-qml-ui-app.md b/tutorial-qml-ui-app.md index 24078ec..58579bb 100644 --- a/tutorial-qml-ui-app.md +++ b/tutorial-qml-ui-app.md @@ -65,7 +65,7 @@ logos-calc-ui/ ## Step 2: Update `metadata.json` -Replace the template contents with your plugin's details: +Replace the template contents with your plugin's details. The template may generate an extra `nix` section — keep it as-is, it's used by the builder: ```json { @@ -76,7 +76,21 @@ Replace the template contents with your plugin's details: "main": "Main.qml", "dependencies": ["calc_module"], "category": "tools", - "icon": "icons/calc.png" + "icon": "icons/calc.png", + + "nix": { + "packages": { + "build": [], + "runtime": [] + }, + "external_libraries": [], + "cmake": { + "find_packages": [], + "extra_sources": [], + "extra_include_dirs": [], + "extra_link_libraries": [] + } + } } ``` @@ -406,7 +420,7 @@ The "Calculator UI" tab appears in the sidebar. Clicking it loads your `Main.qml For rapid iteration on QML without rebuilding, set `QML_PATH` to your QML source directory: ```bash -QML_PATH=$PWD/src/qml nix run . +QML_PATH=$PWD nix run . ``` Edit `Main.qml`, close and re-run — changes appear immediately without `nix build`. When `QML_PATH` is set, the plugin loads QML files from the filesystem instead of from Qt resources, so your edits are picked up on each launch. diff --git a/tutorial-wrapping-c-library.md b/tutorial-wrapping-c-library.md index ffc5fea..e11980e 100644 --- a/tutorial-wrapping-c-library.md +++ b/tutorial-wrapping-c-library.md @@ -15,8 +15,13 @@ This tutorial walks you through wrapping a C shared library (`.so` on Linux, `.d - **Nix** with flakes enabled. Install from [nixos.org](https://nixos.org/download.html), then enable flakes globally: ```bash - # Add to ~/.config/nix/nix.conf: - experimental-features = nix-command flakes + # Add to ~/.config/nix/nix.conf (create the file if it doesn't exist): + mkdir -p ~/.config/nix + echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf + ``` + Verify it works: + ```bash + nix flake --help >/dev/null 2>&1 && echo "Flakes enabled" || echo "Flakes NOT enabled — check nix.conf" ``` - **A C compiler** (gcc or clang) for building the C library. Only needed if you're building the `.so`/`.dylib` yourself rather than using a pre-built library. - Basic familiarity with C and C++. @@ -156,14 +161,14 @@ nm -D lib/libcalc.so | grep calc # nm -gU lib/libcalc.dylib | grep calc ``` -You should see: +You should see each symbol marked with `T` (text/code section). Addresses will vary: ``` -T calc_add -T calc_factorial -T calc_fibonacci -T calc_multiply -T calc_version +0000000000001139 T calc_add +0000000000001179 T calc_factorial +00000000000011f5 T calc_fibonacci +0000000000001159 T calc_multiply +0000000000001299 T calc_version ``` > **Wrapping a third-party library?** If you're wrapping an existing library (e.g., from a system package or a GitHub repo), you don't need to write the C code — just place the pre-built `.so`/`.dylib` and its header file in `lib/`.