From 2746a56f593437b8b7877b8d27f7ae98795f6849 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 18 Jul 2022 15:11:04 -0500 Subject: [PATCH 1/6] tinyscheme: add the libraries to the outputs --- pkgs/development/interpreters/tinyscheme/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/development/interpreters/tinyscheme/default.nix b/pkgs/development/interpreters/tinyscheme/default.nix index 5c7ed9d27ead..0787c2c33311 100644 --- a/pkgs/development/interpreters/tinyscheme/default.nix +++ b/pkgs/development/interpreters/tinyscheme/default.nix @@ -16,6 +16,7 @@ stdenv.mkDerivation rec { installPhase = '' mkdir -p $out/bin $out/lib cp init.scm $out/lib + cp libtinyscheme* $out/lib cp scheme $out/bin/tinyscheme ''; From 698cedfa3c219cf8b8e16077aa215b7d15a2ce2d Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 18 Jul 2022 15:12:40 -0500 Subject: [PATCH 2/6] tinyscheme: don't require the gcc stdenv --- .../02-use-toolchain-env-vars.patch | 26 +++++++++++++++++++ .../interpreters/tinyscheme/default.nix | 12 +++++++-- pkgs/top-level/all-packages.nix | 4 +-- 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 pkgs/development/interpreters/tinyscheme/02-use-toolchain-env-vars.patch diff --git a/pkgs/development/interpreters/tinyscheme/02-use-toolchain-env-vars.patch b/pkgs/development/interpreters/tinyscheme/02-use-toolchain-env-vars.patch new file mode 100644 index 000000000000..f23ad8d02ef5 --- /dev/null +++ b/pkgs/development/interpreters/tinyscheme/02-use-toolchain-env-vars.patch @@ -0,0 +1,26 @@ +diff --git a/makefile b/makefile +index aeb2fcd..4c111a1 100644 +--- a/makefile ++++ b/makefile +@@ -18,7 +18,7 @@ + #AR= echo + + # Unix, generally +-CC = gcc -fpic -pedantic ++CC := $(CC) -fpic -pedantic + DEBUG=-g -Wall -Wno-char-subscripts -O + Osuf=o + SOsuf=so +@@ -27,10 +27,10 @@ EXE_EXT= + LIBPREFIX=lib + OUT = -o $@ + RM= -rm -f +-AR= ar crs ++AR := $(AR) crs + + # Linux +-LD = gcc ++LD := $(CC) + LDFLAGS = -shared + DEBUG=-g -Wno-char-subscripts -O + SYS_LIBS= -ldl -lm diff --git a/pkgs/development/interpreters/tinyscheme/default.nix b/pkgs/development/interpreters/tinyscheme/default.nix index 0787c2c33311..96a0f355ec25 100644 --- a/pkgs/development/interpreters/tinyscheme/default.nix +++ b/pkgs/development/interpreters/tinyscheme/default.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchurl }: +{ lib, stdenv, fetchurl, dos2unix }: stdenv.mkDerivation rec { pname = "tinyscheme"; @@ -9,7 +9,15 @@ stdenv.mkDerivation rec { sha256 = "sha256-F7Cxv/0i89SdWDPiKhILM5A50s/aC0bW/FHdLwG0B60="; }; - patchPhase = '' + nativeBuildInputs = [ dos2unix ]; + + prePatch = "dos2unix makefile"; + patches = [ + # We want to have the makefile pick up $CC, etc. so that we don't have + # to unnecessarily tie this package to the GCC stdenv. + ./02-use-toolchain-env-vars.patch + ]; + postPatch = '' substituteInPlace scheme.c --replace "init.scm" "$out/lib/init.scm" ''; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6c8af61fe2f2..ef79fc2b521b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -14346,9 +14346,7 @@ with pkgs; wasi-libc = pkgsCross.wasi32.wasilibc; }; - tinyscheme = callPackage ../development/interpreters/tinyscheme { - stdenv = gccStdenv; - }; + tinyscheme = callPackage ../development/interpreters/tinyscheme { }; bupc = callPackage ../development/compilers/bupc { }; From 17fb7518ffc2e9a13ec6c1ecec2be1d2cac9d0a6 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 18 Jul 2022 15:13:05 -0500 Subject: [PATCH 3/6] tinyscheme: add the changelog link --- pkgs/development/interpreters/tinyscheme/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/development/interpreters/tinyscheme/default.nix b/pkgs/development/interpreters/tinyscheme/default.nix index 96a0f355ec25..38b4cbe1ba87 100644 --- a/pkgs/development/interpreters/tinyscheme/default.nix +++ b/pkgs/development/interpreters/tinyscheme/default.nix @@ -36,6 +36,7 @@ stdenv.mkDerivation rec { subset of R5RS as was possible without getting very large and complicated. ''; homepage = "http://tinyscheme.sourceforge.net/"; + changelog = "http://tinyscheme.sourceforge.net/CHANGES"; license = licenses.bsdOriginal; maintainers = [ maintainers.ebzzry ]; platforms = platforms.unix; From 8f0ec8269639500be31b2bae37d515388f12b4d8 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 18 Jul 2022 15:13:20 -0500 Subject: [PATCH 4/6] tinyscheme: fix the build on macOS --- .../tinyscheme/01-remove-macOS-main.patch | 24 +++++++++++++++++++ .../tinyscheme/03-macOS-SOsuf.patch | 13 ++++++++++ .../interpreters/tinyscheme/default.nix | 12 ++++++++-- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 pkgs/development/interpreters/tinyscheme/01-remove-macOS-main.patch create mode 100644 pkgs/development/interpreters/tinyscheme/03-macOS-SOsuf.patch diff --git a/pkgs/development/interpreters/tinyscheme/01-remove-macOS-main.patch b/pkgs/development/interpreters/tinyscheme/01-remove-macOS-main.patch new file mode 100644 index 000000000000..3fedec98f383 --- /dev/null +++ b/pkgs/development/interpreters/tinyscheme/01-remove-macOS-main.patch @@ -0,0 +1,24 @@ +diff --git a/scheme.c b/scheme.c +index 6186ef0..5a43592 100644 +--- a/scheme.c ++++ b/scheme.c +@@ -4949,19 +4949,7 @@ pointer scheme_eval(scheme *sc, pointer obj) + + #if STANDALONE + +-#if defined(__APPLE__) && !defined (OSX) +-int main() +-{ +- extern MacTS_main(int argc, char **argv); +- char** argv; +- int argc = ccommand(&argv); +- MacTS_main(argc,argv); +- return 0; +-} +-int MacTS_main(int argc, char **argv) { +-#else + int main(int argc, char **argv) { +-#endif + scheme sc; + FILE *fin; + char *file_name=InitFile; diff --git a/pkgs/development/interpreters/tinyscheme/03-macOS-SOsuf.patch b/pkgs/development/interpreters/tinyscheme/03-macOS-SOsuf.patch new file mode 100644 index 000000000000..479ff369b80b --- /dev/null +++ b/pkgs/development/interpreters/tinyscheme/03-macOS-SOsuf.patch @@ -0,0 +1,13 @@ +diff --git a/makefile b/makefile +index 4c111a1..8d9e02e 100644 +--- a/makefile ++++ b/makefile +@@ -21,7 +21,7 @@ + CC := $(CC) -fpic -pedantic + DEBUG=-g -Wall -Wno-char-subscripts -O + Osuf=o +-SOsuf=so ++SOsuf=dylib + LIBsuf=a + EXE_EXT= + LIBPREFIX=lib diff --git a/pkgs/development/interpreters/tinyscheme/default.nix b/pkgs/development/interpreters/tinyscheme/default.nix index 38b4cbe1ba87..7d064432a732 100644 --- a/pkgs/development/interpreters/tinyscheme/default.nix +++ b/pkgs/development/interpreters/tinyscheme/default.nix @@ -13,9 +13,19 @@ stdenv.mkDerivation rec { prePatch = "dos2unix makefile"; patches = [ + # The alternate macOS main makes use of `ccommand` which seems to be + # `MetroWerks CodeWarrier` specific: + # https://ptgmedia.pearsoncmg.com/imprint_downloads/informit/downloads/9780201703535/macfix.html + # + # In any case, this is not needed to build on macOS. + ./01-remove-macOS-main.patch + # We want to have the makefile pick up $CC, etc. so that we don't have # to unnecessarily tie this package to the GCC stdenv. ./02-use-toolchain-env-vars.patch + ] ++ lib.optionals stdenv.targetPlatform.isDarwin [ + # On macOS the library suffix is .dylib: + ./03-macOS-SOsuf.patch ]; postPatch = '' substituteInPlace scheme.c --replace "init.scm" "$out/lib/init.scm" @@ -29,7 +39,6 @@ stdenv.mkDerivation rec { ''; meta = with lib; { - broken = stdenv.isDarwin; description = "Lightweight Scheme implementation"; longDescription = '' TinyScheme is a lightweight Scheme interpreter that implements as large a @@ -40,6 +49,5 @@ stdenv.mkDerivation rec { license = licenses.bsdOriginal; maintainers = [ maintainers.ebzzry ]; platforms = platforms.unix; - badPlatforms = [ "aarch64-darwin" ]; }; } From 4c958b12006870b8821410637bd471af052afda3 Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 18 Jul 2022 16:44:50 -0500 Subject: [PATCH 5/6] tinyscheme: add some tests --- .../interpreters/tinyscheme/default.nix | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/pkgs/development/interpreters/tinyscheme/default.nix b/pkgs/development/interpreters/tinyscheme/default.nix index 7d064432a732..1bdc2ef82f23 100644 --- a/pkgs/development/interpreters/tinyscheme/default.nix +++ b/pkgs/development/interpreters/tinyscheme/default.nix @@ -1,4 +1,10 @@ -{ lib, stdenv, fetchurl, dos2unix }: +{ lib +, stdenv +, fetchurl +, dos2unix +, runCommand +, tinyscheme +}: stdenv.mkDerivation rec { pname = "tinyscheme"; @@ -38,6 +44,28 @@ stdenv.mkDerivation rec { cp scheme $out/bin/tinyscheme ''; + passthru.tests = { + # Checks that the program can run and exit: + simple = runCommand "${pname}-simple-test" {} '' + ${tinyscheme}/bin/tinyscheme <<<"(quit 0)" + echo "success" > $out + ''; + fileIo = runCommand "${pname}-file-io-test" {} '' + ${tinyscheme}/bin/tinyscheme < $out || : + [[ "$(cat $out)" =~ ^Usage: ]] + ''; + }; + meta = with lib; { description = "Lightweight Scheme implementation"; longDescription = '' From 12257dbc8296f8f0813d8846262d4ee00dfba69a Mon Sep 17 00:00:00 2001 From: Rahul Butani Date: Mon, 18 Jul 2022 22:27:23 -0500 Subject: [PATCH 6/6] tinyscheme: set `mainProgram` --- pkgs/development/interpreters/tinyscheme/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/development/interpreters/tinyscheme/default.nix b/pkgs/development/interpreters/tinyscheme/default.nix index 1bdc2ef82f23..000b0534a104 100644 --- a/pkgs/development/interpreters/tinyscheme/default.nix +++ b/pkgs/development/interpreters/tinyscheme/default.nix @@ -75,6 +75,7 @@ stdenv.mkDerivation rec { homepage = "http://tinyscheme.sourceforge.net/"; changelog = "http://tinyscheme.sourceforge.net/CHANGES"; license = licenses.bsdOriginal; + mainProgram = pname; maintainers = [ maintainers.ebzzry ]; platforms = platforms.unix; };