Adding Haiku support

This commit is contained in:
retropikzel 2025-06-22 17:48:23 +03:00
parent f037d22c40
commit 0af0378c0e
8 changed files with 58 additions and 37 deletions

View File

@ -27,6 +27,15 @@ package:
clean-package:
rm -rf *.tgz
test-java: tmp/test/libtest.o tmp/test/libtest.so tmp/test/libtest.a
mkdir -p tmp/test
cp kawa.jar tmp/test/
cp -r foreign tmp/test/
cp tests/*.scm tmp/test/
cp tests/c-include/libtest.h tmp/test/
cd tmp/test \
&& ${JAVA_HOME}/bin/java --add-exports java.base/jdk.internal.foreign.abi=ALL-UNNAMED --add-exports java.base/jdk.internal.foreign.layout=ALL-UNNAMED --add-exports java.base/jdk.internal.foreign=ALL-UNNAMED --enable-native-access=ALL-UNNAMED --enable-preview -jar kawa.jar --r7rs --full-tailcalls -Dkawa.import.path=*.sld:./snow/*.sld:./snow/retropikzel/*.sld ${TESTNAME}.scm
test-compile-r7rs: tmp/test/libtest.o tmp/test/libtest.so tmp/test/libtest.a
make ${COMPILE_R7RS}
cp -r foreign tmp/test/

View File

@ -210,17 +210,13 @@ Options:
Example:
(cond-expand
(windows (define-c-library libc-stdlib
'("stdlib.h")
"ucrtbase"
'((additional-versions ("0" "6"))
(additiona-paths (".")))))
(else (define-c-library libc-stdlib
(define-c-library libc
(list "stdlib.h")
"c"
'((additional-versions ("0" "6"))
(additiona-paths ("."))))))
'((additional-versions ("" "0" "6"))
(additional-paths ("."))))
Note that libc is exported by this library so you might not need to load it.
#### Notes
@ -245,9 +241,9 @@ Defines a new foreign function to be used from Scheme code.
Example:
(cond-expand
(windows (define-c-library libc-stdlib '("stdlib.h") "ucrtbase" '()))
(else (define-c-library libc-stdlib '("stdlib.h") "c" '("6"))))
(define-c-procedure c-puts libc-stdlib 'puts 'int '(pointer))
(windows (define-c-library libc '("stdlib.h") "ucrtbase" '()))
(else (define-c-library libc '("stdlib.h") "c" '("6"))))
(define-c-procedure c-puts libc 'puts 'int '(pointer))
(c-puts "Message brought to you by foreign-c!")
#### Notes
@ -591,6 +587,24 @@ UTF-8 encoding of the given string.
Returns a newly allocated (unless empty) string whose character sequence is
encoded by the given c-bytevector.
### Utilities
**libc**
Since the library uses C standard internally, and that is most likely library
to have different name on different operating systems. For example libc.so on
Linux, ucrtbase.dll on windows and libroot.so on Haiku. It makes sense to
export it, saving the users the trouble of figuring out which named shared
library they should load.
See foreign/c/libc.scm to see which headers are included and what shared
libraries are loaded.
Example:
(define-c-procedure c-puts libc 'puts 'int '(pointer))
(c-puts "Message brought to you by foreign-c!")
### Environment variables
Setting environment variables like this on Windows works for this library:

View File

@ -193,6 +193,9 @@
bytevector->c-bytevector
c-bytevector->bytevector
;;;; Utilities
libc
;; TODO endianness
native-endianness
make-c-bytevector
@ -317,12 +320,14 @@
(include "c/primitives/ypsilon.scm")))
(cond-expand
(chicken-6 (include-relative "c/main.scm")
(include-relative "c/libc.scm")
(include-relative "c/c-bytevectors.scm")
(include-relative "c/pointer.scm")
;(include-relative "c/array.scm")
;(include-relative "c/struct.scm")
)
(else (include "c/main.scm")
(include "c/libc.scm")
;(include "c/struct.scm")
(include "c/c-bytevectors.scm")
(include "c/pointer.scm")

13
foreign/c/libc.scm Normal file
View File

@ -0,0 +1,13 @@
(cond-expand
(windows (define-c-library libc
'("stdio.h" "string.h")
"ucrtbase"
'((additional-versions ("0" "6")))))
(else
(define c-library "c")
(when (get-environment-variable "BE_HOST_CPU")
(set! c-library "root"))
(define-c-library libc
'("stdio.h" "string.h")
c-library
'((additional-versions ("" "0" "6" "7"))))))

View File

@ -103,7 +103,9 @@
"/usr/lib"
"/usr/lib64"
; NetBSD
"/usr/pkg/lib")))))
"/usr/pkg/lib"
; Haiku
"/boot/system/lib")))))
(auto-load-versions (list ""))
(paths (append auto-load-paths additional-paths))
(versions (append additional-versions auto-load-versions))

View File

@ -1,13 +1,3 @@
(cond-expand
(windows (define-c-library libc
'("stdlib.h" "string.h")
"ucrtbase"
'((additional-versions ("0" "6")))))
(else (define-c-library libc
'("stdlib.h" "string.h")
"c"
'((additional-versions ("0" "6"))))))
(define-c-procedure c-calloc libc 'calloc 'pointer '(int int))
(define-c-procedure c-memset-address->pointer libc 'memset 'pointer '(uint64 uint8 int))
(define-c-procedure c-memset-pointer->address libc 'memset 'uint64 '(pointer uint8 int))

BIN
kawa.jar Normal file

Binary file not shown.

View File

@ -214,18 +214,6 @@
(print-header 'define-c-library)
(cond-expand
(windows (define-c-library libc
'("stdio.h" "string.h")
"ucrtbase"
'((additional-versions ("0" "6")))))
(else (define-c-library libc
'("stdio.h" "string.h")
"c"
'((additional-versions ("0" "6"))))))
(debug libc)
(define-c-library c-testlib
'("libtest.h")
"test"