From 44a381cc22f0c8f8ffa0e287e13f980e1969417e Mon Sep 17 00:00:00 2001 From: Adam Thompson-Sharpe Date: Thu, 25 Sep 2025 18:38:26 -0400 Subject: [PATCH] turingplus: init at 6.2.1 --- pkgs/by-name/tu/turingplus/bootstrap.nix | 93 ++++++++++++++++++++++ pkgs/by-name/tu/turingplus/package.nix | 75 +++++++++++++++++ pkgs/by-name/tu/turingplus/use-gnu89.patch | 13 +++ 3 files changed, 181 insertions(+) create mode 100644 pkgs/by-name/tu/turingplus/bootstrap.nix create mode 100644 pkgs/by-name/tu/turingplus/package.nix create mode 100644 pkgs/by-name/tu/turingplus/use-gnu89.patch diff --git a/pkgs/by-name/tu/turingplus/bootstrap.nix b/pkgs/by-name/tu/turingplus/bootstrap.nix new file mode 100644 index 000000000000..074b6d52c7d7 --- /dev/null +++ b/pkgs/by-name/tu/turingplus/bootstrap.nix @@ -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 ]; + }; +}) diff --git a/pkgs/by-name/tu/turingplus/package.nix b/pkgs/by-name/tu/turingplus/package.nix new file mode 100644 index 000000000000..10cad49005a7 --- /dev/null +++ b/pkgs/by-name/tu/turingplus/package.nix @@ -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 ]; + }; +}) diff --git a/pkgs/by-name/tu/turingplus/use-gnu89.patch b/pkgs/by-name/tu/turingplus/use-gnu89.patch new file mode 100644 index 000000000000..1c053269d97f --- /dev/null +++ b/pkgs/by-name/tu/turingplus/use-gnu89.patch @@ -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