mirror of
https://github.com/logos-co/logos-cpp-sdk.git
synced 2026-08-30 17:21:15 +00:00
* Extract the protocol layer into logos-protocol; consume it as a flake input
The transport/token/IPC layer (transports incl. QRO + plain TCP/TLS,
consumer core LogosAPIClient/LogosAPIConsumer with the capability
auto-requestModule flow, ModuleProxy, token manager, QVariant<->JSON
conversion, the abstract LogosProviderObject interface) now lives in the
logos-protocol repo behind the versioned lp_* C ABI.
This SDK keeps the typed C++ developer layer (LogosAPI, provider base
classes + Qt provider glue, module context, code generator) and still
compiles the protocol sources INTO liblogos_sdk.a from the flake input,
so the installed artifact (archive symbols, include/ + include/cpp
layouts, cmake config) stays byte-compatible: existing consumers need
no changes. Public headers are unchanged; logos_provider_object.h keeps
its name and now re-exports the abstract interface from
logos_provider_interface.h.
Transport/protocol component tests moved to logos-protocol with the
code; the remaining sdk/generator/experimental suites are unchanged
(432/432 green against the local protocol checkout).
* lock: add logos-protocol input
* Make the base SDK Qt-free: move the Qt developer layer to logos-qt-sdk
LogosAPI, LogosAPIProvider, LogosProviderBase/LOGOS_PROVIDER macros, the
QObject provider glue (QtProviderObject) and the legacy PluginInterface
(core/interface.h) move to the new logos-qt-sdk repo. The protocol
sources are no longer compiled into a monolithic archive — consumers
link logos-qt-sdk (which layers on logos-protocol) instead.
What remains here is header-only std C++: logos_module_context.h,
logos_result.h (StdLogosResult), logos_json.h — exported as the CMake
INTERFACE target logos-cpp-sdk::logos_headers — plus the code generator
(a build-time tool; its introspection mode now includes
logos_provider_interface.h from logos-protocol, where
LogosProviderPlugin moved).
Mechanically verified Qt-free: the logos-cpp-lib / logos-cpp-include
closures contain only nlohmann_json. Tests: 245/245 (module-context std
suite + generator + experimental).
* Cdylib authoring backend: --backend cdylib emits the common C ABI wrapper + uniform Qt glue
From a module's LIDL contract the generator now emits:
- <name>_module_impl.cpp — the Qt-FREE logos_module_impl.h export
wrapper (dispatch/get_methods/set_context/set_emit_callback/
accept_token/get_protocol_version/string_free) around the universal
impl class; compiled into the module's cdylib. Tagged {"_bytes"}
bytes, StdLogosResult -> {success,value,error}, context via the
existing _logos_codegen_::maybeSet* SFINAE helpers.
- <name>_events_cdylib.cpp — typed logos_events: bodies marshalling
into nlohmann::json (the cdylib flavor of the events sidecar).
- <name>_cdylib_glue.{h,cpp} — the UNIFORM Qt-plugin glue forwarding
LogosProviderObject to the C symbols; identical regardless of the
module's source language (the Rust SDK emits the same exports).
- the .lidl sidecar.
Qt-container types are rejected at generation time (a cdylib impl is
Qt-free by definition). Verified end-to-end by dlopen smoke: typed
dispatch, typed events through the emit callback, result returns,
introspection, and the protocol-version handshake — and the SAME C
harness passes against a Rust cdylib generated by logos-lidl-gen
--provider.
* fix: accept the installed source-export layout in the protocol-root check
The fail-fast only tested <root>/cpp/logos_protocol.h, but the LP_SRC
selection right below (and the error message itself) support the
installed export layout <root>/include/cpp as well. Pointing
LOGOS_PROTOCOL_ROOT at an installed export tripped the FATAL_ERROR
before that fallback could apply.
Caught by Copilot review on #82.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* lock: pin logos-protocol to the qt-free-split branch head
The Qt-free SDK (and the cdylib backend stacked on it) reference
LogosProviderPlugin from protocol's logos_provider_interface.h, which
lands on feat/qt-free-split — the P1-branch pin no longer compiles
standalone. Temporary — drop when the chain PRs merge.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* lock: pin logos-protocol to the qt-free-split branch head
The Qt-free SDK (and the cdylib backend stacked on it) reference
LogosProviderPlugin from protocol's logos_provider_interface.h, which
lands on feat/qt-free-split — the P1-branch pin no longer compiles
standalone. Temporary — drop when the chain PRs merge.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* doctest: pin the logoscore runtime via its {release} placeholder
The spec built logoscore-cli at bare master with only the cpp-sdk inputs
overridden — master's stack cannot compile against the qt-free SDK, so
the suite failed on the chain branches. With the placeholder, CI's
--release-for pins expand it to the workspace's logoscore commit (and
local runs without a pin still fall back to master, unchanged).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* doctest: override the nested module builders to {release} too
capability_module (via logoscore's lock) and the cloned accounts module
resolve module-builder from their own locks — pre-split revs whose
LogosModule.cmake still detects the SDK by logos_api.h, which the
qt-free SDK no longer ships ('logos-cpp-sdk not found'). Overriding the
builder itself to the workspace-pinned chain rev (keeping the nested
cpp-sdk override) builds both modules with the split-aware builder.
Verified end-to-end locally with the exact doctest command.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* doctest: apply the {release} + nested-builder overrides to all three specs
The runtime spec got the treatment in 210eea1; the composition and
worker-thread specs have the same logoscore/module build commands and
failed identically (pre-split builders from the modules' own locks).
All executed run: blocks now pin logoscore-cli{release} and override
the nested module builders to logos-module-builder{release}; the
displayed code_block: variants stay in their generic master form.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* generator: glue-only cdylib mode for non-C++ impls
--lidl x.lidl --backend cdylib (no --impl-class) emits just the uniform
Qt-plugin glue; the C exports come from the module's own language
backend (e.g. the Rust SDK's lidl-gen --provider). This is the entry
point logos-module-builder's cdylib interface uses for Rust modules.
* cdylib glue: root plugin implements PluginInterface
logos_host's module_initializer hard-requires PluginInterface on the
root plugin before any provider detection — same bases as the qt glue
(QObject, PluginInterface, LogosProviderPlugin). Caught by the first
host-loaded run of a cdylib-authored module; the dlopen smoke harness
exercised only the C seam.
* cdylib glue: seed the cdylib's protocol stack with the host auth token
The glue's init() reads the authToken property module_initializer now
surfaces on the LogosAPI object and forwards it across
logos_module_accept_token under the initializer's own keys
(core / capability_module). Without it the cdylib's TokenManager (a
separate static copy of the singleton) is empty and every outbound
call — including the capability requestModule bootstrap — is rejected
as unauthorized.
* cdylib glue: provider derives LogosProviderBase; tokens land in BOTH stacks
informModuleToken = base save (host-stack TokenManager — what ModuleProxy
validates inbound calls against, incl. the grant the daemon pushes after
a capability requestModule) + C-ABI forward (the cdylib's own stack, for
outbound auth). init folds into onInit; the authToken property seeding
stays.
* lock: protocol integer-fidelity fix
* codegen: typed wrappers throw on call failure; dispatch catches escapes
Generated sync client wrappers call the new err-out invokeRemoteMethod
overload and throw logos::LogosCallError when the call fails (e.g. the
bound module is missing) — previously the empty QVariant silently
degraded to the return type's default and a caller could not tell
failure from a legitimate 0 / "". Both generators (legacy + LIDL),
both API styles. Async paths unchanged.
Generated provider dispatch (universal qt glue + LOGOS_PROVIDER) wraps
the method body in a catch-all that logs and returns an invalid QVariant
— an escaped exception becomes an ordinary METHOD_FAILED instead of
unwinding through Qt event dispatch and killing the module process.
* fix: restore a clean flake.lock after the merge conflict (protocol 176fbc8)
* codegen: CallError out-param instead of throwing wrappers
Per review, the generated sync wrappers expose the error channel as an
optional trailing parameter — add(a, b, &err) — rather than throwing:
explicit, stateless, works on temporaries, and existing call sites
compile unchanged (they keep default-on-failure, now with a qWarning so
failures are visible in the module log). The dispatch catch-all from the
previous commit stays: it contains author exceptions, it doesn't
introduce any.
* generator: contract-first C++ cdylib modules from --lidl
--lidl x.lidl --backend cdylib with --impl-class/--impl-header now emits
the FULL set (C-ABI export wrapper + events + uniform glue) around the
named hand-written Qt-free impl class — the C++ mirror of declaring the
contract in .lidl and implementing the Rust trait. Without --impl-class
the glue-only mode is unchanged.
* glue: fire onContextReady AFTER modules()/event wiring
The generated onInit set the context (which fires the impl's
onContextReady hook) before constructing the LogosModules aggregate and
wiring typed event emission — so an impl doing its documented one-time
setup there (typed dependency calls, event subscriptions) dereferenced
a null aggregate and crashed the module process (signal 11). Found by
the first module to subscribe to a dependency's typed event from
onContextReady. Context now goes last.
* cdylib: fire the context-ready hook at module LOAD, not first dispatch
The impl-exports wrapper used to fire maybeSetContext (stamp + hook)
immediately inside logos_module_set_context — which the glue calls during
onInit, BEFORE the auth token is seeded and BEFORE ModuleProxy wires the
emit callback. A hook that made outbound calls or emitted events ran
half-wired; and the Rust scaffold deferred its hook to first dispatch
entirely, so a Rust module couldn't subscribe/emit/act until someone
called it — a capability gap vs the universal C++ path.
Two changes, applied uniformly:
- The glue's onInit now seeds the auth token FIRST and forwards the
context LAST (the same context-last convention as the universal onInit
ordering fix).
- The impl-exports gained a ready-latch (lidlTryFireContext): the context
is stored on set_context and the hook fires ONCE as soon as both the
context AND the emit callback have been delivered — during module
registration, before the module is published for inbound calls. Hosts
that never wire an emit callback still get the hook before the first
dispatch (requireEmit=false fallback in logos_module_dispatch).
The Rust scaffold (logos-rust-sdk lidl-gen) implements the same latch, so
on_context_ready now matches C++ onContextReady semantics: subscriptions,
authenticated outbound calls and typed emission all work from the hook at
load time.
* ci: run workflows on stacked PRs + workflow_dispatch
Both workflows filtered pull_request to master-based PRs, so stacked PRs
(feat/qt-free-sdk -> feat/extract-logos-protocol, feat/cdylib-authoring
-> feat/qt-free-sdk) ran NO checks at all. Drop the base-branch filter
for pull_request and add workflow_dispatch for manual runs. Same fix as
logos-module-builder 232b8a2.
* generator: --backend ui — universal authoring for UI plugin backends
New emitters (lidl_gen_ui.{h,cpp}) for type=ui_qml + interface=universal
modules: from the author's single clean impl class (optionally deriving
LogosModuleContext), generate
<name>.rep — the view contract, one SLOT per public method
(framework hooks like onContextReady excluded)
<name>_ui_interface.h — PluginInterface subclass + IID
<name>_ui_glue.{h,cpp}— plugin deriving <Cls>SimpleSource +
<Cls>Interface + <Cls>ViewPluginBase; slots
forward to the impl (std<->Qt at the boundary);
Q_INVOKABLE initLogos(LogosAPI*) builds
LogosModules, wires modules(), stamps context
(fires onContextReady — same order as the
universal core glue), then setBackend(this).
Typed dependency callers, typed event subscriptions and bind_<interface>
binders come from the existing umbrella pass (logos_sdk.h), which already
runs for UI modules. ui-host's reflection-based initLogos call site is
unchanged; legacy LogosAPI*-based UI plugins are untouched. v1 view API
types: void/int/uint/float64/bool/string; logos_events: rejected for ui
backends (views talk to QML via .rep, not module events).
* generator: distribute the LIDL frontend for external generators
First step of moving ALL Qt glue emission out of this repo into
logos-qt-sdk's logos-qt-generator (cpp-sdk's generator keeps only the
Qt-free outputs: std typed wrappers, logos_sdk umbrella, cdylib
impl-exports, LIDL derivation).
- Shared emit helpers (lidlToPascalCase, lidlTypeToQt, lidlTypeToStd,
lidlIsStdConvertible) move to a new lidl_emit_common.{h,cpp} unit, used
by both generators.
- The frontend set (AST, lexer, parser, serializer, validator,
impl-header parser, emit-common) is installed under
share/lidl-frontend/ — the qt generator compiles these sources in
directly, so the two tools share one frontend without a binary ABI.
* generator: Qt glue emission removed — logos-qt-generator owns it
The deletion half of the generator split (counterpart: logos-qt-sdk
3b37474, builder d7a2272). This tool now emits ONLY Qt-free outputs:
kept std typed wrappers + logos_sdk umbrella (--general-only),
cdylib C-ABI impl-exports + typed event emitters
(--lidl/--from-header --backend cdylib --impl-class),
LIDL derivation/serialization (--header-to-lidl), client stubs
removed universal Qt glue (--backend qt), the uniform cdylib Qt glue,
the ui backend emitters — all relocated verbatim (byte-identical
output verified) to logos-qt-generator; invocations here now
fail with a pointer to the right tool
The provider-glue golden tests travel with the emitters (to be re-homed
in logos-qt-sdk's test suite); test_lidl_type_mapping stays — it covers
lidl_emit_common, which both generators compile.
* lock: protocol at the typed-requestModule port (3de5398)
* lock: protocol at the typed-requestModule port (3de5398)
* ci: chain pins for the doc-tests (drop at merge)
In repo CI only cpp-sdk's {release} is the commit under test —
logoscore-cli and module-builder expanded to master, which doesn't link
against the chain SDK the specs override in ('Build the CLI with the SDK
override' failed on every run since the stacked-PR triggers were
enabled). Pin both to the extraction-chain heads; the workspace pipeline
is unaffected (it pins every repo itself).
* generator: distribute the LIDL frontend for external generators
First step of moving ALL Qt glue emission out of this repo into
logos-qt-sdk's logos-qt-generator (cpp-sdk's generator keeps only the
Qt-free outputs: std typed wrappers, logos_sdk umbrella, cdylib
impl-exports, LIDL derivation).
- Shared emit helpers (lidlToPascalCase, lidlTypeToQt, lidlTypeToStd,
lidlIsStdConvertible) move to a new lidl_emit_common.{h,cpp} unit, used
by both generators.
- The frontend set (AST, lexer, parser, serializer, validator,
impl-header parser, emit-common) is installed under
share/lidl-frontend/ — the qt generator compiles these sources in
directly, so the two tools share one frontend without a binary ABI.
* docs: note the generator split (Qt glue emission lives in logos-qt-sdk)
* lock: protocol#3 merged — pin advances to protocol master
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
333 lines
15 KiB
C++
333 lines
15 KiB
C++
#include "legacy/legacy_main.h"
|
|
#include "experimental/lidl_gen_client.h"
|
|
#include "experimental/lidl_gen_cdylib.h"
|
|
#include "experimental/lidl_parser.h"
|
|
#include "experimental/lidl_serializer.h"
|
|
#include "experimental/impl_header_parser.h"
|
|
|
|
#include <QCoreApplication>
|
|
#include <QDir>
|
|
#include <QFile>
|
|
#include <QFileInfo>
|
|
#include <QTextStream>
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
// Check for --lidl / --from-header / --header-to-lidl mode before
|
|
// initializing QCoreApplication, since legacy_main creates its own.
|
|
bool hasLidl = false;
|
|
bool hasFromHeader = false;
|
|
bool hasHeaderToLidl = false;
|
|
for (int i = 1; i < argc; ++i) {
|
|
QString arg = QString::fromUtf8(argv[i]);
|
|
if (arg == "--lidl") hasLidl = true;
|
|
if (arg == "--from-header") hasFromHeader = true;
|
|
if (arg == "--header-to-lidl") hasHeaderToLidl = true;
|
|
}
|
|
|
|
// --header-to-lidl: the C++ frontend of the source -> LIDL -> bindings
|
|
// pipeline. Parse an impl header and emit ONLY its LIDL contract (no Qt
|
|
// glue / dispatch), so a module can publish a cheap `lidl` artifact that
|
|
// consumers (any language) turn into bindings without building the module.
|
|
if (hasHeaderToLidl) {
|
|
QCoreApplication app(argc, argv);
|
|
QTextStream err(stderr);
|
|
QTextStream out(stdout);
|
|
const QStringList args = app.arguments();
|
|
|
|
// Strip a leading '@' from path arguments — some build drivers pass
|
|
// `@/abs/path`. Matches the legacy_main path handling.
|
|
auto stripAt = [](QString p) { if (p.startsWith('@')) p.remove(0, 1); return p; };
|
|
|
|
const int idx = args.indexOf("--header-to-lidl");
|
|
if (idx + 1 >= args.size()) {
|
|
err << "Error: --header-to-lidl requires a path to the impl header\n";
|
|
return 1;
|
|
}
|
|
const QString headerPath = stripAt(args.at(idx + 1));
|
|
|
|
const int implClassIdx = args.indexOf("--impl-class");
|
|
if (implClassIdx == -1 || implClassIdx + 1 >= args.size()) {
|
|
err << "Error: --header-to-lidl requires --impl-class <ClassName>\n";
|
|
return 1;
|
|
}
|
|
const QString implClass = args.at(implClassIdx + 1);
|
|
|
|
const int metadataIdx = args.indexOf("--metadata");
|
|
if (metadataIdx == -1 || metadataIdx + 1 >= args.size()) {
|
|
err << "Error: --header-to-lidl requires --metadata <metadata.json>\n";
|
|
return 1;
|
|
}
|
|
const QString metadataPath = stripAt(args.at(metadataIdx + 1));
|
|
|
|
ImplParseResult pr = parseImplHeader(headerPath, implClass, metadataPath, err);
|
|
if (pr.hasError()) {
|
|
err << "Error parsing impl header: " << pr.error << "\n";
|
|
return 4;
|
|
}
|
|
const ModuleDecl& mod = pr.module;
|
|
|
|
// Output path: explicit -o/--output <file>, else <output-dir>/<name>.lidl,
|
|
// else <name>.lidl in the CWD.
|
|
QString outPath;
|
|
const int oIdx = args.indexOf("-o");
|
|
const int outputIdx = args.indexOf("--output");
|
|
const int outDirIdx = args.indexOf("--output-dir");
|
|
if (oIdx != -1 && oIdx + 1 < args.size()) {
|
|
outPath = stripAt(args.at(oIdx + 1));
|
|
} else if (outputIdx != -1 && outputIdx + 1 < args.size()) {
|
|
outPath = stripAt(args.at(outputIdx + 1));
|
|
} else if (outDirIdx != -1 && outDirIdx + 1 < args.size()) {
|
|
const QString d = stripAt(args.at(outDirIdx + 1));
|
|
QDir().mkpath(d);
|
|
outPath = QDir(d).filePath(mod.name + ".lidl");
|
|
} else {
|
|
outPath = mod.name + ".lidl";
|
|
}
|
|
|
|
QFile f(outPath);
|
|
if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
|
|
err << "Failed to write LIDL: " << outPath << "\n";
|
|
return 5;
|
|
}
|
|
f.write(lidlSerialize(mod).toUtf8());
|
|
f.close();
|
|
out << "Generated LIDL: " << outPath << " (" << mod.methods.size()
|
|
<< " methods, " << mod.events.size() << " events)\n";
|
|
out.flush();
|
|
return 0;
|
|
}
|
|
|
|
if (hasLidl || hasFromHeader) {
|
|
QCoreApplication app(argc, argv);
|
|
QTextStream err(stderr);
|
|
QTextStream out(stdout);
|
|
const QStringList args = app.arguments();
|
|
|
|
QString outputDir;
|
|
const int outDirIdx = args.indexOf("--output-dir");
|
|
if (outDirIdx != -1 && outDirIdx + 1 < args.size()) {
|
|
outputDir = args.at(outDirIdx + 1);
|
|
}
|
|
|
|
// --from-header mode: parse C++ impl header directly (no .lidl needed)
|
|
if (hasFromHeader) {
|
|
const int fromHeaderIdx = args.indexOf("--from-header");
|
|
if (fromHeaderIdx + 1 >= args.size()) {
|
|
err << "Error: --from-header requires a path to the impl header\n";
|
|
return 1;
|
|
}
|
|
QString headerPath = args.at(fromHeaderIdx + 1);
|
|
|
|
const int implClassIdx = args.indexOf("--impl-class");
|
|
if (implClassIdx == -1 || implClassIdx + 1 >= args.size()) {
|
|
err << "Error: --from-header requires --impl-class <ClassName>\n";
|
|
return 1;
|
|
}
|
|
QString implClass = args.at(implClassIdx + 1);
|
|
|
|
const int metadataIdx = args.indexOf("--metadata");
|
|
if (metadataIdx == -1 || metadataIdx + 1 >= args.size()) {
|
|
err << "Error: --from-header requires --metadata <metadata.json>\n";
|
|
return 1;
|
|
}
|
|
QString metadataPath = args.at(metadataIdx + 1);
|
|
|
|
// --impl-header: the include path for generated code (defaults to header filename)
|
|
QString implHeader;
|
|
const int implHeaderIdx = args.indexOf("--impl-header");
|
|
if (implHeaderIdx != -1 && implHeaderIdx + 1 < args.size()) {
|
|
implHeader = args.at(implHeaderIdx + 1);
|
|
} else {
|
|
implHeader = QFileInfo(headerPath).fileName();
|
|
}
|
|
|
|
const int backendIdx = args.indexOf("--backend");
|
|
if (backendIdx == -1 || backendIdx + 1 >= args.size()) {
|
|
err << "Error: --from-header requires --backend <qt>\n";
|
|
return 1;
|
|
}
|
|
QString backend = args.at(backendIdx + 1);
|
|
|
|
// Parse the impl header
|
|
ImplParseResult pr = parseImplHeader(headerPath, implClass, metadataPath, err);
|
|
if (pr.hasError()) {
|
|
err << "Error parsing impl header: " << pr.error << "\n";
|
|
return 4;
|
|
}
|
|
|
|
const ModuleDecl& mod = pr.module;
|
|
QString genDirPath = outputDir.isEmpty()
|
|
? QDir::current().filePath("generated")
|
|
: outputDir;
|
|
QDir().mkpath(genDirPath);
|
|
|
|
if (backend == "cdylib") {
|
|
// Cdylib authoring: the common module-impl C ABI exports +
|
|
// the uniform Qt-plugin glue (language-agnostic, forwards to
|
|
// the C symbols). See logos_module_impl.h in logos-protocol.
|
|
QString cdErr;
|
|
if (!lidlCdylibSupported(mod, &cdErr)) {
|
|
err << "Error: module not cdylib-eligible: " << cdErr << "\n";
|
|
return 10;
|
|
}
|
|
struct Out { QString file; QString content; };
|
|
QList<Out> outs;
|
|
outs.append({mod.name + "_module_impl.cpp",
|
|
lidlMakeModuleImplExports(mod, implClass, implHeader)});
|
|
if (!mod.events.isEmpty())
|
|
outs.append({mod.name + "_events_cdylib.cpp",
|
|
lidlMakeEventsSourceCdylib(mod, implClass, implHeader)});
|
|
outs.append({mod.name + ".lidl", lidlSerialize(mod)});
|
|
for (const Out& o : outs) {
|
|
const QString abs = QDir(genDirPath).filePath(o.file);
|
|
QFile f(abs);
|
|
if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
|
|
err << "Failed to write: " << abs << "\n";
|
|
return 11;
|
|
}
|
|
f.write(o.content.toUtf8());
|
|
out << "Generated: " << abs << "\n";
|
|
}
|
|
out.flush();
|
|
return 0;
|
|
}
|
|
|
|
if (backend == "qt") {
|
|
err << "Error: Qt glue generation moved to logos-qt-generator "
|
|
"(logos-qt-sdk). Use it for --backend qt; this tool "
|
|
"keeps the Qt-free outputs (--header-to-lidl emits the "
|
|
".lidl sidecar).\n";
|
|
return 6;
|
|
}
|
|
|
|
err << "Error: --from-header supports --backend cdylib (Qt glue: logos-qt-generator)\n";
|
|
return 1;
|
|
}
|
|
|
|
// --lidl mode
|
|
const int lidlIdx = args.indexOf("--lidl");
|
|
if (lidlIdx + 1 >= args.size()) {
|
|
err << "Usage: " << QFileInfo(app.applicationFilePath()).fileName()
|
|
<< " --lidl /path/to/module.lidl [--output-dir /path] [--module-only]\n"
|
|
<< " " << QFileInfo(app.applicationFilePath()).fileName()
|
|
<< " --lidl /path/to/module.lidl --backend qt --impl-class Class --impl-header header.h [--output-dir /path]\n"
|
|
<< " " << QFileInfo(app.applicationFilePath()).fileName()
|
|
<< " --lidl /path/to/module.lidl --backend cdylib [--output-dir /path] (glue-only: C exports come from the module's own language backend)\n"
|
|
<< " " << QFileInfo(app.applicationFilePath()).fileName()
|
|
<< " --from-header src/impl.h --backend qt --impl-class Class --metadata metadata.json [--output-dir /path]\n";
|
|
return 1;
|
|
}
|
|
QString lidlPath = args.at(lidlIdx + 1);
|
|
|
|
// Provider glue mode: --backend qt --impl-class X --impl-header Y
|
|
const int backendIdx = args.indexOf("--backend");
|
|
if (backendIdx != -1) {
|
|
if (backendIdx + 1 >= args.size()) {
|
|
err << "Error: --backend requires an argument (e.g., qt)\n";
|
|
return 1;
|
|
}
|
|
QString backend = args.at(backendIdx + 1);
|
|
|
|
const int implClassIdx = args.indexOf("--impl-class");
|
|
const int implHeaderIdx = args.indexOf("--impl-header");
|
|
|
|
// Cdylib-from-LIDL (contract-first):
|
|
// - with no --impl-class: GLUE-ONLY — the C exports come from
|
|
// the module's own language backend (e.g. the Rust SDK's
|
|
// lidl-gen --provider); the glue only knows the C symbols.
|
|
// - with --impl-class/--impl-header: the FULL set — the C-ABI
|
|
// export wrapper around the named (hand-written, Qt-free)
|
|
// C++ impl class, plus the same uniform glue. The contract
|
|
// stays the .lidl; the author just implements the class.
|
|
if (backend == "cdylib") {
|
|
QFile f(lidlPath);
|
|
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
err << "Error: cannot read " << lidlPath << "\n";
|
|
return 1;
|
|
}
|
|
LidlParseResult pr = lidlParse(QString::fromUtf8(f.readAll()));
|
|
if (pr.hasError()) {
|
|
err << "Error parsing " << lidlPath << ": " << pr.error
|
|
<< " (line " << pr.errorLine << ")\n";
|
|
return 4;
|
|
}
|
|
const ModuleDecl& mod = pr.module;
|
|
QString cdErr;
|
|
if (!lidlCdylibSupported(mod, &cdErr)) {
|
|
err << "Error: module not cdylib-eligible: " << cdErr << "\n";
|
|
return 10;
|
|
}
|
|
QString genDirPath = outputDir.isEmpty()
|
|
? QDir::current().filePath("generated")
|
|
: outputDir;
|
|
QDir().mkpath(genDirPath);
|
|
struct Out { QString file; QString content; };
|
|
QList<Out> outs;
|
|
if (implClassIdx != -1) {
|
|
if (implClassIdx + 1 >= args.size()) {
|
|
err << "Error: --impl-class requires a class name\n";
|
|
return 1;
|
|
}
|
|
const QString implClass = args.at(implClassIdx + 1);
|
|
QString implHeader;
|
|
if (implHeaderIdx != -1 && implHeaderIdx + 1 < args.size())
|
|
implHeader = args.at(implHeaderIdx + 1);
|
|
else
|
|
implHeader = mod.name + "_impl.h";
|
|
outs.append({mod.name + "_module_impl.cpp",
|
|
lidlMakeModuleImplExports(mod, implClass, implHeader)});
|
|
if (!mod.events.isEmpty())
|
|
outs.append({mod.name + "_events_cdylib.cpp",
|
|
lidlMakeEventsSourceCdylib(mod, implClass, implHeader)});
|
|
} else {
|
|
err << "Error: the uniform cdylib Qt glue is generated by "
|
|
"logos-qt-generator (logos-qt-sdk); this tool emits "
|
|
"the Qt-free C-ABI export wrapper, which requires "
|
|
"--impl-class.\n";
|
|
return 12;
|
|
}
|
|
for (const Out& o : outs) {
|
|
const QString abs = QDir(genDirPath).filePath(o.file);
|
|
QFile of(abs);
|
|
if (!of.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
|
|
err << "Failed to write: " << abs << "\n";
|
|
return 11;
|
|
}
|
|
of.write(o.content.toUtf8());
|
|
out << "Generated: " << abs << "\n";
|
|
}
|
|
out.flush();
|
|
return 0;
|
|
}
|
|
|
|
if (implClassIdx == -1 || implClassIdx + 1 >= args.size()) {
|
|
err << "Error: --backend " << backend << " requires --impl-class <ClassName>\n";
|
|
return 1;
|
|
}
|
|
if (implHeaderIdx == -1 || implHeaderIdx + 1 >= args.size()) {
|
|
err << "Error: --backend " << backend << " requires --impl-header <header.h>\n";
|
|
return 1;
|
|
}
|
|
|
|
QString implClass = args.at(implClassIdx + 1);
|
|
QString implHeader = args.at(implHeaderIdx + 1);
|
|
|
|
if (backend == "qt") {
|
|
err << "Error: Qt glue generation moved to logos-qt-generator "
|
|
"(logos-qt-sdk).\n";
|
|
return 6;
|
|
}
|
|
|
|
err << "Error: unsupported backend '" << backend << "' (supported: cdylib)\n";
|
|
return 1;
|
|
}
|
|
|
|
// Client stub mode (default)
|
|
bool moduleOnly = args.contains("--module-only");
|
|
return lidlGenerateClientStubs(lidlPath, outputDir, moduleOnly, out, err);
|
|
}
|
|
|
|
return legacy_main(argc, argv);
|
|
}
|