• Stars
    star
    136
  • Rank 267,670 (Top 6 %)
  • Language
    Common Lisp
  • License
    MIT License
  • Created over 5 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Common Lisp .Net Core Interop
I've got a bike, you can ride it if you like
It's got a basket, a bell that rings
And things to make it look good
I'd give it to you if I could, but I borrowed it

-- Pink Floyd

Bike reinvents two wheels

  • First of all, it is RDNZL reborn

  • This time, on .Net Core, without a line of C++ code, and fully cross-platform

Now you have the batteries included! Which are of the size of Battersea Power Station.

CircleCI

TL;DR

This library implements cross-platform Common Lisp interface to .Net Core platform, using lisp compatibility layers.

(use-package :bike)

(named-readtables:in-readtable bike-syntax)

(import-assembly 'System.Runtime.InteropServices.RuntimeInformation)

(use-namespace 'System)
(use-namespace 'System.Runtime.InteropServices)

(defun hello ()
  (let* ((os [:RuntimeInformation %OSDescription])
         (delegate (new '(Action :string)
                        (lambda (who)
                          (format t "Hello ~a!~%You are running .Net Core~% inside ~a ~a~% on ~a"
                                  who
                                  (lisp-implementation-type)
                                  (lisp-implementation-version)
                                  os))))
         (user [:Environment %UserName]))
    [delegate Invoke user]))

(hello)

;; ==>

;; Hello lovesan!
;; You are running .Net Core
;;  inside SBCL 1.5.3
;;  on Linux 4.15.0-1041-aws #43-Ubuntu SMP Thu Jun 6 13:39:11 UTC 2019

Installation

The most basic way to install the library at this moment would be to use quicklisp:

(ql:quickload :bike)

Alternatively, you can drop the contents of the repository into ~/quicklisp/local-projects/bike directory.

The library, once loaded, searches for .Net Core runtime and for BikeInterop.dll library in several places, like in the executable directory.

In case of the library is unable to locate .Net Core in one of the predefined places, it then asks dotnet command to list available runtimes and picks up latest one.

The interop .Net library(BikeInterop.dll), should be unavailable, is being built, again, by utilizing the dotnet command.

To build the library, you would, of course, need .Net Core SDK installed. But running the code in production should only require .Net Core runtime installed and the built interop binary nearby.

The library handles image restore, by utilizing uiop. It searches for CoreCLR and interop layer again, then reloads cached types, and properly handles all the state.

Given this, you can deploy dumped images to other machines.

(defun hello () (bike:invoke 'System.Console 'WriteLine "Hello, World!"))
(setf uiop:*image-entry-point* #'hello)
(uiop:dump-image "hello.exe" :executable t)

;; ./hello.exe
;; ==> Hello, World!

Known Issues

Task.Result and other things which block .Net code

Do not use this if you pass Lisp callbacks to .Net code - this may cause deadlocks.

SBCL

SBCL is the main development and testing platform.

Windows

The library seems to work well on SBCL/Windows, the runtimes and garbage collectors seem to coexist peacefully. SBCL callbacks can even be utilized by .Net System.Threading.Tasks

There were some issues with exceptions in the past, but those were resolved.

The reason for those issues was described in my (D.I.) SBCL patch that had been applied in 2019.

Basically, on x86-64 Windows, SBCL uses VEH, and its handler had been catching all the exceptions before .Net Core handlers even had a chance to look at their ones. This, next, sometimes led to a situation where SBCL disallowed .Net runtime to enter into the correct state, which led to the corruption of both runtimes and process crashes.

Seems like it has been resolved. The latest patch from Luís Oliveira greatly enhanced SBCL exception handling.

Linux

Early SBCL versions(namely pre 1.5.4.13-b656602a3) were frequently crashing into LDB with a cryptic message of blockables unblocked if .Net Core runtime was present in a lisp process.

The reason for this is that SBCL and .Net Core stomp on each other signals, in a kind of a wrong way.

Seems that it is not only a case of .Net Core.

Thankfully, Stas Boukarev(stassats) implemented a workaround in the latest SBCL.

We still have to understand what may that workaround do to .Net Core runtime, but at least, it solves a problem of unavoidable and frequent crashes.

On overall, this need to be debugged out further. Maybe we would ask for help someone from .Net Core team.

UPD 2019-07-13: CoreFX(the .Net Core stdlib) also establishes signals for handling System.Diagnostics.Process classes and Console Ctrl handlers. We let it handle processes, because it can handle that perfectly(that means, including processes started by lisp, e.g. using uiop:run-program), but revert the SIGINT handler for lisp one.

MacOS X

Testers are welcome.

TODO

  • Documentation and tests are always good

  • Add more examples which utilize third-party assemblies, NuGet, or something like that

  • dotnet command interface

  • NuGet interface

  • Fancy async/await syntax

  • MacOS X testing

  • Implement some cache for parsed type definitions

  • Expose DEFKNOW-alike API to the user

  • Investigate CoreCLR interop on Linux. Fix SBCL crashes on Windows with NullReferenceException.

  • Optimize invocation cache (maybe write some hash functions instead of using sxhash etc)

  • Write compiler macros for API and type resolution

  • etc.

More Repositories

1

doors

MS Windows API from Common Lisp perspective
Common Lisp
32
star
2

virgil

An extensible and high level FFI
Common Lisp
18
star
3

clave

Common Lisp Audio Video Engine
Common Lisp
18
star
4

Microlisp

Common Lisp
17
star
5

CLR

Common Lisp Runtime
Common Lisp
12
star
6

Reactivity

Reactive GUI framework for Common Lisp
Common Lisp
10
star
7

neural-flow

A simple dataflow library for Common Lisp
Common Lisp
9
star
8

LDX

An attempt to bring DirectX into Common Lisp
Common Lisp
7
star
9

trivial-bit-streams

Flexible buffered bit streams
Common Lisp
7
star
10

Reef

Reef scene with realistic water. Direct3D 11, HLSL Shader Model 4.0.
C++
5
star
11

D3DWorkshop

2D/3D graphics mini-framework built on top of Microsoft Direct3D and Direct2D.
C++
5
star
12

MyActiveX

MyActiveX is a simple example of ATL-based OLE control.
C++
5
star
13

Organizer

Simple task organizer, an example of WPF MVVM application.
C#
4
star
14

Prototype

Prototype-based object system for Common Lisp implemented by means of CLOS MOP
Common Lisp
4
star
15

ByteShop

Simple ASP.NET MVC application
JavaScript
3
star
16

ConditionSystem

An implementation of Common Lisp Condition System in C#
C#
3
star
17

vue2-typescript-netcore-starter

Vue.js 2 + Typescript 2.9 + .Net Core 2.1 + Webpack 4 + Bootstrap-vue starter template
JavaScript
3
star
18

SLXI

SL cross interpreter
Common Lisp
3
star
19

RabbitDemo

RabbitMQ demos for .Net Core
C#
2
star
20

SimpleAudioPlayer

Simple audio player library for windows.
Common Lisp
2
star
21

dotnet-core-sdk-common-lisp-docker

Docker files for lisp implementations being bundled with .Net Core SDK
Dockerfile
2
star
22

CommonBlocks

Common algorithms & data structures
C#
1
star
23

ContactSwarm

Simple REST HTTP service for storing contacts.
C#
1
star
24

D3DU

Simple wrapper library for modern Direct3D API.
C++
1
star
25

circleci-101

CircleCI 101
Common Lisp
1
star
26

lvsn-utils

Yet another Common Lisp utility library
Common Lisp
1
star
27

SpecialVM

Special [Olympics] VM is a virtual 32 bit load/store RISC processor with some periphery.
C
1
star
28

x86_64-w64-cross-mingw32-docker

GCC cross-compiler for MinGW environment - Docker files
Shell
1
star
29

todomvc-scalajs

Scala.js implementation of TodoMVC
Scala
1
star
30

SilverlightClock

Simple Silverlight(v4) application - an interactive clock
C#
1
star
31

pastebin.com-api

pastebin.com api for common lisp
Common Lisp
1
star
32

erlman

Simple erlang documentation viewer
C#
1
star
33

libmonitor

Native monitor pattern implementation
Common Lisp
1
star
34

WinDial

Simple library for establishing Windows' network connections by name.
C
1
star
35

.emacs.d

Personal Emacs configuration files
Common Lisp
1
star
36

aws-ci-cd-101

AWS CI/CD 101
C#
1
star