From 267c387c53ac1340ab5a1ba45c2b69c1062c1c5c Mon Sep 17 00:00:00 2001 From: Adam Thompson-Sharpe Date: Wed, 18 Mar 2026 19:52:48 -0400 Subject: [PATCH 1/4] opentxl: pass proper make variables for cross-compilation Provides the correct information about binutils to use for compilation. Without this, builds will fail when the C compiler has a target prefix. --- pkgs/by-name/op/opentxl/fix-cross.patch | 166 ++++++++++++++++++++++++ pkgs/by-name/op/opentxl/package.nix | 34 +++-- 2 files changed, 189 insertions(+), 11 deletions(-) create mode 100644 pkgs/by-name/op/opentxl/fix-cross.patch diff --git a/pkgs/by-name/op/opentxl/fix-cross.patch b/pkgs/by-name/op/opentxl/fix-cross.patch new file mode 100644 index 000000000000..3cc318cf134d --- /dev/null +++ b/pkgs/by-name/op/opentxl/fix-cross.patch @@ -0,0 +1,166 @@ +diff --git a/Makefile b/Makefile +index 1374808..2de353f 100644 +--- a/Makefile ++++ b/Makefile +@@ -13,9 +13,10 @@ + # most optimizing C compilers to generate incorrect code for it, or at + # the very least to slow it down severely, at higher levels of optimization. + +-CC = gcc -w -Wno-error=int-conversion +-CFLAGS = -c -O -fno-inline -I . ++CC = gcc ++CFLAGS = -w -Wno-error=int-conversion -c -O -fno-inline -I . + LD = gcc ++STRIP = strip + LDFLAGS = + LDLIBS = -lm + RLFLAGS = -r +@@ -52,12 +53,14 @@ else ifeq ($(OS), CYGWIN) + + else ifeq ($(OS), MSYS) + MESSAGE = "Making TXL on Msys / MinGW using gcc and BSD signal handling" ++ CFLAGS := $(CFLAGS) -DWIN + LDFLAGS := $(LDFLAGS) -Wl,--stack,0x2000000 + EXE = .exe + SIGTYPE = BSD + + else ifeq ($(OS), MINGW64) + MESSAGE = "Making TXL on Msys / MinGW using gcc and BSD signal handling" ++ CFLAGS := $(CFLAGS) -DWIN + LDFLAGS := $(LDFLAGS) -Wl,--stack,0x2000000 + EXE = .exe + SIGTYPE = BSD +@@ -89,18 +92,18 @@ alltxls : thetxl thetxldb thetxlpf thetxlvm thetxlcvt thetxlapr + thetxl : bin objs objs/main.o objs/txl.o objs/xform.o objs/parse.o objs/loadstor.o ${OBJS} ${TLOBJS} + ${CC} ${LDFLAGS} -o bin/txl objs/main.o objs/txl.o objs/xform.o objs/parse.o objs/loadstor.o \ + ${OBJS} ${TLOBJS} ${LDLIBS} +- strip bin/txl${EXE} ++ $(STRIP) bin/txl${EXE} + cp scripts/unix/* bin/ + + thetxldb : bin objs objs/main.o objs/txl.o objs/xformdb.o objs/parse.o objs/loadstor.o ${OBJS} ${TLOBJS} + ${CC} ${LDFLAGS} -o bin/txldb objs/main.o objs/txl.o objs/xformdb.o objs/parse.o objs/loadstor.o \ + ${OBJS} ${TLOBJS} ${LDLIBS} +- strip bin/txldb${EXE} ++ $(STRIP) bin/txldb${EXE} + + thetxlpf : lib objs objs/main.o objs/txl.o objs/xformpf.o objs/parsepf.o objs/loadstor.o ${OBJS} ${TLOBJS} + ${CC} ${LDFLAGS} -o lib/txlpf.x objs/main.o objs/txl.o objs/xformpf.o objs/parsepf.o objs/loadstor.o \ + ${OBJS} ${TLOBJS} ${LDLIBS} +- strip lib/txlpf.x ++ $(STRIP) lib/txlpf.x + + thetxlvm : lib objs objs/main.o objs/txlsa.o objs/xform.o objs/loadsa.o objs/parsa.o ${COMMONOBJS} ${TLOBJS} + ${LD} ${RLFLAGS} -o lib/txlvm.o objs/txlsa.o objs/xform.o objs/loadsa.o objs/parsa.o \ +@@ -109,11 +112,11 @@ thetxlvm : lib objs objs/main.o objs/txlsa.o objs/xform.o objs/loadsa.o objs/par + + thetxlcvt : lib objs objs/main.o objs/txlcvt.o + ${CC} ${LDFLAGS} -o lib/txlcvt.x objs/main.o objs/txlcvt.o ${TLOBJS} ${LDLIBS} +- strip lib/txlcvt.x ++ $(STRIP) lib/txlcvt.x + + thetxlapr : lib objs objs/main.o objs/txlapr.o + ${CC} ${LDFLAGS} -o lib/txlapr.x objs/main.o objs/txlapr.o ${TLOBJS} ${LDLIBS} +- strip lib/txlapr.x ++ $(STRIP) lib/txlapr.x + + objs/main.o : tpluslib/TL.h UNIX main.c + ${CC} $(CFLAGS) -D${SIGTYPE} main.c; mv main.o objs/main.o +@@ -216,4 +219,3 @@ clean : + rm -f bin/txl* objs/*.o + rm -rf opentxl opentxl-* opentxl*.tar.gz + cd test; make clean; cd .. +- +diff --git a/scripts/unix/txl2c b/scripts/unix/txl2c +index 7429daf..ebf56c5 100755 +--- a/scripts/unix/txl2c ++++ b/scripts/unix/txl2c +@@ -19,15 +19,7 @@ then + exit 99 + fi + +-# Localization +-CC="gcc" +- +-case `uname -s` in +- CYGWIN*|MSYS*|MINGW64*) +- CC="$CC -Wl,--stack,0x20000000";; +- *) +- ;; +-esac ++BUILD_TXLLIB="${BUILD_TXLLIB:-$TXLLIB}" + + # Decode TXL program name and options + TXLPROG="" +@@ -90,7 +82,7 @@ then + fi + + # Convert TXLVM byte code to initialized C byte array +-$TXLLIB/txlcvt.x $TXLNAME.ctxl ++$BUILD_TXLLIB/txlcvt.x $TXLNAME.ctxl + + # Clean up + /bin/rm -f $TXLNAME.ctxl Txl/$TXLNAME.ctxl txl/$TXLNAME.ctxl 2> /dev/null +diff --git a/scripts/unix/txlc b/scripts/unix/txlc +index 4f49f49..201037e 100755 +--- a/scripts/unix/txlc ++++ b/scripts/unix/txlc +@@ -20,9 +20,12 @@ then + fi + + # Localization +-CC="gcc" ++CC="${CC:-cc}" ++BUILD_TXLLIB="${BUILD_TXLLIB:-$TXLLIB}" ++TARGET_TXLLIB="${TARGET_TXLLIB:-$TXLLIB}" ++OS="${OS:-$(uname -s)}" + +-case `uname -s` in ++case "$OS" in + CYGWIN*|MSYS*|MINGW64*) + CC="$CC -Wl,--stack,0x20000000";; + *) +@@ -90,10 +93,10 @@ then + fi + + # Convert TXLVM byte code to initialized C byte array +-$TXLLIB/txlcvt.x $TXLNAME.ctxl ++$BUILD_TXLLIB/txlcvt.x $TXLNAME.ctxl + + # Compile and link with TXLVM +-$CC -O -w -o $TXLNAME.x $TXLLIB/txlmain.o $TXLLIB/txlvm.o ${TXLNAME}_TXL.c -lm ++$CC -O -w -o $TXLNAME.x $TARGET_TXLLIB/txlmain.o $TARGET_TXLLIB/txlvm.o ${TXLNAME}_TXL.c -lm + + # Clean up + /bin/rm -f $TXLNAME.ctxl Txl/$TXLNAME.ctxl txl/$TXLNAME.ctxl ${TXLNAME}_TXL.* 2> /dev/null +diff --git a/scripts/unix/txlp b/scripts/unix/txlp +index e39af87..cbb53ac 100755 +--- a/scripts/unix/txlp ++++ b/scripts/unix/txlp +@@ -19,6 +19,8 @@ then + exit 99 + fi + ++BUILD_TXLLIB="${BUILD_TXLLIB:-$TXLLIB}" ++ + # Decode TXL program name and options + TXLFILES="" + TXLOPTIONS="" +@@ -43,7 +45,7 @@ done + # Run the TXL command, using txlpf + if [ "$1" != "" ] + then +-if ! $TXLLIB/txlpf.x $* > /dev/null 2> /tmp/txlp$$ ++if ! $BUILD_TXLLIB/txlpf.x $* > /dev/null 2> /tmp/txlp$$ + then + echo "txlp: TXL program failed" 2>&1 + cat /tmp/txlp$$ 2>&1 +@@ -54,7 +56,7 @@ then + fi + + # Analyze the results +-$TXLLIB/txlapr.x $PROFOPTIONS ++$BUILD_TXLLIB/txlapr.x $PROFOPTIONS + + # Clean up + /bin/rm -f /tmp/txlp$$ diff --git a/pkgs/by-name/op/opentxl/package.nix b/pkgs/by-name/op/opentxl/package.nix index ae5d1c644e84..e26fb2167e8a 100644 --- a/pkgs/by-name/op/opentxl/package.nix +++ b/pkgs/by-name/op/opentxl/package.nix @@ -5,6 +5,18 @@ fetchurl, nix-update-script, }: +let + osOption = + platform: + if platform.isDarwin then + "Darwin" + else if platform.isCygwin then + "CYGWIN" + else if platform.isWindows then + "MSYS" + else + "Linux"; +in stdenv.mkDerivation (finalAttrs: { pname = "opentxl"; version = "11.3.7"; @@ -19,6 +31,10 @@ stdenv.mkDerivation (finalAttrs: { # Using -std=gnu89 to prevent errors that occur with default args env.NIX_CFLAGS_COMPILE = "-std=gnu89 -Wno-int-conversion"; + patches = [ + ./fix-cross.patch + ]; + postPatch = '' # Replace hardcoded FHS paths in various files find . -type f -exec sed -i \ @@ -27,18 +43,15 @@ stdenv.mkDerivation (finalAttrs: { -e "s#/usr/local/bin#$out/bin#g" \ -e "s#/usr/local/lib/txl#$out/lib#g" \ {} + - - # Replace hardcoded gcc references - substituteInPlace scripts/unix/{txlc,txl2c} \ - --replace-fail gcc '${stdenv.cc}/bin/cc' ''; - preBuild = '' - makeFlagsArray+=( - CC="$CC" - LD="$CC" - ) - ''; + makeFlags = [ + "CC=${stdenv.cc.targetPrefix}cc" + "LD=${stdenv.cc.targetPrefix}cc" + "STRIP=${stdenv.cc.targetPrefix}strip" + "EXE=${stdenv.hostPlatform.extensions.executable}" + "OS=${osOption stdenv.hostPlatform}" + ]; checkFlags = [ "-C test" ]; @@ -58,7 +71,6 @@ stdenv.mkDerivation (finalAttrs: { meta = { description = "Open-source compiler for the Txl language"; mainProgram = "txl"; - platforms = lib.platforms.unix; homepage = "https://github.com/CordyJ/OpenTxl"; downloadPage = "https://github.com/CordyJ/OpenTxl/releases"; changelog = "https://github.com/CordyJ/OpenTxl/releases/tag/v${finalAttrs.version}"; From f56d8ab9f1086b3ee5f2f404e8c53b804195d02c Mon Sep 17 00:00:00 2001 From: Adam Thompson-Sharpe Date: Thu, 9 Apr 2026 15:32:27 -0400 Subject: [PATCH 2/4] opentxl: include runtimeShellPackage in buildInputs Required for patchShebangs to find the right shell for runtime scripts. --- pkgs/by-name/op/opentxl/package.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/by-name/op/opentxl/package.nix b/pkgs/by-name/op/opentxl/package.nix index e26fb2167e8a..084179a97734 100644 --- a/pkgs/by-name/op/opentxl/package.nix +++ b/pkgs/by-name/op/opentxl/package.nix @@ -4,6 +4,7 @@ callPackage, fetchurl, nix-update-script, + runtimeShellPackage, }: let osOption = @@ -20,6 +21,7 @@ in stdenv.mkDerivation (finalAttrs: { pname = "opentxl"; version = "11.3.7"; + strictDeps = true; # The code generation part of the upstream build system relies on an x86-only binary, # so the generated code is fetched from the GitHub release instead @@ -28,6 +30,11 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-qIvxQqo1yCVJImjUvNNinzhoywVgaq9s0E+Ab+QStc0="; }; + # Required for patchShebangs to find the right shell for runtime scripts. + # Optional check is to make sure that it is not added on platforms + # that can't run a POSIX shell (e.g. MinGW) + buildInputs = lib.optional (lib.meta.availableOn stdenv.hostPlatform runtimeShellPackage) runtimeShellPackage; + # Using -std=gnu89 to prevent errors that occur with default args env.NIX_CFLAGS_COMPILE = "-std=gnu89 -Wno-int-conversion"; From 1b769bd0d31d248a0406a1fe5f40b4efef948fbd Mon Sep 17 00:00:00 2001 From: Adam Thompson-Sharpe Date: Tue, 7 Apr 2026 09:57:01 -0400 Subject: [PATCH 3/4] opentxl-unwrapped: rename from opentxl --- pkgs/by-name/op/{opentxl => opentxl-unwrapped}/factorial-test.nix | 0 pkgs/by-name/op/{opentxl => opentxl-unwrapped}/factorial.txl | 0 pkgs/by-name/op/{opentxl => opentxl-unwrapped}/fix-cross.patch | 0 pkgs/by-name/op/{opentxl => opentxl-unwrapped}/package.nix | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename pkgs/by-name/op/{opentxl => opentxl-unwrapped}/factorial-test.nix (100%) rename pkgs/by-name/op/{opentxl => opentxl-unwrapped}/factorial.txl (100%) rename pkgs/by-name/op/{opentxl => opentxl-unwrapped}/fix-cross.patch (100%) rename pkgs/by-name/op/{opentxl => opentxl-unwrapped}/package.nix (100%) diff --git a/pkgs/by-name/op/opentxl/factorial-test.nix b/pkgs/by-name/op/opentxl-unwrapped/factorial-test.nix similarity index 100% rename from pkgs/by-name/op/opentxl/factorial-test.nix rename to pkgs/by-name/op/opentxl-unwrapped/factorial-test.nix diff --git a/pkgs/by-name/op/opentxl/factorial.txl b/pkgs/by-name/op/opentxl-unwrapped/factorial.txl similarity index 100% rename from pkgs/by-name/op/opentxl/factorial.txl rename to pkgs/by-name/op/opentxl-unwrapped/factorial.txl diff --git a/pkgs/by-name/op/opentxl/fix-cross.patch b/pkgs/by-name/op/opentxl-unwrapped/fix-cross.patch similarity index 100% rename from pkgs/by-name/op/opentxl/fix-cross.patch rename to pkgs/by-name/op/opentxl-unwrapped/fix-cross.patch diff --git a/pkgs/by-name/op/opentxl/package.nix b/pkgs/by-name/op/opentxl-unwrapped/package.nix similarity index 100% rename from pkgs/by-name/op/opentxl/package.nix rename to pkgs/by-name/op/opentxl-unwrapped/package.nix From 6b57a9f2ffe11d18aece218cd04e772713757f06 Mon Sep 17 00:00:00 2001 From: Adam Thompson-Sharpe Date: Thu, 19 Mar 2026 22:37:32 -0400 Subject: [PATCH 4/4] opentxl: init wrapper --- pkgs/by-name/op/opentxl-unwrapped/package.nix | 7 +- pkgs/by-name/op/opentxl/package.nix | 69 +++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 pkgs/by-name/op/opentxl/package.nix diff --git a/pkgs/by-name/op/opentxl-unwrapped/package.nix b/pkgs/by-name/op/opentxl-unwrapped/package.nix index 084179a97734..7524f904c7ca 100644 --- a/pkgs/by-name/op/opentxl-unwrapped/package.nix +++ b/pkgs/by-name/op/opentxl-unwrapped/package.nix @@ -72,8 +72,11 @@ stdenv.mkDerivation (finalAttrs: { runHook postInstall ''; - passthru.tests.factorial = callPackage ./factorial-test.nix { opentxl = finalAttrs.finalPackage; }; - passthru.updateScript = nix-update-script { }; + passthru = { + inherit osOption; + tests.factorial = callPackage ./factorial-test.nix { opentxl = finalAttrs.finalPackage; }; + updateScript = nix-update-script { }; + }; meta = { description = "Open-source compiler for the Txl language"; diff --git a/pkgs/by-name/op/opentxl/package.nix b/pkgs/by-name/op/opentxl/package.nix new file mode 100644 index 000000000000..ab1b5896ba1c --- /dev/null +++ b/pkgs/by-name/op/opentxl/package.nix @@ -0,0 +1,69 @@ +{ + lib, + stdenv, + makeWrapper, + opentxl-unwrapped, + targetPackages, +}: +let + inherit (targetPackages.stdenv.cc) targetPrefix; + + crossCompiling = stdenv.hostPlatform != stdenv.targetPlatform; + targetOpentxl = if !crossCompiling then opentxl-unwrapped else targetPackages.opentxl-unwrapped; +in +stdenv.mkDerivation (finalAttrs: { + pname = "${targetPrefix}opentxl-wrapper"; + inherit (opentxl-unwrapped) version; + preferLocalBuild = true; + strictDeps = true; + + dontUnpack = true; + dontConfigure = true; + dontBuild = true; + + nativeBuildInputs = [ makeWrapper ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + + # Wrap compiler + makeWrapper ${opentxl-unwrapped}/bin/txlc \ + $out/bin/${targetPrefix}txlc \ + --set TXLLIB ${opentxl-unwrapped}/lib \ + --set BUILD_TXLLIB ${opentxl-unwrapped}/lib \ + --set TARGET_TXLLIB ${targetOpentxl}/lib \ + --set CC ${targetPackages.stdenv.cc}/bin/${targetPrefix}cc \ + --set OS ${opentxl-unwrapped.osOption stdenv.targetPlatform} + ${ + # For convenience, if there is a target prefix, create a symlink named txlc + lib.optionalString (targetPrefix != "") '' + ln -s $out/bin/${targetPrefix}txlc $out/bin/txlc + '' + } + + # Wrap other scripts + for name in txl2c txlp; do + makeWrapper "${opentxl-unwrapped}/bin/$name" \ + "$out/bin/$name" \ + --set-default TXLLIB ${opentxl-unwrapped}/lib + done + + # Link to binaries that don't need wrapping + for name in txl txldb; do + ln -s "${opentxl-unwrapped}/bin/$name" "$out/bin/$name" + done + + runHook postInstall + ''; + + passthru = { + unwrapped = opentxl-unwrapped; + inherit (opentxl-unwrapped.passthru) tests; + }; + + meta = opentxl-unwrapped.meta // { + platforms = lib.platforms.unix; + }; +})