turingplus: init at 6.2.1

This commit is contained in:
Adam Thompson-Sharpe
2025-09-25 18:38:26 -04:00
parent b8384ad90d
commit 44a381cc22
3 changed files with 181 additions and 0 deletions
+93
View File
@@ -0,0 +1,93 @@
{
lib,
stdenv,
fetchzip,
autoPatchelfHook,
makeWrapper,
coreutils,
libredirect,
}:
let
sources = {
"x86_64-linux" = {
url = "https://github.com/CordyJ/Open-TuringPlus/releases/download/v6.2.1/opentplus-62-linux64.tar.gz";
sha256 = "sha256-FoOlOcRWpStg4aerjr+FmcXXnwYftrqG1j4iZJ+4AzE=";
};
"x86_64-darwin" = {
url = "https://github.com/CordyJ/Open-TuringPlus/releases/download/v6.2.1/opentplus-62-macos64.tar.gz";
sha256 = "sha256-8o1hIA74JPqZyjWfg4leC99z1+YMVhwFGME5qBf/BP0=";
};
};
redirects = [
# Turing+ library/includes
"/usr/local/lib/tplus=${placeholder "out"}/lib"
"/local/lib/tplus=${placeholder "out"}/lib"
"/usr/local/include/tplus=${placeholder "out"}/include"
"/local/include/tplus=${placeholder "out"}/include"
# Turing+ binaries
"/usr/local/bin=${placeholder "out"}/bin"
# Other
"/bin/rm=${coreutils}/bin/rm"
];
in
stdenv.mkDerivation (finalAttrs: {
pname = "turingplus-bootstrap";
version = "6.2.1";
src = fetchzip sources."${stdenv.hostPlatform.system}";
nativeBuildInputs = [
makeWrapper
]
++ lib.optionals stdenv.hostPlatform.isLinux [
autoPatchelfHook
];
buildInputs = [ stdenv.cc.cc.lib ];
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p $out/{bin,lib,include}
cp bin/* $out/bin/
cp lib/* $out/lib/
cp -r include/* $out/include/
runHook postInstall
'';
# Wrap package and redirect FHS reads to the derivation output
postInstall =
let
preloadVar = if stdenv.hostPlatform.isDarwin then "DYLD_INSERT_LIBRARIES" else "LD_PRELOAD";
preloadLib = "${libredirect}/lib/libredirect" + stdenv.hostPlatform.extensions.sharedLibrary;
in
''
wrapProgram $out/bin/tpc \
--set ${preloadVar} ${preloadLib} \
--set NIX_REDIRECTS ${builtins.concatStringsSep ":" redirects} \
--set NIX_ENFORCE_PURITY 0
wrapProgram $out/bin/tssl \
--set ${preloadVar} ${preloadLib} \
--set NIX_REDIRECTS ${builtins.concatStringsSep ":" redirects} \
--set NIX_ENFORCE_PURITY 0
'';
meta = with lib; {
description = "Extended version of the Turing programming language with concurrency and systems programming features";
mainProgram = "tpc";
platforms = [
"x86_64-linux"
"x86_64-darwin"
];
homepage = "https://github.com/CordyJ/Open-TuringPlus";
downloadPage = "https://github.com/CordyJ/Open-TuringPlus/releases";
changelog = "https://github.com/CordyJ/Open-TuringPlus/releases/tag/v${finalAttrs.version}";
license = licenses.mit;
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
maintainers = with maintainers; [ MysteryBlokHed ];
};
})
+75
View File
@@ -0,0 +1,75 @@
{
lib,
stdenv,
callPackage,
fetchFromGitHub,
bootstrap ? callPackage ./bootstrap.nix { },
}:
stdenv.mkDerivation (finalAttrs: {
pname = "turingplus";
version = "6.2.1";
src = fetchFromGitHub {
owner = "CordyJ";
repo = "Open-TuringPlus";
tag = "v${finalAttrs.version}";
hash = "sha256-jiMbSuNg2o9fNCPNoLpyAdMCxgMVBiDjRhC0HgKwmqk=";
};
nativeBuildInputs = [ bootstrap ];
# Using -std=gnu89 to prevent errors that occur with default args
env.NIX_CFLAGS_COMPILE = "-std=gnu89 -Wno-int-conversion";
# Patch required to fix compilation errors when certain C input files are used with tpc
patches = [ ./use-gnu89.patch ];
postPatch = ''
# Replace hardcoded paths in source
find src -type f -exec sed -i \
-e "s#/usr/local/lib/tplus#$out/lib#g" \
-e "s#/local/lib/tplus#$out/lib#g" \
-e "s#/usr/local/include/tplus#$out/include#g" \
-e "s#/local/include/tplus#$out/include#g" \
-e "s#/usr/local/bin#$out/bin#g" \
-e "s#/bin/rm#rm#g" \
{} +
# Use proper C compiler for target
substituteInPlace src/cmd/lib/* \
--replace-fail 'cc ' '${stdenv.cc}/bin/cc '
'';
buildFlags = [
"INCLUDE_DIR=${bootstrap}/include"
"TPC=${bootstrap}/bin/tpc"
];
checkFlags = [ "-C test" ];
checkTarget = "all";
installPhase = ''
runHook preInstall
mkdir -p $out/{bin,lib,include}
cp bin/* $out/bin/
cp lib/* $out/lib/
cp -r include/* $out/include/
runHook postInstall
'';
meta = with lib; {
description = "Extended version of the Turing programming language with concurrency and systems programming features";
mainProgram = "tpc";
platforms = [
"x86_64-linux"
"x86_64-darwin"
];
homepage = "https://github.com/CordyJ/Open-TuringPlus";
downloadPage = "https://github.com/CordyJ/Open-TuringPlus/releases";
changelog = "https://github.com/CordyJ/Open-TuringPlus/releases/tag/v${finalAttrs.version}";
license = licenses.mit;
maintainers = with maintainers; [ MysteryBlokHed ];
};
})
@@ -0,0 +1,13 @@
--- a/src/cmd/tpc.t
+++ b/src/cmd/tpc.t
@@ -1342,6 +1342,10 @@ procedure CompileC (cFileName : string, var s : string, var status : int)
i += 1
end if
+ % Use C standard that allows C++-style comments
+ tArgs(i) := "-std=gnu89"
+ i += 1
+
% ignore warnings from C compiler
tArgs(i) := "-w"
i += 1