Improvements

This commit is contained in:
retropikzel 2025-10-09 10:45:14 +03:00
parent c47420b706
commit 5ba6b6c0b4
16 changed files with 680 additions and 782 deletions

View File

@ -1,32 +1,15 @@
FROM debian:trixie-slim AS build
RUN apt-get update && apt-get install -y gcc make git chicken-bin
RUN chicken-install r7rs
FROM debian:trixie-slim
RUN apt-get update && apt-get install -y gcc make git libffi-dev
WORKDIR /build
RUN git clone https://github.com/ashinn/chibi-scheme.git --depth=1 chibi
WORKDIR /build/chibi
RUN make DESTDIR=/opt/compile-r7rs
RUN make DESTDIR=/opt/compile-r7rs install
RUN mkdir -p /opt/compile-r7rs/bin
RUN echo "#!/bin/sh" > /opt/compile-r7rs/bin/snow-chibi
RUN echo "PATH=/opt/compile-r7rs/usr/local/bin:${PATH} LD_LIBRARY_PATH=/opt/compile-r7rs/usr/local/lib:/opt/compile-r7rs/usr/local/lib/chibi CHIBI_MODULE_PATH=/opt/compile-r7rs/usr/local/share/chibi:/opt/compile-r7rs/usr/local/lib/chibi /opt/compile-r7rs/usr/local/bin/chibi-scheme -I /opt/compile-r7rs/usr/local/share/chibi -I /opt/compile-r7rs/usr/local/lib/chibi -I /opt/compile/snow -mchibi.snow.commands -mchibi.snow.interface -mchibi.snow.package -mchibi.snow.utils /opt/compile-r7rs/usr/local/bin/snow-chibi.scm \"\$@\"" >> /opt/compile-r7rs/bin/snow-chibi
RUN chmod +x /opt/compile-r7rs/bin/snow-chibi
ENV PATH=/opt/compile-r7rs/bin:${PATH}
WORKDIR /build
RUN snow-chibi install --impls=chicken --always-yes "(foreign c)"
RUN snow-chibi install --impls=chicken --always-yes "(srfi 170)"
RUN make
RUN make install
RUN mkdir -p ${HOME}/.snow && echo "()" > ${HOME}/.snow/config.scm
RUN snow-chibi install --impls=chibi --always-yes "(foreign c)"
RUN snow-chibi install --impls=chibi --always-yes "(srfi 170)"
COPY Makefile .
COPY compile-r7rs.scm .
COPY libs libs
RUN make build-chicken
RUN make PREFIX=/opt/compile-r7rs install
FROM debian:trixie-slim
RUN apt-get update && apt-get install -y \
build-essential libffi-dev docker.io make cmake
COPY --from=build /opt/compile-r7rs /opt/compile-r7rs
ENV PATH=/opt/compile-r7rs/bin:${PATH}
RUN mkdir -p ${HOME}/.snow && echo "()" > ${HOME}/.snow/config.scm
RUN make build-chibi
RUN make install

View File

@ -1,24 +0,0 @@
FROM alpine AS build
RUN apk add make gcc chicken git
RUN chicken-install r7rs
WORKDIR /build
RUN git clone https://github.com/ashinn/chibi-scheme.git --depth=1 chibi
WORKDIR /build/chibi
RUN make
RUN make install
WORKDIR /build
RUN mkdir -p ${HOME}/.snow && echo "()" > ${HOME}/.snow/config.scm
RUN snow-chibi install --always-yes --impls=chicken "(foreign c)"
RUN snow-chibi install --always-yes --impls=chicken "(srfi 170)"
COPY Makefile .
COPY compile-r7rs.scm .
COPY libs ./libs
RUN make PREFIX=/opt/compile-r7rs build-chicken
RUN make PREFIX=/opt/compile-r7rs install
FROM alpine
COPY --from=build /opt/compile-r7rs /opt/compile-r7rs
ENV PATH=/opt/compile-r7rs/bin:${PATH}

View File

@ -1,21 +1,23 @@
ARG SCHEME=chibi
ARG IMAGE=chibi:head
FROM debian:trixie AS build
RUN apt-get update && apt-get install -y \
--download-only \
--no-install-recommends \
--no-install-suggests \
build-essential \
make \
libffi-dev \
ca-certificates \
git \
cmark
FROM debian:bookworm AS cache
RUN apt-get update && apt-get install -y gcc make git
WORKDIR /cache
RUN git clone https://github.com/ashinn/chibi-scheme.git --depth=1
WORKDIR /cache/chibi-scheme
RUN make
ARG SCHEME=chibi
ENV COMPILE_R7RS=${SCHEME}
ARG IMAGE=chibi:head
FROM schemers/${IMAGE}
COPY --from=build /var/cache/apt/archives /debs
RUN dpkg -i /debs/*.deb
COPY --from=local-build-compile-r7rs /opt/compile-r7rs /opt/compile-r7rs
ENV PATH=/opt/compile-r7rs/bin:${PATH}:/opt/compile-r7rs/snow-chibi/bin
RUN apt-get update && apt-get install -y make gcc libffi-dev unzip
COPY --from=cache /cache /cache
WORKDIR /cache/chibi-scheme
RUN make install
WORKDIR /
RUN snow-chibi install --always-yes "(foreign c)"
RUN snow-chibi install --always-yes "(srfi 170)"
COPY Makefile .
COPY libs libs/
COPY compile-r7rs.scm .
RUN make build-chibi && make install

74
Jenkinsfile vendored
View File

@ -1,32 +1,28 @@
pipeline {
agent {
label 'docker-x86_64'
docker {
label 'docker-x86_64'
image 'schemers/chibi:head'
args '--user=root --privileged -v /var/run/docker.sock:/var/run/docker.sock'
}
}
options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
timeout(time: 1, unit: 'HOURS')
}
parameters {
booleanParam(name: 'DOCKER', defaultValue: false, description: 'Build and push docker image')
}
stages {
stage('Build') {
stage('Build and install') {
steps {
sh "docker build -f Dockerfile --tag=local-build-compile-r7rs ."
}
}
stage('Warm up cache') {
steps {
sh "docker build -f Dockerfile.test --build-arg IMAGE=chibi:head --build-arg SCHEME=chibi --tag=compile-r7rs-test-chibi ."
sh "apt-get install -y make"
sh "make build-chibi"
sh "make install"
}
}
/*
stage('Test R6RS implementations') {
steps {
script {
@ -72,54 +68,6 @@ pipeline {
}
}
}
stage('Docker build/login/push x84-64') {
agent {
label 'linux-x86_64'
}
when {
allOf {
branch 'main'
expression {
return params.DOCKER
}
}
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh 'docker build . --tag=retropikzel1/compile-r7rs'
sh 'docker login -u ${DOCKER_HUB_USERNAME} -p ${DOCKER_HUB_TOKEN}'
sh 'docker push retropikzel1/compile-r7rs'
}
}
}
stage('Docker build/login/push arm') {
agent {
label 'linux-arm'
}
when {
allOf {
branch 'main'
expression {
return params.DOCKER
}
}
}
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh 'docker build . --tag=retropikzel1/compile-r7rs'
sh 'docker login -u ${DOCKER_HUB_USERNAME} -p ${DOCKER_HUB_TOKEN}'
sh 'docker push retropikzel1/compile-r7rs'
}
}
}
stage('Docker logout') {
steps {
sh 'docker logout'
}
}
*/
}
}

View File

@ -6,12 +6,15 @@ DOCKERIMG=${SCHEME}:head
ifeq "${SCHEME}" "chicken"
DOCKERIMG="chicken:5"
endif
STATIC_LIBS=libs.util.a libs.library-util.a libs.data.a libs.srfi-64-util.a
all:
echo "HERE!"
build-chibi:
echo "#!/bin/sh" > compile-r7rs
echo "chibi-scheme -A ${PREFIX}/lib/compile-r7rs ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm \"\$$@\"" >> compile-r7rs
chmod +x compile-r7rs
build-chicken:
csc -R r7rs -X r7rs -static -c -J -unit libs.util -o libs.util.o libs/util.sld
@ -32,14 +35,17 @@ build-chicken:
build-gauche:
echo "#!/bin/sh" > compile-r7rs
echo "gosh -r -I ${PREFIX}/lib/compile-r7rs -I ${PREFIX}/lib/compile-r7rs/libs ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm \"\$$@\"" >> compile-r7rs
chmod +x compile-r7rs
build-guile:
echo "#!/bin/sh" > compile-r7rs
echo "guile --r7rs --auto-compile -I -q -L ${PREFIX}/lib/compile-r7rs ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm \"\$$@\" 2> /dev/null" >> compile-r7rs
chmod +x compile-r7rs
build-kawa:
echo "#!/bin/sh" > compile-r7rs
echo "kawa -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 -Dkawa.import.path=/usr/local/share/kawa/lib/*.sld:${PREFIX}/lib/compile-r7rs/*.sld --r7rs ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm \"\$$@\" 2> /dev/null" >> compile-r7rs
chmod +x compile-r7rs
#build-racket:
#echo "#!/bin/sh" > compile-r7rs
@ -48,24 +54,12 @@ build-kawa:
build-sagittarius:
echo "#!/bin/sh" > compile-r7rs
echo "sash -A ${PREFIX}/lib/compile-r7rs ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm \"\$$@\"" >> compile-r7rs
chmod +x compile-r7rs
build-stklos:
echo "#!/bin/sh" > compile-r7rs
echo "stklos -I ${PREFIX}/lib/compile-r7rs ${PREFIX}/lib/compile-r7rs/compile-r7rs.scm \"\$$@\"" >> compile-r7rs
docker-images: build-docker-image-debian build-docker-image-alpine
docker-image-debian:
docker build . -f Dockerfile --tag=retropikzel1/compile-r7rs:latest
docker-image-debian-push:
docker push retropikzel1/compile-r7rs:latest
docker-image-alpine:
docker build . -f Dockerfile.alpine --tag=retropikzel1/compile-r7rs:alpine-latest
docker-image-alpine-push:
docker push retropikzel1/compile-r7rs:alpine-latest
chmod +x compile-r7rs
install:
mkdir -p ${PREFIX}/bin
@ -81,39 +75,26 @@ uninstall:
test-r6rs:
rm -rf ${R6RSTMP}
mkdir -p ${R6RSTMP}
mkdir -p ${R6RSTMP}/libs
mkdir -p ${R6RSTMP}/libs/foo
printf "#!r6rs\n(library (foo bar) (export baz) (import (rnrs)) (define baz (lambda () (display \"Test successfull\") (newline))))" > ${R6RSTMP}/libs/foo/bar.sls
printf "#!r6rs\n(import (rnrs) (foo bar)) (baz)" > ${R6RSTMP}/main.sps
cp -r r6rs-testfiles/* ${R6RSTMP}/
cd ${R6RSTMP} && COMPILE_R7RS=${SCHEME} compile-r7rs -I ./libs -o main main.sps
-cd ${R6RSTMP} && ./main > compile-r7rs-test-result.txt 2>&1
@grep "Test successfull" ${R6RSTMP}/compile-r7rs-test-result.txt || (echo "Test failed, output: " && cat ${R6RSTMP}/compile-r7rs-test-result.txt && exit 1)
cd ${R6RSTMP} && ./main 1 2 3 > test-result.txt
@grep "Test successfull (\"1\" \"2\" \"3\")" ${R6RSTMP}/test-result.txt || (echo "Test failed, output: " && cat ${R6RSTMP}/test-result.txt && exit 1)
test-r6rs-docker: build-local-docker
test-r6rs-docker:
docker build -f Dockerfile.test --build-arg IMAGE=${DOCKERIMG} --build-arg SCHEME=${SCHEME} --tag=compile-r7rs-test-${SCHEME} .
docker run -v "${PWD}":/workdir -w /workdir -t compile-r7rs-test-${SCHEME} sh -c "make && make install && make SCHEME=${SCHEME} test-r6rs"
docker run -v "${PWD}":/workdir -w /workdir -t compile-r7rs-test-${SCHEME} sh -c "make SCHEME=${SCHEME} test-r6rs"
test-r7rs:
rm -rf ${R7RSTMP}
mkdir -p ${R7RSTMP}
mkdir -p ${R7RSTMP}/libs
mkdir -p ${R7RSTMP}/libs/foo
mkdir -p ${R7RSTMP}/libs/hello
echo "(import (scheme base) (foo bar) (hello world) (other hellolib)) (baz) (hello-world) (over-9000)" > ${R7RSTMP}/main.scm
echo "(define baz (lambda () (display \"Test successfull\") (newline)))" > ${R7RSTMP}/libs/foo/bar.scm
echo "(define-library (foo bar) (import (scheme base) (scheme write) (hello world)) (export baz) (include \"bar.scm\"))" > ${R7RSTMP}/libs/foo/bar.sld
echo "(define hello-world (lambda () (+ 1 1)))" > ${R7RSTMP}/libs/hello/world.scm
echo "(define-library (hello world) (import (scheme base) (scheme write)) (export hello-world) (include \"world.scm\"))" > ${R7RSTMP}/libs/hello/world.sld
mkdir -p ${R7RSTMP}/libs/other
echo "(define over-9000 (lambda () (+ 1 1)))" > ${R7RSTMP}/libs/other/hellolib.scm
echo "(define-library (other hellolib) (import (scheme base) (scheme write)) (export over-9000) (include \"hellolib.scm\"))" > ${R7RSTMP}/libs/other/hellolib.sld
cp -r r7rs-testfiles/* ${R7RSTMP}/
cd ${R7RSTMP} && COMPILE_R7RS=${SCHEME} compile-r7rs -I ./libs -o main main.scm
-cd ${R7RSTMP} && ./main > compile-r7rs-test-result.txt 2>&1
@grep "Test successfull" ${R7RSTMP}/compile-r7rs-test-result.txt || (echo "Test failed, output: " && cat ${R7RSTMP}/compile-r7rs-test-result.txt && exit 1)
-cd ${R7RSTMP} && ./main 1 2 3 > test-result.txt 2>&1
@grep "Test successfull (\"1\" \"2\" \"3\")" ${R7RSTMP}/test-result.txt || (echo "Test failed, output: " && cat ${R7RSTMP}/test-result.txt && exit 1)
test-r7rs-docker: build-local-docker
test-r7rs-docker:
docker build -f Dockerfile.test --build-arg IMAGE=${DOCKERIMG} --build-arg SCHEME=${SCHEME} --tag=compile-r7rs-test-${SCHEME} .
docker run -v "${PWD}":/workdir -w /workdir -t compile-r7rs-test-${SCHEME} sh -c "make && make install && make SCHEME=${SCHEME} test-r7rs"
docker run -it -v "${PWD}":/workdir -w /workdir -t compile-r7rs-test-${SCHEME} sh -c "make SCHEME=${SCHEME} test-r7rs"
clean:
rm -rf test-r7rs
@ -125,6 +106,7 @@ clean:
find . -name "*.link" -delete
find . -name "*.meta" -delete
find . -name "*.import.*" -delete
rm -rf libs.library-util.c
rm -rf dist
rm -rf deps

View File

@ -151,13 +151,13 @@
(define scheme-type (cdr (assoc 'type (cdr (assoc scheme data)))))
(define scheme-command
(string-append (apply (cdr (assoc 'command (cdr (assoc scheme data))))
(list (if input-file input-file "")
(if output-file output-file "")
prepend-directories
append-directories
library-files
r6rs?))))
(apply (cdr (assoc 'command (cdr (assoc scheme data))))
(list (if input-file input-file "")
(if output-file output-file "")
prepend-directories
append-directories
library-files
r6rs?)))
(define scheme-library-command
(lambda (library-file)
@ -198,16 +198,18 @@
(display "Compiling library ")
(display file)
(newline)
(display "With command ")
(display library-command)
(newline)
(display "Exit code ")
(let ((output (c-system (string->c-utf8 library-command))))
(when (not (= output 0))
(error "Problem compiling libraries, exiting" output))
(display output))
(newline)
(newline)))
(for-each
(lambda (command)
(display "Running ")
(write command)
(newline)
(display "Exit code ")
(let ((exit-code (c-system (string->c-utf8 command))))
(display exit-code)
(newline)
(when (not (= exit-code 0))
(exit exit-code))))
library-command)))
library-files))
(else
(display "Implementation has no library build command, skipping library compilation.")
@ -217,32 +219,33 @@
(when (and (equal? scheme-type 'interpreter) input-file)
(when (and output-file (file-exists? output-file))
(delete-file output-file))
(let ((shebang-line (string-append
(cond ((string=? compilation-target "unix")
"#!/usr/bin/env -S ")
((string=? compilation-target "windows")
(string-append
"@echo off"
(string #\newline)
"start")))
scheme-command))
(scheme-program (slurp input-file)))
(display "Creating startup script ")
(display output-file)
(newline)
(display "Containing command ")
(display scheme-command)
(display "Starting with ")
(display shebang-line)
(newline)
(with-output-to-file
(if (string=? compilation-target "windows")
(string-append output-file ".bat")
output-file)
(lambda ()
(cond ((string=? compilation-target "unix")
(display "#!/bin/sh")
(newline))
((string=? compilation-target "windows")
(display "@echo off")
(newline)
(display "start")))
(display scheme-command)
(cond ((string=? compilation-target "unix")
(display " \"")
(display "$@")
(display "\"")))
(display shebang-line)
(newline)
(display scheme-program)
(newline)))
(cond ((string=? compilation-target "unix")
(c-system (string->c-utf8 (string-append "chmod +x " output-file))))))
(cond ((string=? compilation-target "unix")
(c-system (string->c-utf8 (string-append "chmod +x " output-file)))))))
(when (and (equal? scheme-type 'compiler) input-file)
(when (and output-file (file-exists? output-file))
@ -250,10 +253,17 @@
(display "Compiling file ")
(display input-file)
(newline)
(display "With command ")
(display scheme-command)
(newline)
(display "Exit code ")
(display (c-system (string->c-utf8 scheme-command)))
(for-each
(lambda (command)
(display "Running ")
(write command)
(newline)
(display "Exit code ")
(let ((exit-code (c-system (string->c-utf8 command))))
(display exit-code)
(newline)
(when (not (= exit-code 0))
(exit exit-code))))
scheme-command)
(newline))

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,2 @@
#!r6rs
(library (foo bar) (export baz) (import (rnrs)) (define baz (lambda () (display "Test successfull "))))

6
r6rs-testfiles/main.sps Normal file
View File

@ -0,0 +1,6 @@
#!r6rs
(import (rnrs)
(rnrs programs)
(foo bar))
(baz)
(write (list-tail (command-line) 1))

View File

@ -0,0 +1 @@
(define baz (lambda () (display "Test successfull ")))

View File

@ -0,0 +1 @@
(define-library (foo bar) (import (scheme base) (scheme write) (hello world)) (export baz) (include "bar.scm"))

View File

@ -0,0 +1 @@
(define hello-world (lambda () (+ 1 1)))

View File

@ -0,0 +1 @@
(define-library (hello world) (import (scheme base) (scheme write)) (export hello-world) (include "world.scm"))

View File

@ -0,0 +1 @@
(define over-9000 (lambda () (+ 1 1)))

View File

@ -0,0 +1 @@
(define-library (other hellolib) (import (scheme base) (scheme write)) (export over-9000) (include "hellolib.scm"))

23
r7rs-testfiles/main.scm Normal file
View File

@ -0,0 +1,23 @@
(import (scheme base)
(scheme write)
(scheme process-context)
(foo bar)
(hello world)
(other hellolib))
(baz)
(hello-world)
(define l (list "1" "2" "3"))
(cond-expand
;; Meevax gives too much args
;; For this test for now this is okay
(meevax (when (> (length (command-line)) 3) (write l)))
;; mit-scheme gives too much args
;; For this test for now this is okay
(mit (when (> (length (command-line)) 3) (write l)))
;; tr7 gives too much args
;; For this test for now this is okay
(tr7 (when (> (length (command-line)) 3) (write l)))
(else (write (list-tail (command-line) 1))))
(over-9000)