Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Nix environment #1335

Merged
merged 18 commits into from
Feb 28, 2024
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"--build-dtk",
dest="build_dtk",
type=Path,
help="path to decomp-toolkit source (optional)",
help="path to decomp-toolkit source or binary (optional)",
)
parser.add_argument(
"--sjiswrap",
Expand Down
1 change: 1 addition & 0 deletions default.nix
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to exist? Like when I source Python, I do:

. ./.venv/bin/activate

Or when I source vimrc I do

:source tools/vimc

Can this file be removed and your local command updated accordingly?

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import ./nix
2 changes: 2 additions & 0 deletions nix/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.nix]
indent_size = 2
34 changes: 34 additions & 0 deletions nix/decomp-toolkit.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{ lib
, fetchFromGitHub
, git
, rustPlatform
, stdenv
}:

rustPlatform.buildRustPackage rec {
pname = "decomp-toolkit";
version = "0.7.3";

src = fetchFromGitHub {
owner = "encounter";
repo = "decomp-toolkit";
rev = "v${version}";
hash = "sha256-cpHaoxRr/Lyx6tpyUx7Sm+9h0BicrO+jVJA09BBgKJ4=";
};

nativeBuildInputs = [
git
];

cargoLock.lockFile = "${src}/Cargo.lock";
cargoLock.outputHashes."ar-0.8.0" = "sha256-OLyo+cRRWMsI1i8NsgsBKRJH1XsKW1CculQnJ/wcya0=";
cargoLock.outputHashes."dol-0.1.0" = "sha256-YfMXWNtmZJhK39R3w98DEGm4y9x59osFGliG36BcuLU=";

meta = with lib; {
description = "A GameCube & Wii decompilation toolkit";
homepage = "https://github.com/encounter/decomp-toolkit";
license = with licenses; [ asl20 mit ];
maintainers = with maintainers; [ r-burns ];
mainProgram = "dtk";
};
}
17 changes: 17 additions & 0 deletions nix/default.nix
r-burns marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
sources ? import ./sources.nix,
}:
let
pkgs = import sources.nixpkgs {
overlays = [
(self: super: {
decomp-toolkit = super.callPackage ./decomp-toolkit.nix {};
devkitppc = super.callPackage ./devkitppc.nix {};
mwcc = super.callPackage ./mwcc.nix {};
wibo = super.pkgsi686Linux.callPackage ./wibo.nix {};
})
];
};
in

pkgs.callPackage ./melee.nix {}
41 changes: 41 additions & 0 deletions nix/devkitppc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{ stdenvNoCC, lib
, buildEnv
, fetchFromGitHub
, fetchpatch
, makeWrapper
, overrideCC
, pkgsCross
}:

let
version = "43";

tag = "devkitPPC_r${version}";

ppcCrossBinutils = pkgsCross.ppc-embedded.buildPackages.binutils-unwrapped;

bintools' = ppcCrossBinutils.overrideAttrs (oa: {
patches = oa.patches ++ [
(fetchpatch {
url = "https://raw.githubusercontent.com/devkitPro/buildscripts/${tag}/dkppc/patches/binutils-${oa.version}.patch";
hash = "sha256-IOqa20LQYBxfR1KKxkp0hVV21CKd9IZrvNeEyuW09us=";
})
];
});
in
stdenvNoCC.mkDerivation {
pname = "devkitppc";
inherit version;
nativeBuildInputs = [
makeWrapper
];
buildCommand = ''
for bindir in '${lib.getBin bintools'}/bin'; do
cd "$bindir"
for f in powerpc-none-eabi-*; do
short="$(echo "$f" | sed s/powerpc-none-eabi-/powerpc-eabi-/)"
makeWrapper "$bindir/$f" "$out/bin/$short"
done
done
'';
}
62 changes: 62 additions & 0 deletions nix/melee.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{ lib
, stdenv
, decomp-toolkit
, devkitppc
, fetchurl
, mwcc
, ninja
, python3
, wibo
}:
let
sjiswrap = fetchurl {
url = "https://github.com/encounter/sjiswrap/releases/download/v1.1.1/sjiswrap-windows-x86.exe";
hash = "sha256-J6PF1PJj5OuW5WGc/Noi9F0zzNEhEEx/9qN+FbP0J80=";
};
in
stdenv.mkDerivation {
name = "doldecomp-melee";

src = lib.cleanSourceWith {
filter = name: type: let
basename = baseNameOf (toString name);
in !(false
|| basename == "build"
|| basename == "expected"
|| lib.hasSuffix ".nix" basename
|| lib.hasSuffix ".dump" basename
|| lib.hasSuffix ".o" basename
);
src = lib.cleanSource ../.;
};

shellHook = ''
runHook postPatch
'';

nativeBuildInputs = [
decomp-toolkit
devkitppc
ninja
python3
wibo
];

configurePhase = ''
runHook preConfigure
python3 ./configure.py --wrapper ${wibo}/bin/wibo \
--build-dtk ${decomp-toolkit}/bin/dtk \
--sjiswrap ${sjiswrap} \
--compilers ${mwcc}
runHook postConfigure
'';

enableParallelBuilding = true;

installPhase = ''
runHook preInstall
mkdir -p $out
cp build/GALE01/main.dol $out/
runHook postInstall
'';
}
23 changes: 23 additions & 0 deletions nix/mwcc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ lib
, stdenv
, fetchzip
}:
stdenv.mkDerivation {
name = "GC_WII_COMPILERS";
src = fetchzip {
url = "https://cdn.discordapp.com/attachments/727918646525165659/1129759991696457728/GC_WII_COMPILERS.zip";
stripRoot = false;
sha256 = "sha256-IX3byvEUVJB6Rmc+NqO9ZNt1jl95nQpEIqxbHI+uUio=";
};
# Patch 1.1 linker to not read garbage from stack.
# Fixes random crashes under wibo.
postPatch = ''
printf '\x51' | dd of=GC/1.1/mwldeppc.exe bs=1 seek=130933 count=1 conv=notrunc
'';

installPhase = ''
runHook preInstall
cp -r . $out/
runHook postInstall
'';
}
26 changes: 26 additions & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
sources ? import ./sources.nix,
}:
let
pkgs = import sources.nixpkgs {
overlays = [
(self: super: {
decomp-toolkit = super.callPackage ./decomp-toolkit.nix {};
devkitppc = super.callPackage ./devkitppc.nix {};
mwcc = super.callPackage ./mwcc.nix {};
wibo = super.pkgsi686Linux.callPackage ./wibo.nix {};
})
];
};

melee = import ./default.nix { inherit sources; };
in

melee.overrideAttrs (oa: {
nativeBuildInputs = oa.nativeBuildInputs ++ [
(pkgs.clang-tools.override {
llvmPackages = pkgs.llvmPackages_15;
})
pkgs.clang.cc.python
];
})
14 changes: 14 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"nixpkgs": {
"branch": "nixos-unstable",
"description": "Nix Packages collection",
"homepage": "",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "73de017ef2d18a04ac4bfd0c02650007ccb31c2a",
"sha256": "1v9sy2i2dy3qksx4mf81gwzfl0jzpqccfkzq7fjxgq832f9d255i",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/73de017ef2d18a04ac4bfd0c02650007ccb31c2a.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
Loading
Loading