Skip to content

Commit

Permalink
Support Nix environment (#1335)
Browse files Browse the repository at this point in the history
* Nix setup for Makefile build

* Modify nix files for ninja/dtk build

* Allow specifying prebuilt dtk binary

* Fix compiler zip url

* Rename nix/ to .nix/

* Add Nix CI workflow

Co-authored-by: Robin Avery <[email protected]>
  • Loading branch information
r-burns and ribbanya authored Feb 28, 2024
1 parent 9931994 commit 09d26b4
Show file tree
Hide file tree
Showing 15 changed files with 489 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,31 @@ jobs:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

build-nix:
name: Nix
runs-on: ubuntu-latest
if: github.repository == 'doldecomp/melee'
env:
REGISTRY: ghcr.io
IMAGE: doldecomp/build-melee:main
steps:
- uses: actions/checkout@v4
- name: Log into container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Grab Melee DOL
run: |
image="$REGISTRY/$IMAGE"
docker pull "$image"
container_id=$(docker create "$image")
docker cp "$container_id":/orig .
- uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: DeterminateSystems/magic-nix-cache-action@v2
- run: nix-build
- run: nix-shell --run "echo OK"
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
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://files.decomp.dev/compilers_20230715.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

0 comments on commit 09d26b4

Please sign in to comment.