Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 93 additions & 19 deletions .github/workflows/ffi-full-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ on:
- 'scripts/build-header-refc.sh'
- 'scripts/test-refc-staging.sh'
- '.github/workflows/ffi-full-integration.yml'
- 'bindings/elixir/native/proven_nif/src/lib.rs'
- 'scripts/check-native-nif-exports.sh'
- 'tests/check-native-nif-exports.sh'
- 'tests/check-refc-staging.sh'
pull_request:
paths:
- 'src/**'
Expand All @@ -25,11 +29,32 @@ on:
- 'scripts/build-header-refc.sh'
- 'scripts/test-refc-staging.sh'
- '.github/workflows/ffi-full-integration.yml'
- 'bindings/elixir/native/proven_nif/src/lib.rs'
- 'scripts/check-native-nif-exports.sh'
- 'tests/check-native-nif-exports.sh'
- 'tests/check-refc-staging.sh'
workflow_dispatch:
concurrency:
group: ffi-full-integration-${{ github.ref }}
cancel-in-progress: true
jobs:
nif-abi-symbol-controls:
name: Native ABI symbol validator (planted controls only)
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- name: Checkout proven
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
persist-credentials: false
- name: Execute real positive and negative controls
# This proves the validator detects missing exports. It does NOT
# imply any real libproven artifact was built or validated.
run: bash tests/check-native-nif-exports.sh
- name: RefC staging regression controls
# Planted empty/stale compiler outputs must not become fake evidence.
run: bash tests/check-refc-staging.sh

idris-refc-zig:
name: Idris -> RefC -> Zig
runs-on: ubuntu-22.04
Expand All @@ -39,6 +64,53 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
persist-credentials: false
- name: Check language-bridges credential
id: bridge-token
env:
LANGUAGE_BRIDGES_TOKEN: ${{ secrets.LANGUAGE_BRIDGES_TOKEN }}
run: |
set -euo pipefail
if [ -z "$LANGUAGE_BRIDGES_TOKEN" ]; then
echo "available=false" >> "$GITHUB_OUTPUT"
echo "::error title=Full FFI not run::LANGUAGE_BRIDGES_TOKEN is absent; genuine Idris2/RefC/Zig integration cannot be verified."
echo "PROVEN_FFI_CLASS=not_run:missing_private_dependency"
exit 2
Comment on lines +73 to +77

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove the unused private-dependency gate

For fork pull requests and other runs without repository secrets, this unconditional exit prevents the real Idris/RefC/Zig integration from running even though the checked proven-ffi.ipkg depends only on contrib, the subsequent build commands never reference the checked-out bridge directory, and docs/ffi-ci-build.adoc explicitly records that the unused private dependency was removed. Requiring LANGUAGE_BRIDGES_TOKEN therefore turns an otherwise self-contained build into a permanent failure for those contexts.

Useful? React with 👍 / 👎.

fi
echo "available=true" >> "$GITHUB_OUTPUT"
- name: Checkout language-bridges
if: steps.bridge-token.outputs.available == 'true'
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
repository: nextgen-languages/language-bridges
path: nextgen-languages/language-bridges
token: ${{ secrets.LANGUAGE_BRIDGES_TOKEN }}
persist-credentials: false
- name: Install Idris 2 dependencies
if: steps.bridge-token.outputs.available == 'true'
run: |
set -euo pipefail
sudo apt-get update
sudo apt-get install -y chezscheme libgmp-dev
- name: Cache Idris 2
if: steps.bridge-token.outputs.available == 'true'
id: cache-idris2
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: |
~/.idris2
~/idris2-${{ env.IDRIS2_VERSION }}
key: idris2-refc-${{ env.IDRIS2_VERSION }}-${{ runner.os }}
- name: Install Idris 2
if: steps.bridge-token.outputs.available == 'true' && steps.cache-idris2.outputs.cache-hit != 'true'
run: |
set -euo pipefail
git clone --depth 1 --branch v${{ env.IDRIS2_VERSION }} https://github.com/idris-lang/Idris2.git ~/idris2-${{ env.IDRIS2_VERSION }}
cd ~/idris2-${{ env.IDRIS2_VERSION }}
Comment on lines +107 to +108

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Set IDRIS2_VERSION before constructing the install command

When LANGUAGE_BRIDGES_TOKEN is available and the cache misses, this installation step interpolates env.IDRIS2_VERSION, but the checked workflow defines no such environment variable. GitHub therefore constructs the branch as v and the destination as ~/idris2-, preventing the integration job from provisioning Idris before it reaches the pinned compiler action.

Useful? React with 👍 / 👎.

make bootstrap SCHEME=chezscheme
make install
- name: Add Idris 2 to PATH
if: steps.bridge-token.outputs.available == 'true'
run: echo "$HOME/.idris2/bin" >> "$GITHUB_PATH"
- name: Setup Zig
uses: mlugg/setup-zig@e7d1537c378b83b8049f65dda471d87a2f7b2df2 # v1
with:
Expand All @@ -54,22 +126,24 @@ jobs:
set -euo pipefail
source build/refc/sdk.env
cd ffi/zig
zig build --summary all \
-Didris-refc="$REFC_OUTPUT_DIR" \
-Didris-refc-runtime="$IDRIS2_REFC_RUNTIME" \
-Didris-c-support="$IDRIS2_C_SUPPORT" \
-Didris-support-lib="$IDRIS2_SUPPORT_LIB" 2>&1 | tee ../../build/refc/zig-build.log
zig build test --summary all \
-Didris-refc="$REFC_OUTPUT_DIR" \
-Didris-refc-runtime="$IDRIS2_REFC_RUNTIME" \
-Didris-c-support="$IDRIS2_C_SUPPORT" \
-Didris-support-lib="$IDRIS2_SUPPORT_LIB" 2>&1 | tee ../../build/refc/zig-tests.log
test -s zig-out/lib/libproven.a
- name: Reject stale output and misleading compiler success
run: bash scripts/test-refc-staging.sh
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
if: always()
with:
name: full-refc-build-evidence
path: build/refc/
if-no-files-found: error
zig build \
-Didris-refc="$GITHUB_WORKSPACE/build/refc" \
-Didris-refc-runtime="$REFC_RUNTIME" \
-Didris-c-support="$C_SUPPORT" \
-Didris-support-lib="$SUPPORT_LIB"
Comment on lines +131 to +133

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the RefC SDK environment contract

In the checked idris-refc-zig job, the preceding script deletes build/refc/sdk.env and now only prints IDRIS2_REFC_RUNTIME, IDRIS2_C_SUPPORT, and IDRIS2_SUPPORT_LIB to stdout, while this step still sources that file and reads the unrelated aliases REFC_RUNTIME, C_SUPPORT, and SUPPORT_LIB. Even after the RefC builder's earlier failures are fixed, the step will either fail while sourcing the missing file or exit under set -u before either Zig command; persist the environment file and consume the names it actually defines.

Useful? React with 👍 / 👎.

zig build test \
-Didris-refc="$GITHUB_WORKSPACE/build/refc" \
-Didris-refc-runtime="$REFC_RUNTIME" \
-Didris-c-support="$C_SUPPORT" \
-Didris-support-lib="$SUPPORT_LIB"
ls -la zig-out/lib/libproven.*
- name: Verify the genuine built artifact exports every Rustler NIF symbol
if: steps.bridge-token.outputs.available == 'true'
run: |
set -euo pipefail
artifact="$GITHUB_WORKSPACE/ffi/zig/zig-out/lib/libproven.a"
if [ ! -f "$artifact" ]; then
echo "::error::Missing actual libproven.a, not a successful integration."
exit 1
fi
bash scripts/check-native-nif-exports.sh "$artifact"
80 changes: 80 additions & 0 deletions docs/ffi/NATIVE-NIF-ABI-CONTRACT.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: CC-BY-SA-4.0
// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell
= Native libproven / Rustler ABI boundary

This repository currently has a *broken consumer boundary*, not a missing
search directory alone. `bindings/elixir/native/proven_nif/src/lib.rs`
declares 66 `proven_*` C ABI functions. The current
`ffi/zig/src/main.zig` exports 17 `proven_*` functions and does not
define most of the required functions, such as `proven_math_div`.
The shared name `proven_init` also has incompatible return types:
Rust declares `i32` while Zig returns an optional `*Handle`.
These are source observations, not a verified inventory of any
generated Idris2 RefC C output.

== Actual Idris2 RefC package scope

On 2026-11-15 an isolated checkout ran `idris2 --build proven-ffi.ipkg`
and `idris2 --codegen refc --build proven-ffi.ipkg` using Idris2
0.8.0. Both compiled successfully. The package currently lists
`Proven.Core`, `Proven.SafeUrl.Parser`,
`Proven.FFI.SafeUrl` and `Proven.FFI.Main`; compilation also loads
the imported SafeUrl/Query modules. `Proven.FFI.Main` references
*SafeUrl only*. This package does not presently include an Idris2 FFI
Comment on lines +20 to +23

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include the retained header kernel in the documented scope

The reviewed proven-ffi.ipkg also lists Proven.SafeHeader.ByteKernel, and Proven.FFI.Main imports it and calls headerStep, so the statement that the package and entrypoint cover SafeUrl only is false for this commit. Because this section is presented as the measured boundary of the Idris-backed package, omitting the retained header kernel gives readers an inaccurate inventory of what the generated RefC translation unit contains.

Useful? React with 👍 / 👎.

implementation for the Rustler NIF's math, crypto, string and other
API families. A successfully generated `proven-ffi.c` is **not** a
complete 66-function Idris-backed ABI.

The existing `scripts/build-refc.sh` also previously scanned
`build/exec` and its parent `build` (double-counting the same
source), and could report success even when the compiler produced no
C. It now requires at least one *fresh* generated C source, deduplicates
the scan, and replaces stale staged sources. The five fake-compiler
controls in `tests/check-refc-staging.sh` exercise empty, stale,
fresh and failed generation, while an independent live Idris2/RefC
build has confirmed one generated source file. Neither fixture
testing nor one generated C source proves complete ABI parity.

== A mandatory precondition, not a substitute for proof

Run `bash scripts/check-native-nif-exports.sh /path/to/libproven.so`
*after* the authentic Idris2 -> RefC -> Zig library build.
For a static library, pass `libproven.a` instead.

The checker extracts required C symbols from the Rust `extern "C"` block
and confirms that the compiled library *defines* all of them. Missing
names cause exit 1; missing tools/inputs or unreadable artifacts cause
exit 2 (NOT RUN); only a complete symbol list gives exit 0.

The script expressly **does not verify ABI types, memory ownership,
verified Idris2 provenance, dynamic dependencies, or behavioural
semantics**. Its positive controls are fixture libraries, not
`libproven` evidence. Type/layout compatibility must additionally be
checked against an authoritative C header, with compiled calls and
negative fixtures, before declaring the full interface safe.
Actual runtime behaviour must be exercised from Elixir and Rust.

== Required upstream repairs

. Resolve the currently private `nextgen-languages/language-bridges`
dependency with correctly scoped credentials or a reviewed vendor pin.
. Produce genuine Idris2 RefC code, with pinned compiler/runtime inputs,
and include the required ABI implementation in the Zig linker.
. Agree whether the consumer links a static or shared `libproven`.
The Zig build currently emits a static target while Rust explicitly
requests `dylib=proven`.
. Repair all 66 function contracts, including `proven_init` return
type and correct ownership of returned buffers.
. Check exported symbols on *the exact artifact to be consumed*; run
typed calls against it and the real Elixir/Rustler integration.
. Publish immutable, attestable artifact provenance and a pinned,
reproducible consumer configuration. Never silently substitute
`build_standalone.zig`, which builds a narrower pure Zig ABI.

== Positive and negative gate controls

`bash tests/check-native-nif-exports.sh` runs six isolated cases:
a defined shared and static fixture, deliberately missing symbols,
missing input, an empty contract, and a corrupt binary. These tests
establish only that the name-presence gate fails closed; they do
not certify this repository's actual `libproven` ABI.
Loading
Loading