Skip to content

SBCL librarian runtime - #58

Draft
BatmanAoD wants to merge 13 commits into
mainfrom
sbcl-librarian-runtime
Draft

SBCL librarian runtime#58
BatmanAoD wants to merge 13 commits into
mainfrom
sbcl-librarian-runtime

Conversation

@BatmanAoD

Copy link
Copy Markdown

Update sbcl-librarian and adopt its new conventions

BatmanAoD and others added 13 commits November 27, 2023 10:18
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Moves off the 2023 sbcl-librarian pin, which also unblocks modern SBCL. libquil is
now the generated C bindings only; the Lisp image lives in a core loaded by the
libsbcl_librarian runtime, whose constructor initializes Lisp when it is loaded.
The explicit init(core) call is gone, as is libquil's hand-rolled error handling.

libquil keeps shipping a core rather than the FASL bundles that
CREATE-FASL-LIBRARY-CMAKE-PROJECT produces. FASL bundles are re-loaded on every
startup, re-running load-time code, and cl-quil resolves stdgates.quil through
ASDF:SYSTEM-RELATIVE-PATHNAME at load time -- so a FASL build only runs where
quilc's source tree sits at the path recorded when it was built. A core evaluates
that once, at build time.

build-image.lisp emits three things from one image: libquil's bindings, the
runtime's bindings, and the core exporting both sets of callables. The Makefile
builds the runtime too, so plain 'make' still yields a usable artifact.

Errors move to the runtime's get_error_message/lisp_err_t. libquil redefines
default-error-map so ordinary bad input reports as LISP_ERR_FAILURE rather than an
internal bug, handling T rather than CL:ERROR because cl-quil signals conditions
that are not subtypes of ERROR.

REARCHITECTURE.md records the decisions. Needs three sbcl-librarian fixes, on its
fix-secondary-system-bundles branch.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- build.yml builds SBCL $SBCL_VERSION (2.6.7) with --with-sb-linkable-runtime,
  replacing the sbcl-2.2.4 build that failed in make-host-1 ('undefined variable:
  SB-VM::END') because a current host SBCL cannot cross-compile a 2022 target.
  sbcl-librarian's repo and ref are workflow inputs, since libquil needs three
  fixes that are not upstream yet.
- The artifact is now the bindings library, its header and the whole runtime
  directory: libsbcl_librarian, libquil.core, libsbcl.so and the runtime headers.
  install.sh and the release archives follow, with libquil.core installed beside
  libsbcl_librarian because the runtime finds its core relative to itself.
- The examples drop their init(core) calls and -pagezero_size, link the runtime,
  and use get_error_message/lisp_err_t.
- The redundant quickload steps before make are gone; build-image.lisp does it.

Verified by simulating package -> zip -> install and running the libquil-sys
suite against the installed layout.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
magicl looks for Homebrew's reference LAPACK first and otherwise falls back to a
bare liblapack.dylib, which on macOS resolves to Accelerate's. Neither works: the
reference build returns incorrect eigenvectors on arm64, failing with 'Could not
find diagonalizer for matrix ... after 16 attempts', and Accelerate's LAPACK
predates 3.3 so routines quilc calls are missing, failing with 'The alien function
zuncsd_ is undefined'. OpenBLAS is correct and complete.

Loading it first means its symbols are the ones that resolve, and because SBCL
records loaded shared objects in the core and reloads them at startup, the choice
is baked into the artifact instead of depending on what the loader happens to find.

Verified against a stock magicl checkout with Homebrew's lapack installed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Cutting a prerelease from a branch produced a tag pointing at the wrong code.
knope 0.10/0.11 create the GitHub release against the default branch, so the
version bump landed on the branch while the tag landed on main -- and the publish
job, which checks out whatever that tag resolves to, then tried to republish main's
already-released version:

    error: crate libquil-sys@0.4.2 already exists on crates.io index

Adopt the setup rigetti-pyo3 arrived at (36a1850, 9b5235c, 3505971):

- knope 0.23, which tags the ref being released and takes --prerelease-label, so
  the separate prerelease workflow in knope.toml is no longer needed;
- the ref decides what gets cut: main releases, anything else prereleases;
- check out ${{ github.ref }} so a release acts on the dispatched branch;
- pass the token to the Release step through GITHUB_TOKEN, which is how it
  authenticates;
- dry-run the release on pull requests, so a broken config is visible before it is
  dispatched.

The publish job now checks out the release tag explicitly, so it always publishes
exactly what was tagged rather than whatever the target commitish points at.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… root

Two problems with installing a release:

magicl loads BLAS and LAPACK at runtime under their unversioned names, libblas.so and
liblapack.so, so a missing one does not surface at install or link time: it surfaces much
later, in the middle of compiling a program. Check for them before anything is
downloaded, and name the ones that are missing. The unversioned names are also why a
runtime-only package is not enough -- Debian's libblas3 provides libblas.so.3 and no
unversioned symlink -- so say that in the requirements, which is the part users get
wrong. Drop libz from the requirements while there: nothing in the release artifacts
refers to it.

Container images commonly run as root with no sudo installed, where every sudo call here
fails with "sudo: command not found" even though nothing needs elevating. That is how CI
installs libquil, so the installer was unusable there. Resolve sudo once: empty when
already root, sudo when available, and a clear error when neither.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant