In the beginning there was fire

This commit is contained in:
Daniel Ziltener 2024-09-30 01:30:15 +02:00
parent f68de389b2
commit 96a6a1ecbe
Signed by: zilti
GPG key ID: B38976E82C9DAE42
8 changed files with 310 additions and 5 deletions

2
.envrc
View file

@ -1,3 +1,3 @@
use nix -p chicken chickenPackages_5.chickenEggs.apropos chickenPackages_5.chickenEggs.chicken-doc chickenPackages_5.chickenEggs.srfi-1 chickenPackages_5.chickenEggs.srfi-18 chickenPackages_5.chickenEggs.test-new-egg chickenPackages_5.chickenEggs.openssl chickenPackages_5.chickenEggs.test use nix # -p chicken chickenPackages_5.chickenEggs.apropos chickenPackages_5.chickenEggs.chicken-doc chickenPackages_5.chickenEggs.srfi-1 chickenPackages_5.chickenEggs.srfi-18 chickenPackages_5.chickenEggs.test-new-egg chickenPackages_5.chickenEggs.openssl chickenPackages_5.chickenEggs.test
export TEST_NEW_EGG_HENRIETTA_CACHE="$(which henrietta-cache)" export TEST_NEW_EGG_HENRIETTA_CACHE="$(which henrietta-cache)"
export TEST_NEW_EGG_SALMONELLA="$(which salmonella)" export TEST_NEW_EGG_SALMONELLA="$(which salmonella)"

126
nix/chicken.nix Normal file
View file

@ -0,0 +1,126 @@
{
pkgs,
lib,
stdenv,
fetchgit,
fetchurl,
makeWrapper,
darwin,
tcc-mob,
version ? "git",
testers
}:
let
platform = with stdenv;
if isDarwin then "macosx"
else if isCygwin then "cygwin"
else if (isFreeBSD || isOpenBSD) then "bsd"
else if isSunOS then "solaris"
else "linux"; # Should be a sane default
in
stdenv.mkDerivation (finalAttrs: {
pname = "chicken";
inherit version;
binaryVersion = 12;
srcs = [
(fetchgit {
url = "git://code.call-cc.org/chicken-core";
rev = "8c16ffb605a89d2f1580e01696d673e71fa1f6c4";
sha256 = "sha256-y7vFeglKJYyTyW91bvp0ZrcQF18S0SGCZ1rNCx36W4w=";
})
(fetchurl {
url = "https://code.call-cc.org/dev-snapshots/2024/07/01/chicken-6.0.0-bootstrap.tar.gz";
sha256 = "sha256-qkcyWzsaN9+HbMBolmv7zeaPrtbaCTGa9HoF2g/3//o=";
})
];
unpackPhase = ''
cp -r `echo $srcs | awk '{print $1}'`/* .
cp -r `echo $srcs | awk '{print $1}'`/.* .
chmod -R 777 .
mkdir -p boot/snapshot
cd boot
tar xzf `echo $srcs | awk '{print $2}'`
cd ..
echo ${version} > buildid
cd boot/chicken-6.0.0
case "${platform}" in
bsd)
mkcmd=gmake;;
*)
mkcmd=make;;
esac
export CC="${tcc-mob}/bin/tcc"
$mkcmd C_COMPILER=$CC PREFIX="$(pwd)"/../snapshot
$mkcmd C_COMPILER=$CC PREFIX="$(pwd)"/../snapshot install
cd ../..
./configure --chicken "$(pwd)"/boot/snapshot/bin/chicken --c-compiler "${tcc-mob}/bin/tcc"
$mkcmd boot-chicken
'';
# Disable two broken tests: "static link" and "linking tests"
postPatch = ''
sed -i tests/runtests.sh -e "/static link/,+4 { s/^/# / }"
sed -i tests/runtests.sh -e "/linking tests/,+11 { s/^/# / }"
'';
# -fno-strict-overflow is not a supported argument in clang
hardeningDisable = lib.optionals stdenv.cc.isClang [ "strictoverflow" ];
makeFlags = [
"PLATFORM=${platform}"
"PREFIX=$(out)"
"C_COMPILER=${tcc-mob}/bin/tcc"
"CXX_COMPILER=$(CXX)"
] ++ (lib.optionals stdenv.isDarwin [
"XCODE_TOOL_PATH=${darwin.binutils.bintools}/bin"
"LINKER_OPTIONS=-headerpad_max_install_names"
"POSTINSTALL_PROGRAM=install_name_tool"
]) ++ (lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"HOSTSYSTEM=${stdenv.hostPlatform.config}"
"TARGET_C_COMPILER=${tcc-mob}/bin/${stdenv.cc.targetPrefix}tcc"
"TARGET_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++"
]);
nativeBuildInputs = [
makeWrapper
pkgs.hostname
tcc-mob
] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
darwin.autoSignDarwinBinariesHook
];
configurePhase = ''
./configure --chicken ./chicken-boot --prefix $PREFIX --platform=$PLATFORM --c-compiler "${tcc-mob}/bin/tcc"
'';
doCheck = !stdenv.isDarwin;
postCheck = ''
./csi -R chicken.pathname -R chicken.platform \
-p "(assert (equal? \"${toString finalAttrs.binaryVersion}\" (pathname-file (car (repository-path)))))"
'';
passthru.tests.version = testers.testVersion {
package = finalAttrs.finalPackage;
command = "csi -version";
};
meta = {
homepage = "https://call-cc.org/";
license = lib.licenses.bsd3;
maintainers = with lib.maintainers; [ corngood nagy konst-aa ];
platforms = lib.platforms.unix;
description = "Portable compiler for the Scheme programming language";
longDescription = ''
CHICKEN is a compiler for the Scheme programming language.
CHICKEN produces portable and efficient C, supports almost all
of the R5RS Scheme language standard, and includes many
enhancements and extensions. CHICKEN runs on Linux, macOS,
Windows, and many Unix flavours.
'';
};
})

129
nix/tinycc.nix Normal file
View file

@ -0,0 +1,129 @@
{ lib
, copyPkgconfigItems
, fetchFromRepoOrCz
, makePkgconfigItem
, perl
, stdenv
, texinfo
, which
}:
stdenv.mkDerivation (finalAttrs: {
pname = "tcc-mob";
version = "0.9.29-unstable-2024-09-16";
src = fetchFromRepoOrCz {
repo = "tinycc";
rev = "b8b6a5fd7b4e8cab8e5a5d01064cf5bf2b5eed95";
hash = "sha256-jY0P2GErmo//YBaz6u4/jj/voOE3C2JaIDRmo0orXN8=";
};
outputs = [ "out" "info" "man" ];
nativeBuildInputs = [
copyPkgconfigItems
perl
texinfo
which
];
strictDeps = true;
pkgconfigItems = let
libtcc-pcitem = {
name = "libtcc";
inherit (finalAttrs) version;
cflags = [ "-I${libtcc-pcitem.variables.includedir}" ];
libs = [
"-L${libtcc-pcitem.variables.libdir}"
"-Wl,--rpath ${libtcc-pcitem.variables.libdir}"
"-ltcc"
];
variables = {
prefix = "${placeholder "out"}";
includedir = "${placeholder "dev"}/include";
libdir = "${placeholder "lib"}/lib";
};
description = "Tiny C compiler backend";
};
in [
(makePkgconfigItem libtcc-pcitem)
];
postPatch = ''
patchShebangs texi2pod.pl
'';
configureFlags = [
"--cc=$CC"
"--ar=$AR"
"--crtprefix=${lib.getLib stdenv.cc.libc}/lib"
"--sysincludepaths=${lib.getDev stdenv.cc.libc}/include:{B}/include"
"--libpaths=${lib.getLib stdenv.cc.libc}/lib"
# build cross compilers
"--enable-cross"
] ++ lib.optionals stdenv.hostPlatform.isMusl [
"--config-musl"
];
preConfigure = let
# To avoid "malformed 32-bit x.y.z" error on mac when using clang
versionIsClean = version:
builtins.match "^[0-9]\\.+[0-9]+\\.[0-9]+" version != null;
in ''
${
if stdenv.isDarwin && ! versionIsClean finalAttrs.version
then "echo 'not overwriting VERSION since it would upset ld'"
else "echo ${finalAttrs.version} > VERSION"
}
configureFlagsArray+=("--elfinterp=$(< $NIX_CC/nix-support/dynamic-linker)")
'';
env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.cc.isClang [
"-Wno-error=implicit-int"
"-Wno-error=int-conversion"
]);
# Test segfault for static build
doCheck = !stdenv.hostPlatform.isStatic;
checkTarget = "test";
# https://www.mail-archive.com/tinycc-devel@nongnu.org/msg10142.html
preCheck = lib.optionalString (stdenv.isDarwin && stdenv.isx86_64) ''
rm tests/tests2/{108,114}*
'';
meta = {
homepage = "https://repo.or.cz/tinycc.git";
description = "Small, fast, and embeddable C compiler and interpreter";
longDescription = ''
TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other C
compilers, it is meant to be self-sufficient: you do not need an external
assembler or linker because TCC does that for you.
TCC compiles so fast that even for big projects Makefiles may not be
necessary.
TCC not only supports ANSI C, but also most of the new ISO C99 standard
and many GNU C extensions.
TCC can also be used to make C scripts, i.e. pieces of C source that you
run as a Perl or Python script. Compilation is so fast that your script
will be as fast as if it was an executable.
TCC can also automatically generate memory and bound checks while allowing
all C pointers operations. TCC can do these checks even if non patched
libraries are used.
With libtcc, you can use TCC as a backend for dynamic code generation.
'';
license = with lib.licenses; [ lgpl21Only ];
mainProgram = "tcc";
maintainers = with lib.maintainers; [ joachifm AndersonTorres ];
platforms = lib.platforms.unix;
# https://www.mail-archive.com/tinycc-devel@nongnu.org/msg10199.html
broken = stdenv.isDarwin && stdenv.isAarch64;
};
})
# TODO: more multiple outputs
# TODO: self-compilation

View file

@ -1,5 +1,6 @@
(import (import
(scheme) (scheme)
(scheme case-lambda)
(srfi 1) (srfi 1)
(hermes)) (hermes))
@ -130,7 +131,7 @@
(define-syntax define-object/add-slots! (define-syntax define-object/add-slots!
(syntax-rules () (syntax-rules ()
((_ o) ((_ o)
(values)) (void))
((_ o ((method-name . method-args) body ...) ((_ o ((method-name . method-args) body ...)
slots ...) slots ...)
(begin (begin

View file

@ -3,7 +3,7 @@
(synopsis "The Prometheus Object System.") (synopsis "The Prometheus Object System.")
(category oop) (category oop)
(license "BSD") (license "BSD")
(version "1.0.0") (version "1.0.1")
(dependencies srfi-1) (dependencies srfi-1)
(test-dependencies test) (test-dependencies test)
(components (components

View file

@ -63,7 +63,7 @@ Test dependencies:
#+end_src #+end_src
#+begin_src fundamental :noweb yes :tangle .envrc :exports none #+begin_src fundamental :noweb yes :tangle .envrc :exports none
use nix -p <<dependencies-for-nix()>> use nix # -p <<dependencies-for-nix()>>
export TEST_NEW_EGG_HENRIETTA_CACHE="$(which henrietta-cache)" export TEST_NEW_EGG_HENRIETTA_CACHE="$(which henrietta-cache)"
export TEST_NEW_EGG_SALMONELLA="$(which salmonella)" export TEST_NEW_EGG_SALMONELLA="$(which salmonella)"
#+end_src #+end_src
@ -361,6 +361,7 @@ The messages record stores an association of message names and message handlers.
#+begin_src scheme :tangle prometheus-impl.scm :exports none #+begin_src scheme :tangle prometheus-impl.scm :exports none
(import (import
(scheme) (scheme)
(scheme case-lambda)
(srfi 1) (srfi 1)
(hermes)) (hermes))
#+end_src #+end_src
@ -964,6 +965,9 @@ Daniel Ziltener, Jorgen Schaefer
** Version History ** Version History
#+name: version-history-6
| 1.0.1 | Port to Chicken 6 |
#+name: version-history #+name: version-history
| 1.0.0 | Port to Chicken 5 | | 1.0.0 | Port to Chicken 5 |
@ -974,10 +978,17 @@ Daniel Ziltener, Jorgen Schaefer
#+end_src #+end_src
#+name: latest-release #+name: latest-release
#+begin_src emacs-lisp :var vers=version-history :exports none :results code #+begin_src emacs-lisp :var vers=version-history-6 :exports none :results code
(caar vers) (caar vers)
#+end_src #+end_src
#+begin_src scheme :noweb yes :tangle prometheus.release-info.6 :exports none
;; -*- Scheme -*-
(repo git "https://forgejo.lyrion.ch/Chicken/prometheus.git")
(uri targz "https://forgejo.lyrion.ch/Chicken/prometheus/archive/{egg-release}.tar.gz")
<<gen-releases(vers=version-history-6)>>
#+end_src
#+begin_src scheme :noweb yes :tangle prometheus.release-info :exports none #+begin_src scheme :noweb yes :tangle prometheus.release-info :exports none
;; -*- Scheme -*- ;; -*- Scheme -*-
(repo git "https://forgejo.lyrion.ch/Chicken/prometheus.git") (repo git "https://forgejo.lyrion.ch/Chicken/prometheus.git")

View file

@ -0,0 +1,4 @@
;; -*- Scheme -*-
(repo git "https://forgejo.lyrion.ch/Chicken/prometheus.git")
(uri targz "https://forgejo.lyrion.ch/Chicken/prometheus/archive/{egg-release}.tar.gz")
(release "1.0.1") ;; Port to Chicken 6

34
shell.nix Normal file
View file

@ -0,0 +1,34 @@
with import <nixpkgs> {
overlays = [
(final: prev: {
tcc-mob = final.callPackage ./nix/tinycc.nix { stdenv = final.gcc13Stdenv; };
chicken = final.callPackage ./nix/chicken.nix {
stdenv = final.gcc13Stdenv;
version = "6.0.0-8c16ffb";
};
})
];
};
mkShell {
packages = with pkgs; [
tcc-mob
chicken
]
# ++ (with pkgs.chickenPackages_5.chickenEggs; [
# apropos
# chicken-doc
# srfi-1
# srfi-18
# lsp-server
# srfi-152
# ])
;
shellHook = ''
export CC="${pkgs.tcc-mob}/bin/tcc"
export CHICKEN_INSTALL_PREFIX="$HOME/.chicken"
export CHICKEN_INSTALL_REPOSITORY="$HOME/.chicken/eggs"
export CHICKEN_REPOSITORY_PATH="${pkgs.chicken}/lib/chicken/12:$HOME/.chicken/eggs"
export PATH="$PATH:$CHICKEN_PREFIX"
export CHICKEN_INSTALL_PREFIX="${pkgs.chicken}"
'';
}