112 lines
3.3 KiB
Nix
112 lines
3.3 KiB
Nix
{
|
|
description = "animator-as-crab: Animator Controllers described in Rhai, generated from Rust into Unity";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
crane.url = "github:ipetkov/crane";
|
|
rust-overlay = {
|
|
url = "github:oxalica/rust-overlay";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
};
|
|
|
|
outputs =
|
|
{
|
|
self,
|
|
nixpkgs,
|
|
crane,
|
|
rust-overlay,
|
|
}:
|
|
let
|
|
systems = [
|
|
"x86_64-linux"
|
|
"aarch64-linux"
|
|
"x86_64-darwin"
|
|
"aarch64-darwin"
|
|
];
|
|
forAllSystems = nixpkgs.lib.genAttrs systems;
|
|
|
|
perSystem =
|
|
system:
|
|
let
|
|
pkgs = import nixpkgs {
|
|
inherit system;
|
|
overlays = [ (import rust-overlay) ];
|
|
};
|
|
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
|
|
extensions = [
|
|
"rust-src"
|
|
"rust-analyzer"
|
|
"clippy"
|
|
"rustfmt"
|
|
];
|
|
};
|
|
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
|
|
|
|
# Name Unity expects on the current platform; AacCrabNative.cs imports "libaac".
|
|
nativeLib =
|
|
if pkgs.stdenv.hostPlatform.isDarwin then
|
|
"libaac.dylib"
|
|
else if pkgs.stdenv.hostPlatform.isWindows then
|
|
"aac.dll"
|
|
else
|
|
"libaac.so";
|
|
|
|
# The Rust core: evaluates the Rhai DSL and emits the graph as JSON for Unity.
|
|
aac = craneLib.buildPackage {
|
|
src = ./rust;
|
|
strictDeps = true;
|
|
doCheck = true;
|
|
# crane's default install only copies binaries; install the cdylib explicitly.
|
|
installPhase = ''
|
|
runHook preInstall
|
|
mkdir -p $out/lib $out/bin
|
|
cp target/release/${nativeLib} $out/lib/
|
|
cp target/release/aac-dump $out/bin/
|
|
runHook postInstall
|
|
'';
|
|
};
|
|
|
|
# Unity-importable bundle: native library plus the C# packages, as a single zip.
|
|
bundle =
|
|
pkgs.runCommand "animator-as-crab-${system}.zip"
|
|
{
|
|
nativeBuildInputs = [ pkgs.zip ];
|
|
meta.description = "Unity plugin bundle for animator-as-crab";
|
|
}
|
|
''
|
|
mkdir -p root/Plugins root/bin
|
|
cp ${aac}/lib/${nativeLib} root/Plugins/
|
|
cp ${aac}/bin/aac-dump root/bin/
|
|
cp -r ${./csharp}/dev.doloro.animator-as-crab root/
|
|
cp -r ${./csharp}/dev.hai-vr.animator-as-code.v1.base.test root/
|
|
(cd root && zip -q -r $out .)
|
|
'';
|
|
in
|
|
{
|
|
packages = {
|
|
inherit aac bundle;
|
|
default = bundle;
|
|
};
|
|
|
|
devShells.default = craneLib.devShell {
|
|
inputsFrom = [ aac ];
|
|
packages = [
|
|
rustToolchain
|
|
pkgs.curl
|
|
pkgs.jq
|
|
pkgs.zip
|
|
pkgs.just
|
|
];
|
|
};
|
|
|
|
formatter = pkgs.nixfmt-rfc-style;
|
|
};
|
|
in
|
|
{
|
|
packages = forAllSystems (system: (perSystem system).packages);
|
|
devShells = forAllSystems (system: (perSystem system).devShells);
|
|
formatter = forAllSystems (system: (perSystem system).formatter);
|
|
};
|
|
}
|