Skip to content

Commit d9a7413

Browse files
authored
add icon field to manifest (#14)
* add icon field to manifest * run tests only during the build
1 parent 9fefc4d commit d9a7413

File tree

12 files changed

+98
-80
lines changed

12 files changed

+98
-80
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,16 @@ on:
99
jobs:
1010
build-and-test:
1111
runs-on: ubuntu-latest
12-
12+
1313
steps:
1414
- name: Checkout code
1515
uses: actions/checkout@v4
16-
16+
1717
- name: Install Nix
1818
uses: cachix/install-nix-action@v27
1919
with:
2020
extra_nix_config: |
2121
experimental-features = nix-command flakes
22-
23-
- name: Build with Nix
22+
23+
- name: Build and test
2424
run: nix build
25-
26-
- name: Run core tests
27-
run: |
28-
export LGX_BINARY="$(pwd)/result/bin/lgx"
29-
./result/bin/lgx_tests
30-
31-
- name: Run library tests
32-
run: ./result/bin/lgx_lib_tests

README.md

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,7 @@ The C API header will be at `./result/include/lgx.h`.
133133

134134
#### Running Tests with Nix
135135

136-
After building with `nix build '.'` or `nix build '.#all'`, run the tests:
137-
138-
```bash
139-
# Run core tests (including CLI integration tests)
140-
export LGX_BINARY="$(pwd)/result/bin/lgx"
141-
./result/bin/lgx_tests
142-
143-
# Run library API tests
144-
./result/bin/lgx_lib_tests
145-
```
146-
147-
**Note:** The `LGX_BINARY` environment variable tells the CLI tests where to find the `lgx` binary. Without it, the CLI integration tests will be skipped (though all other tests will still run).
136+
Tests run automatically during `nix build`. The build will fail if any tests do not pass.
148137

149138
**Note:** If you haven't enabled flakes, you'll need to add the experimental features flag:
150139

@@ -212,13 +201,6 @@ This will create:
212201
```bash
213202
mkdir build
214203
cd build
215-
cmake .. -DLGX_BUILD_TESTS=ON
216-
make -j$(nproc)
217-
```
218-
219-
To also test the library:
220-
221-
```bash
222204
cmake .. -DLGX_BUILD_TESTS=ON -DLGX_BUILD_SHARED=ON
223205
make -j$(nproc)
224206
```
@@ -229,9 +211,3 @@ make -j$(nproc)
229211
cd build
230212
ctest --output-on-failure
231213
```
232-
233-
Or run the test executable directly:
234-
235-
```bash
236-
./build/lgx_tests
237-
```

docs/project.md

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ The header file `src/lgx.h` is installed to `include/` when using `make install`
234234
- `lgx_set_version(pkg, version) → lgx_result_t` - Set package version
235235
- `lgx_get_description(pkg) → const char*` - Get package description (owned by library)
236236
- `lgx_set_description(pkg, description)` - Set package description
237+
- `lgx_get_icon(pkg) → const char*` - Get package icon path (owned by library)
238+
- `lgx_set_icon(pkg, icon)` - Set package icon path
237239
- `lgx_get_manifest_json(pkg) → const char*` - Get the full manifest as a JSON string (owned by library)
238240

239241
**Memory Management:**
@@ -594,37 +596,13 @@ This builds:
594596

595597
**Running Tests with CMake:**
596598

597-
Tests are built using Google Test and can be run via CMake's CTest or directly:
599+
Tests are built using Google Test and can be run via CMake's CTest:
598600

599601
```bash
600602
cd build
601603
ctest --output-on-failure
602604
```
603605

604-
Or run test executables directly:
605-
606-
```bash
607-
# Core tests (including CLI integration tests)
608-
./build/tests/lgx_tests
609-
610-
# Library API tests (requires shared library build)
611-
./build/tests/lgx_lib_tests
612-
```
613-
614-
**CLI Integration Tests:**
615-
616-
The CLI tests (`test_cli.cpp`) require the `lgx` binary to be available. They will:
617-
1. Check for `LGX_BINARY` environment variable first
618-
2. Search common locations (build directory, parent directories)
619-
3. Skip if binary is not found
620-
621-
To run CLI tests explicitly:
622-
623-
```bash
624-
export LGX_BINARY="$(pwd)/build/lgx"
625-
./build/tests/lgx_tests
626-
```
627-
628606
**Installation:**
629607

630608
To install the built binaries and libraries system-wide:

docs/spec.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ The manifest is a UTF-8 encoded JSON file with the following required fields:
6363
"author": "Author Name",
6464
"type": "library",
6565
"category": "crypto",
66+
"icon": "icon.png",
6667
"dependencies": ["dep1", "dep2"],
6768
"main": {
6869
"linux-amd64": "path/to/main.so",
@@ -82,6 +83,7 @@ The manifest is a UTF-8 encoded JSON file with the following required fields:
8283
| `author` | string | Author/maintainer name | Human metadata |
8384
| `type` | string | Package type classification | Classification |
8485
| `category` | string | Package category | Classification |
86+
| `icon` | string | Relative path to icon file bundled in the package | Display/branding |
8587
| `dependencies` | array | List of dependency strings | Runtime needs |
8688
| `main` | object | Map of variant name → relative path to entry point (e.g ) `"linux-amd64": "path/to/main.so"` means `linux-amd64/path/to/main.so` | Entry point resolution |
8789

@@ -156,6 +158,7 @@ lgx create <name>
156158
- `author`: `""`
157159
- `type`: `""`
158160
- `category`: `""`
161+
- `icon`: `""`
159162
- `dependencies`: `[]`
160163
- `main`: `{}`
161164
4. Create empty `variants/` directory

nix/all.nix

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,6 @@ pkgs.stdenv.mkDerivation {
5252
mkdir -p $out/include
5353
cp ${src}/src/lgx.h $out/include/
5454
55-
# Install test executables
56-
mkdir -p $out/bin
57-
cp build/tests/lgx_tests $out/bin/
58-
cp build/tests/lgx_lib_tests $out/bin/
59-
60-
# Fix rpath for lgx_lib_tests to find the shared library
61-
if [ -f $out/bin/lgx_lib_tests ]; then
62-
if [[ "$OSTYPE" == "darwin"* ]]; then
63-
install_name_tool -add_rpath $out/lib $out/bin/lgx_lib_tests
64-
else
65-
patchelf --set-rpath $out/lib:$(patchelf --print-rpath $out/bin/lgx_lib_tests) $out/bin/lgx_lib_tests
66-
fi
67-
fi
68-
6955
runHook postInstall
7056
'';
7157

src/core/manifest.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Manifest::Manifest()
1919
, author("")
2020
, type("")
2121
, category("")
22+
, icon("")
2223
{
2324
}
2425

@@ -70,7 +71,13 @@ std::optional<Manifest> Manifest::fromJson(const std::string& jsonStr) {
7071
return std::nullopt;
7172
}
7273
m.category = j["category"].get<std::string>();
73-
74+
75+
if (!j.contains("icon") || !j["icon"].is_string()) {
76+
lastError_ = "Missing or invalid 'icon' field";
77+
return std::nullopt;
78+
}
79+
m.icon = j["icon"].get<std::string>();
80+
7481
if (!j.contains("dependencies") || !j["dependencies"].is_array()) {
7582
lastError_ = "Missing or invalid 'dependencies' field";
7683
return std::nullopt;
@@ -115,6 +122,7 @@ std::string Manifest::toJson() const {
115122
j["author"] = author;
116123
j["type"] = type;
117124
j["category"] = category;
125+
j["icon"] = icon;
118126
j["dependencies"] = dependencies;
119127

120128
// main as object with sorted keys

src/core/manifest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Manifest {
4545
std::string author;
4646
std::string type;
4747
std::string category;
48+
std::string icon;
4849
std::vector<std::string> dependencies;
4950

5051
// Main mapping: variant -> relative path to entry point

src/core/package.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Package::Result Package::create(
3030
pkg.manifest_.author = "";
3131
pkg.manifest_.type = "";
3232
pkg.manifest_.category = "";
33+
pkg.manifest_.icon = "";
3334
pkg.manifest_.dependencies = {};
3435

3536
// Create skeleton with manifest and variants directory

src/lgx.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,22 @@ LGX_EXPORT const char* lgx_get_description(lgx_package_t pkg);
190190
*/
191191
LGX_EXPORT void lgx_set_description(lgx_package_t pkg, const char* description);
192192

193+
/**
194+
* Get the package icon path from manifest.
195+
*
196+
* @param pkg Package handle
197+
* @return Package icon path, owned by library (valid until package is freed)
198+
*/
199+
LGX_EXPORT const char* lgx_get_icon(lgx_package_t pkg);
200+
201+
/**
202+
* Set the package icon path in manifest.
203+
*
204+
* @param pkg Package handle
205+
* @param icon New icon path string
206+
*/
207+
LGX_EXPORT void lgx_set_icon(lgx_package_t pkg, const char* icon);
208+
193209
/**
194210
* Get the full manifest as a JSON string.
195211
*

src/lib.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct lgx_package_opaque {
6868
std::string name_cache;
6969
std::string version_cache;
7070
std::string description_cache;
71+
std::string icon_cache;
7172
std::string manifest_json_cache;
7273
};
7374

@@ -280,6 +281,27 @@ LGX_EXPORT void lgx_set_description(lgx_package_t pkg, const char* description)
280281
pkg->pkg->getManifest().description = description;
281282
}
282283

284+
LGX_EXPORT const char* lgx_get_icon(lgx_package_t pkg) {
285+
if (!pkg) {
286+
set_error("Invalid argument: pkg cannot be NULL");
287+
return nullptr;
288+
}
289+
290+
clear_error();
291+
pkg->icon_cache = pkg->pkg->getManifest().icon;
292+
return pkg->icon_cache.c_str();
293+
}
294+
295+
LGX_EXPORT void lgx_set_icon(lgx_package_t pkg, const char* icon) {
296+
if (!pkg || !icon) {
297+
set_error("Invalid arguments: pkg and icon cannot be NULL");
298+
return;
299+
}
300+
301+
clear_error();
302+
pkg->pkg->getManifest().icon = icon;
303+
}
304+
283305
LGX_EXPORT const char* lgx_get_manifest_json(lgx_package_t pkg) {
284306
if (!pkg) {
285307
set_error("Invalid argument: pkg cannot be NULL");

0 commit comments

Comments
 (0)