1
0
Fork
You've already forked foreign-c
0
forked from foreign-c/foreign-c
(foreign c) is a C foreign function interface (FFI) library for R6RS and R7RS Schemes. It is portable in the sense that it supports multiple implementations.
  • Scheme 49.1%
  • C 44.3%
  • Tree-sitter Query 5.9%
  • Makefile 0.7%
2026年06月16日 06:56:34 +02:00
foreign Fix Kawa u64 handling 2026年05月29日 09:32:14 +03:00
tests Clean up tests 2026年05月14日 12:17:54 +03:00
.gitignore switch-to-test-r7rs ( #36 ) 2026年04月03日 11:24:51 +02:00
COPYING Add license 2025年07月20日 06:33:58 +03:00
Dockerfile.jenkins Fix jenkins tests 2026年05月14日 12:59:19 +03:00
Jenkinsfile Add webhooks ( #37 ) 2026年06月16日 06:56:34 +02:00
LICENSE Fix tests, add pffi-os-name 2024年07月31日 21:14:38 +03:00
Makefile Fix Kawa u64 handling 2026年05月29日 09:32:14 +03:00
README.md Fixes for Chicken 6 2026年05月14日 12:08:05 +03:00
REFERENCE.md types ( #34 ) 2026年03月12日 05:43:48 +01:00

(foreign c) is a C foreign function interface (FFI) library for R6RS and R7RS Schemes

Documentation

See REFERENCE.md

Supported implementations

  • Chez => 10.0.0
    • R6RS
  • Chibi > 0.11
    • R7RS
  • Chicken >= 6.0.0
    • R7RS
  • Guile >= 3
    • R6RS
    • R7RS
      • Has include bug, might not work on all situations
  • Ikarus >= 0.0.4-rc1+
    • R6RS
  • Ironscheme
    • R6RS
  • Kawa >= 3.11 and Java >= 22
    • R7RS
    • Needs arguments to enable FFI
      • -J--add-exports=java.base/jdk.internal.foreign.abi=ALL-UNNAMED
      • -J--add-exports=java.base/jdk.internal.foreign.layout=ALL-UNNAMED
      • -J--add-exports=java.base/jdk.internal.foreign=ALL-UNNAMED
      • -J--enable-native-access=ALL-UNNAMED
      • -J--enable-preview
    • All needed arguments on one line for copy pasting
      • -J--add-exports=java.base/jdk.internal.foreign.abi=ALL-UNNAMED -J--add-exports=java.base/jdk.internal.foreign.layout=ALL-UNNAMED -J--add-exports=java.base/jdk.internal.foreign=ALL-UNNAMED -J--enable-native-access=ALL-UNNAMED -J--enable-preview
    • So that snow-chibi installed library is found
      • -Dkawa.import.path=/usr/local/share/kawa
      • -Dkawa.import.path=/usr/local/share/kawa/lib
  • Racket >= 8.16 [cs]
    • R6RS
      • Unable to run tests as Rackets SRFI-64 implementation does not work
    • R7RS
  • Sagittarius >= 0.9.13
    • R6RS
    • R7RS
  • STklos > 2.10
    • R7RS
    • At the time only 2.10 is out so build from git
  • Ypsilon >= 2.08
    • R6RS
    • R7RS

Work in progress

  • Cyclone
    • R7RS
  • Gambit
    • R7RS
  • Gauche
    • R7RS
    • Waiting for Gauche to support dynamic FFI
  • Gerbil
    • R7RS
  • Mit-Scheme
    • R7RS
  • Mosh
    • R6RS
    • R7RS
  • Larceny
    • R6RS
    • R7RS

Dependencies

  • Chibi
    • libffi

Installation

R6RS - Akku

In your project directory run:

akku install "(foreign c)"

R6RS - Manual

Dowloand the latest release or clone from git and copy directory named
"foreign" into your project, then run:
 akku install

R7RS - Snow-fort

https://snow-fort.org/

snow-chibi --impls=IMPLEMENTATION install "(foreign c)"

You can test that library is found by your implementation like this:

cp tests/hello.scm /tmp/hello.scm
cd /tmp
IMPLEMENTATION hello.scm

R7RS Manual

Manual system wide installation requires snow-chibi.

Either download the latest release from https://git.sr.ht/~retropikzel/foreign-c/refs or git clone, tag, and copy the foreign directory to your library directory.

Example for how to install for Gauche:

apt-get install libffi-dev
git clone https://git.sr.ht/~retropikzel/foreign-c
cd foreign-c
make SCHEME=gauche
make SCHEME=gauche install

Adding support for new implementation

See from any foreign/c/SCHEME-primitives.sld what needs to be exported. Make the library files foreign/c/YOURSCHEME-primitives.sld foreign/c/YOURSCHEME-primitives.scm. Import it in cond expand in foreign/c.sld.

Run tests with:

make SCHEME=YOURSCHEME test-r6rs

or

make SCHEME=YOURSCHEME test-r6rs