Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Conda package #65

Merged
merged 1 commit into from
Dec 16, 2024
Merged

Add Conda package #65

merged 1 commit into from
Dec 16, 2024

Conversation

kartik-s
Copy link
Contributor

@kartik-s kartik-s commented Sep 13, 2024

Closes #66.

Summary

This PR adds a Conda recipe for building a package called sbcl-librarian containing the following artifacts:

  • lib/libsbcl_librarian.so
  • lib/sbcl_librarian.core
  • include/sbcl_librarian.h
  • include/sbcl_librarian_err.h
  • the sbcl_librarian Python package with wrappers for libsbcl_librarian.so

The CI workflows on all platforms are updated so that they:

  1. Build SBCL + libsbcl from source
  2. Build the sbcl-librarian Conda package and install it into an environment
  3. Build calc.dll as a FASL-packed DLL against libsbcl_librarian.dll in that environment
  4. Run the example C and Python programs against calc.dll

Artifacts

libsbcl_librarian.so

Built via the CMakeLists.txt file in lib/, which lists its sources and dependent libraries:

add_library(sbcl_librarian SHARED sbcl_librarian.c sbcl_librarian.h sbcl_librarian_err.h entry_point.c)
target_link_libraries(sbcl_librarian PUBLIC sbcl)

sbcl_librarian.c and sbcl_librarian.h are auto-generated bindings for this library as defined in generate-bindings.lisp:

(define-aggregate-library sbcl-librarian (:function-linkage "LIBSBCL_LIBRARIAN_API")
  diagnostics
  environment
  errors
  handles
  loader)

These bindings contain the functions that FASL-packed DLLs call to load themselves into the running Lisp image.

Additionally, we link in entry_point.c which defines the do_initialize_lisp function that gets called automatically by the system when libsbcl_librarian.so is loaded into a process. This function does the following:

  1. Get the path to sbcl_librarian.core, which is installed in the same directory as the currently executing DLL.
  2. Call SBCL's initialize_lisp function with the the above core file to initialize the Lisp runtime.
  3. Wire up SBCL's lossage handler so that fatal Lisp errors are caught and handled.

sbcl_librarian.core

Built via generate-bindings.lisp. Loads SWANK, the sbcl-librarian library, sets up some signal-handling hacks, generates C and Python bindings, then saves the core.

include/sbcl_librarian.h

Generated via generate-bindings.lisp. Declares functions and values contained in libsbcl_librarian.so

sbcl_librarian_err.h

Declares fatal error handling jmp_bufs and flags, as well as the global error enum that gets returned by all wrapper functions.

Python package

Contains several modules that wrap the raw Python bindings:

  • debug.py wraps functions for enabling/disabling the debugger + backtraces, memory + handle reporting, doing GC, and profiling
  • errors.py matches the error enum defined in sbcl_librarian.h so that errors returned by C functions can be translated into Python exceptions
  • fixtures.py has a test fixture that checks for handle leaks
  • version.py reads the package version from VERSION.txt
  • wrapper.py defines the LispObject class for wrapping handles with release logic, exception types corresponding to the errors enums defined in sbcl_librarian_err.h, and functions for wrapping raw binding functions with logic to deal with handles and exceptions

@kartik-s kartik-s changed the base branch from main to fasl-libs September 23, 2024 23:59
@kartik-s kartik-s marked this pull request as ready for review December 13, 2024 17:52
Copy link
Member

@jbouwman jbouwman left a comment

Choose a reason for hiding this comment

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

Approved, review comments mainly pertain to nonsubstantive documentation of platform quirks

examples/libcalc/example.py Show resolved Hide resolved
lib/entry_point.c Outdated Show resolved Hide resolved
patches/win32-dll-build.patch Outdated Show resolved Hide resolved
lib/sbcl_librarian_err.h Show resolved Hide resolved
src/errors.lisp Show resolved Hide resolved
@kartik-s kartik-s requested a review from macrologist December 13, 2024 22:36
Copy link

@eliaslfox eliaslfox left a comment

Choose a reason for hiding this comment

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

🚀

@kartik-s kartik-s mentioned this pull request Dec 16, 2024
@kartik-s kartik-s force-pushed the conda-recipe-fasl branch 2 times, most recently from 1f276e3 to 12f3040 Compare December 16, 2024 17:50
@kartik-s kartik-s merged commit a40c0e7 into fasl-libs Dec 16, 2024
4 checks passed
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.

4 participants