Files
Dario LipicarandClaude Opus 5 480f40ff63 feat(abi): publish the module-impl export list as data, for backends to check against (#66)
* feat(abi): publish the module-impl export list as data, for backends to check against

logos-protocol DECLARES the module-impl C ABI; every language backend
(logos-cpp-sdk, logos-rust-sdk, and the Nim path now in flight) must
DEFINE every entry. Those are independent facts, and the gap between them
has shipped twice — grant_host_services at 0.3, the teardown pair at 0.5.
Each time it surfaced three repos downstream as an "undefined symbol" at
dlopen, on Linux only, and each time the runtime still reported the module
as LOADED, so what anyone actually saw was other modules timing out on a
replica that never appeared.

Both breakages happened at PERFECT version agreement between the caller
and the module. Version agreement is necessary and not sufficient: it says
nothing about which symbols a given backend's emitter happens to write.

So derive the list once, here, in the repo that owns the ABI, and ship it
as a build output:

  packages.<sys>.module-impl-abi
    exports.txt  — the declared names
    version      — the protocol version that header belongs to
    bin/logos-module-impl-diff — the assertion, and the explanation

Two properties follow from putting it here rather than in each backend.
There is ONE parser to keep working, rather than one regex per language
that can each silently stop matching. And the list is version-correct with
no version arithmetic anywhere: the header is itself versioned — at 0.4 it
declared eight exports, at 0.5 it declares ten — so "what this protocol
requires" is just "what this header declares". A backend pinning 0.4 reads
eight and is right to define eight. No @since tags, no MINOR comparisons,
nothing for a backend to get wrong.

The extractor parses LOGICAL declarations rather than lines (a reflowed
header must not silently drop one) and refuses to emit a list it is unsure
of: under-reporting is the dangerous direction, because a short list makes
every consumer's diff pass over an ABI nobody checked. The floor it checks
against is asserted rather than derived, so a broken parse cannot satisfy
it. logos-protocol failing to build is the right consequence of
logos-protocol being unable to state its own ABI.

checks.<sys>.module-impl-abi-tests proves all of that can still fail: empty
header, renamed macro, a founding export removed, an empty defined-set, and
a reflowed declaration — eleven cases, each a way this could have decayed
into a green check over nothing.

Also corrects the compatibility note above logos_module_about_to_unload.
It argued the pair was safe because "the glue is generated alongside the
module". That does not follow, and is the reasoning the 0.5 break rested on.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* ci: run the ABI manifest check — `nix build .#tests` never reaches `checks`

The step added here is not incidental. `nix build '.#tests'` builds the
PACKAGE; nothing in this workflow evaluated the `checks` attrset at all, so
the manifest self-test added in the previous commit would have sat there
green-by-absence — which is precisely the failure mode it exists to catch.

`ws test` is not a substitute either: it evaluates exactly one check per
repo (scripts/ws truncates the checks JSON at the first comma), so a green
`ws test logos-protocol` says nothing about whether this ran.

builtins.currentSystem rather than a literal, so one line is correct on both
matrix runners.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(abi): the helper must not depend on the consumer's PATH — and the suite must notice

Two bugs, and the second is the interesting one.

1. The installed helper carried `#!/usr/bin/env bash`. Consumers execute it
   from inside their own nix builds, whose PATH is whatever THEIR
   nativeBuildInputs provide. It resolved on macOS and not in the Linux
   sandbox, so the helper simply did not run there. patchShebangs pins an
   absolute interpreter.

2. The self-test did not notice, and the reason is worth keeping. expect_fail
   accepted ANY non-zero exit as a correct refusal — but a script that cannot
   be executed exits 126/127, so all five refusal cases reported PASS while
   proving nothing at all. Only the two POSITIVE cases failed, which is the
   only reason this surfaced.

   That is precisely the failure this whole change exists to prevent, one
   level up: a check that reports green over something it never examined. So
   expect_fail now asserts a deliberate refusal and rejects 126/127 by name.

Caught by CI on ubuntu-latest while macOS was green — the same
platform-asymmetry that let the original ABI break through.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 12:06:48 -03:00

92 lines
3.2 KiB
Nix

{
description = "Logos Protocol - transports, token exchange and the language-neutral lp_* C ABI";
inputs.logos-nix.url = "github:logos-co/logos-nix";
inputs.nixpkgs.follows = "logos-nix/nixpkgs";
outputs = { self, nixpkgs, logos-nix }:
let
systems = [ "aarch64-darwin" "x86_64-darwin" "aarch64-linux" "x86_64-linux" ];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f {
inherit system;
pkgs = import nixpkgs { inherit system; };
});
# Adds the "x86_64-windows" pseudo-system. A cross derivation's `system`
# attribute is its BUILD platform, so packages.x86_64-windows.* evaluates
# anywhere but realises on x86_64-linux.
forAllTargets = logos-nix.lib.forAllTargets;
in
{
packages = forAllTargets ({ pkgs, ... }:
let
common = import ./nix/default.nix { inherit pkgs; };
src = ./.;
lib = import ./nix/lib.nix { inherit pkgs common src; };
include = import ./nix/include.nix { inherit pkgs common src; };
tests = import ./nix/tests.nix { inherit pkgs common src; };
# The module-impl C ABI as data, for the language backends to check
# themselves against. See nix/module-impl-abi.nix.
module-impl-abi = import ./nix/module-impl-abi.nix { inherit pkgs common src; };
# Combined package: static lib + cmake config + source-export
# headers. propagatedBuildInputs re-declared on the join because
# symlinkJoin doesn't forward propagation from `paths`. Qt is
# excluded for the same setup-hook ordering reason as in
# nix/default.nix; consumers list qt6.qtbase +
# qt6.wrapQtAppsNoGuiHook themselves.
protocol = pkgs.symlinkJoin {
name = "logos-protocol";
paths = [ lib include ];
propagatedBuildInputs = common.propagatedBuildInputs;
};
in
{
logos-protocol-lib = lib;
logos-protocol-include = include;
inherit tests module-impl-abi;
logos-protocol = protocol;
default = protocol;
}
);
checks = forAllSystems ({ pkgs, ... }:
let
common = import ./nix/default.nix { inherit pkgs; };
src = ./.;
tests = import ./nix/tests.nix { inherit pkgs common src; };
module-impl-abi = import ./nix/module-impl-abi.nix { inherit pkgs common src; };
in
{
inherit tests;
# Proves the ABI manifest every backend checks itself against can
# still fail. See nix/tests-module-impl-abi.nix.
module-impl-abi-tests = import ./nix/tests-module-impl-abi.nix {
inherit pkgs common src module-impl-abi;
};
}
);
devShells = forAllSystems ({ pkgs, ... }: {
default = pkgs.mkShell {
nativeBuildInputs = [
pkgs.cmake
pkgs.ninja
pkgs.pkg-config
];
buildInputs = [
pkgs.qt6.qtbase
pkgs.qt6.qtremoteobjects
pkgs.gtest
pkgs.boost
pkgs.openssl
pkgs.nlohmann_json
];
};
});
};
}