Skip to content

Commit

Permalink
Use rpypkgs.
Browse files Browse the repository at this point in the history
This also includes an update for building with newer RPython and for
mt-python now living in bin/ like it should have always been.
  • Loading branch information
MostAwesomeDude committed Apr 16, 2024
1 parent 1ff8263 commit 8bff474
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 83 deletions.
52 changes: 51 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05";
flake-utils.url = "github:numtide/flake-utils";
rpypkgs = {
url = "git://git.pf.osdn.net/gitroot/c/co/corbin/rpypkgs.git";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
};

outputs = { self, nixpkgs, flake-utils }:
outputs = { self, nixpkgs, flake-utils, rpypkgs }:
let
noPythonCheck = p: p.overridePythonAttrs (old: {
doCheck = false;
Expand Down Expand Up @@ -34,7 +41,7 @@
};
overlays = [ overlay ];
};
typhon = import ./nix-support/typhon.nix pkgs;
typhon = import ./nix-support/typhon.nix { inherit pkgs rpypkgs; };
qbe = pkgs.stdenv.mkDerivation {
name = "qbe-unstable";

Expand All @@ -49,7 +56,7 @@
in {
overlays.default = overlay;
packages = typhon // {
default = typhon.fullMonte;
default = typhon.monte;
};
devShells.default = pkgs.mkShell {
packages = with pkgs; [ cachix nix-tree ];
Expand Down
2 changes: 1 addition & 1 deletion nix-support/bench.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ stdenv.mkDerivation {
name = "typhon-bench";
buildInputs = [ typhonVm mast ];
buildPhase = ''
ln -s ${typhonVm}/mt-typhon .
ln -s ${typhonVm}/bin/mt-typhon .
./mt-typhon -l ${mast} -l ${mast}/mast -b ${mast}/loader bench \
${mast}/mast/bench/{brot,nqueens,primeCount,richards}
'';#*/
Expand Down
4 changes: 2 additions & 2 deletions nix-support/mast.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let
then "-noverify"
else "";
in pkgs.runCommand name {} ''
${typhonVm}/mt-typhon -l ${boot} ${boot}/loader run montec ${flags} ${mt} $out
${typhonVm}/bin/mt-typhon -l ${boot} ${boot}/loader run montec ${flags} ${mt} $out
'';
exts = [ ".mt" ".mt.md" ".asdl" ];
# Compile a whole tree.
Expand All @@ -33,6 +33,6 @@ let
in buildMASTFarm.overrideAttrs (attrs: {
# Run the tests in the built tree using the built tree's loader.
buildCommand = attrs.buildCommand + ''
${typhonVm}/mt-typhon -l $out $out/loader test all-tests
${typhonVm}/bin/mt-typhon -l $out $out/loader test all-tests
'';
})
20 changes: 10 additions & 10 deletions nix-support/monte-script.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,22 @@ let
case $OPERATION in
${buildCmds}
repl)
$RLWRAP ${typhonVm}/mt-typhon -l ${mast} \
$RLWRAP ${typhonVm}/bin/mt-typhon -l ${mast} \
${mast}/loader run tools/repl
if [ $? == 1 ]; then
echo "Due to a Docker bug, readline-style editing is not currently available in this REPL. Sorry."
${typhonVm}/mt-typhon -l ${mast} \
${typhonVm}/bin/mt-typhon -l ${mast} \
${mast}/loader run tools/repl
fi
;;
muffin)
shift
${typhonVm}/mt-typhon -l ${mast} \
${typhonVm}/bin/mt-typhon -l ${mast} \
${mast}/loader run tools/muffin "$@"
;;
lint)
shift
${typhonVm}/mt-typhon -l ${mast} ${mast}/loader \
${typhonVm}/bin/mt-typhon -l ${mast} ${mast}/loader \
run montec -lint -terse "$@"
;;
run|test|bench|dot)
Expand All @@ -118,7 +118,7 @@ let
usage 1
else
DEST=''${3:-''${SOURCE%.mt.mast}}
${typhonVm}/mt-typhon -l ${mast} ${mast}/loader \
${typhonVm}/bin/mt-typhon -l ${mast} ${mast}/loader \
run montec -mix "$SOURCE" "$DEST"
fi
;;
Expand All @@ -129,12 +129,12 @@ let
else
if [[ "$SOURCE" != *.mast ]]; then
MASTSOURCE=''${SOURCE%.mt}.mast
${typhonVm}/mt-typhon -l ${mast} \
${typhonVm}/bin/mt-typhon -l ${mast} \
${mast}/loader run montec -mix "$SOURCE" "$MASTSOURCE"
SOURCE=$MASTSOURCE
fi
if [[ "$SOURCE" == *.mast ]]; then
${typhonVm}/mt-typhon -l ${mast} -l $PWD \
${typhonVm}/bin/mt-typhon -l ${mast} -l $PWD \
${mast}/loader run ''${SOURCE%.mast} "$@"
fi
fi
Expand All @@ -144,7 +144,7 @@ let
if [[ -z $SOURCE ]]; then
usage 1
else
${typhonVm}/mt-typhon -l ${mast} \
${typhonVm}/bin/mt-typhon -l ${mast} \
${mast}/loader run tools/dump "$SOURCE"
fi
;;
Expand All @@ -153,7 +153,7 @@ let
if [[ -z $SOURCE ]]; then
usage 1
else
${typhonVm}/mt-typhon -l ${mast} \
${typhonVm}/bin/mt-typhon -l ${mast} \
${mast}/loader run format "$SOURCE"
fi
;;
Expand All @@ -171,7 +171,7 @@ let
'';
capnpc-script = pkgs.writeScript "capnpc-monte" ''
#!${shellForMt}
${typhonVm}/mt-typhon -l ${mast} \
exec ${typhonVm}/bin/mt-typhon -l ${mast} \
${mast}/loader run tools/capnpc "$@"
'';

Expand Down
6 changes: 3 additions & 3 deletions nix-support/montePackage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let
for srcP in ${lib.concatStringsSep " " pathNames}; do
for srcF in `find ./$srcP -name \\*.mt`; do
destF=\${srcF%%.mt}.mast
${typhonVm}/mt-typhon -l ${mast}/mast ${mast}/loader run montec -mix $srcF $destF
${typhonVm}/bin/mt-typhon -l ${mast}/mast ${mast}/loader run montec -mix $srcF $destF
fail=$?
if [ $fail -ne 0 ]; then
exit $fail
Expand All @@ -34,7 +34,7 @@ let
";
doCheck = doCheck;
checkPhase = if doCheck then ''
${typhonVm}/mt-typhon ${dependencySearchPaths} -l ${mast}/mast -l . ${mast}/loader test ${entrypoint}
${typhonVm}/bin/mt-typhon ${dependencySearchPaths} -l ${mast}/mast -l . ${mast}/loader test ${entrypoint}
'' else null;
installPhase = "
mkdir -p $out
Expand Down Expand Up @@ -70,7 +70,7 @@ let
for p in ${lib.concatStringsSep " " pathNames}; do
LOCALPKGPATHS+=" -l $out/$p"
done
${typhonVm}/mt-typhon ${dependencySearchPaths} \$LOCALPKGPATHS -l ${mast}/mast ${mast}/loader \$OPERATION ${entrypoint} "\$@"
${typhonVm}/bin/mt-typhon ${dependencySearchPaths} \$LOCALPKGPATHS -l ${mast}/mast ${mast}/loader \$OPERATION ${entrypoint} "\$@"
EOF
chmod +x $out/bin/${entryPointName}
'' else "");
Expand Down
44 changes: 20 additions & 24 deletions nix-support/typhon.nix
Original file line number Diff line number Diff line change
@@ -1,65 +1,61 @@
nixpkgs:
{ pkgs, rpypkgs }:
let
lib = nixpkgs.lib;
lib = pkgs.lib;
vmSrc = let loc = part: (toString ./..) + part;
in builtins.filterSource (path: type:
let p = toString path;
in (lib.hasPrefix (loc "/typhon/") p &&
(type == "directory" || lib.hasSuffix ".py" p)) ||
p == loc "/typhon" ||
p == loc "/main.py") ./..;
vmConfig = {
inherit vmSrc;
inherit (nixpkgs) pypy libsodium;
pypyPackages = nixpkgs.pypy.pkgs;
# Want to build Typhon with Clang instead of GCC? Uncomment this next
# line. ~ C.
# stdenv = nixpkgs.clangStdenv;
};
typhon = with nixpkgs; rec {
typhonVm = callPackage ./vm.nix (vmConfig // { buildJIT = false; });
typhonVmJIT = callPackage ./vm.nix (vmConfig // { buildJIT = true; });
typhon = with pkgs; rec {
# Want to build Typhon with Clang instead of GCC?
# Add `stdenv = pkgs.clangStdenv` to either VM. ~ C.
typhonVm = callPackage ./vm.nix {
inherit vmSrc rpypkgs; buildJIT = false;
};
typhonVmJIT = callPackage ./vm.nix {
inherit vmSrc rpypkgs; buildJIT = true;
};
mast = callPackage ./mast.nix { typhonVm = typhonVmJIT;
pkgs = nixpkgs; };
pkgs = pkgs; };

typhonDumpMAST = callPackage ./dump.nix {};
# XXX broken for unknown reasons
# bench = callPackage ./bench.nix { typhonVm = typhonVmJIT; mast = mast; }
monte = callPackage ./monte-script.nix {
typhonVm = typhonVmJIT; mast = mast;
};
capnMast = callPackage ./capn.nix {
pkgs = nixpkgs; monte = monte;
};
fullMast = nixpkgs.symlinkJoin {
capnMast = callPackage ./capn.nix { inherit pkgs monte; };
fullMast = pkgs.symlinkJoin {
name = "mast-full";
paths = [ mast capnMast ];
};
fullMonte = callPackage ./monte-script.nix {
typhonVm = typhonVmJIT; mast = fullMast;
};
mtBusybox = monte.override { shellForMt = "${nixpkgs.busybox}/bin/sh"; };
mtBusybox = monte.override { shellForMt = "${pkgs.busybox}/bin/sh"; };
mtLite = mtBusybox.override { withBuild = false; };
};
typhonDocker = {
mtDocker = nixpkgs.dockerTools.buildImage {
mtDocker = pkgs.dockerTools.buildImage {
name = "monte-dev";
tag = "latest";
contents = [nixpkgs.nix.out nixpkgs.busybox typhon.mtBusybox typhon.typhonVmJIT];
contents = [pkgs.nix.out pkgs.busybox typhon.mtBusybox typhon.typhonVmJIT];
runAsRoot = ''
#!${nixpkgs.busybox}/bin/sh
#!${pkgs.busybox}/bin/sh
mkdir -p /etc
tee /etc/profile <<'EOF'
echo "Try \`monte repl' for an interactive Monte prompt."
echo "See \`monte --help' for more commands."
EOF
'';
config = {
Cmd = [ "${nixpkgs.busybox}/bin/sh" "-l" ];
Cmd = [ "${pkgs.busybox}/bin/sh" "-l" ];
WorkingDir = "/";
};
};
mtLiteDocker = nixpkgs.dockerTools.buildImage {
mtLiteDocker = pkgs.dockerTools.buildImage {
name = "repl";
tag = "latest";
contents = with typhon; [mtLite typhonVmJIT];
Expand Down
46 changes: 10 additions & 36 deletions nix-support/vm.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{stdenv, fetchFromGitLab, fetchFromGitHub, lib, libsodium, libuv, libffi,
pkg-config, pypy, pypyPackages, vmSrc, buildJIT}:
{ stdenv, fetchFromGitLab, fetchFromGitHub, libsodium, libuv, libffi,
pypy, system, vmSrc, rpypkgs, buildJIT }:

let
# https://foss.heptapod.net/pypy/pypy/
Expand All @@ -11,29 +11,18 @@ let
rev = "90fd9ed34d52181de59cbfff863719472b05418e";
sha256 = "03cshgvh8qcsyac4q4vf0sbvcm1m2ikgwycwip4cc7sw9pzpw6a3";
};
macropy = pypyPackages.buildPythonPackage rec {
pname = "macropy";
version = "1.0.4";
name = "${pname}-${version}";
src = fetchFromGitHub {
owner = "lihaoyi";
repo = "macropy";
rev = "13993ccb08df21a0d63b091dbaae50b9dbb3fe3e";
sha256 = "12496896c823h0849vnslbdgmn6z9mhfkckqa8sb8k9qqab7pyyl";
};
};
optLevel = if buildJIT then "-Ojit" else "-O2";

in
stdenv.mkDerivation {
in rpypkgs.lib.${system}.mkRPythonDerivation {
entrypoint = "main.py";
binName = "mt-typhon";
nativeBuildInputs = with rpypkgs.packages.${system}.rpythonPackages; [ macropy ];
buildInputs = [ libuv libsodium ];
optLevel = if buildJIT then "jit" else "2";
} {
name = if buildJIT then "typhon-vm" else "typhon-vm-nojit";

src = vmSrc;

buildInputs = [ pypy
pypyPackages.py pypyPackages.pytest
macropy pypySrc
pkg-config libffi libuv libsodium ];
# XXX really?
propagatedBuildInputs = [ libffi libuv libsodium ];

shellHook = ''
Expand All @@ -52,20 +41,5 @@ stdenv.mkDerivation {
trap typhon_cleanup EXIT
'';

buildPhase = ''
source $stdenv/setup
mkdir -p ./rpython/_cache
cp -r ${pypySrc}/rpython .
chmod -R u+w rpython/
cp -r $src/main.py .
# Do the actual translation.
${pypy}/bin/pypy -mrpython ${optLevel} main.py
'';

installPhase = ''
mkdir $out
cp mt-typhon $out/
'';

separateDebugInfo = true;
}
Loading

0 comments on commit 8bff474

Please sign in to comment.