cross compile for windows and macOS

This commit is contained in:
Chance 2025-04-01 18:05:07 -04:00 committed by BitSyndicate
parent 2d4736f12e
commit a990d1c9c8
2 changed files with 61 additions and 36 deletions

View file

@ -1,5 +1,4 @@
{
lib,
{ lib,
rustPlatform,
nix-gitignore,
bash,
@ -11,43 +10,63 @@
pkg-config,
libxkbcommon,
pkgs,
stdenv,
targetPackages ? pkgs,
}: let
version = (builtins.fromTOML (builtins.readFile ./engine/Cargo.toml)).package.version;
src = nix-gitignore.gitignoreSource [] ./.;
in
rustPlatform.buildRustPackage rec {
pname = "zenyx";
inherit src version;
cargoLock.lockFile = ./Cargo.lock;
nativeBuildInputs = [
makeWrapper
pkg-config
];
buildInputs = with pkgs; [
wayland
vulkan-loader
libxkbcommon
libGL
libxkbcommon
xorg.libXcursor
xorg.libXrandr
xorg.libXi
xorg.libX11
xorg.libxcb
bash
dav1d
];
doCheck = false;
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath buildInputs}";
rustPlatform.buildRustPackage rec {
pname = "zenyx";
inherit src version;
cargoLock.lockFile = ./Cargo.lock;
fixupPhase = ''
wrapProgram $out/bin/${pname} --set PATH ${bash}/bin:\$PATH --set LD_LIBRARY_PATH ${pkgs.lib.makeLibraryPath buildInputs}
'';
nativeBuildInputs = [
pkg-config
] ++ lib.optionals stdenv.targetPlatform.isDarwin [
targetPackages.darwin.apple_sdk.frameworks.CoreServices
];
meta = {
description = "Test";
license = lib.licenses.mit;
platforms = lib.platforms.linux;
mainProgram = "zenyx";
};
}
buildInputs = with targetPackages; [
dav1d
] ++ lib.optionals (stdenv.targetPlatform.isLinux || stdenv.targetPlatform.isWindows) [
vulkan-loader
] ++ lib.optionals stdenv.targetPlatform.isLinux [
makeWrapper
wayland
libxkbcommon
libGL
xorg.libXcursor
xorg.libXrandr
xorg.libXi
xorg.libX11
xorg.libxcb
bash
] ++ lib.optionals stdenv.targetPlatform.isDarwin [
makeWrapper
darwin.apple_sdk.frameworks.Cocoa
darwin.apple_sdk.frameworks.Metal
darwin.apple_sdk.frameworks.CoreVideo
darwin.apple_sdk.frameworks.QuartzCore
];
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER =
lib.optionalString stdenv.targetPlatform.isWindows "${stdenv.cc.targetPrefix}gcc";
NIX_LDFLAGS = lib.optionalString stdenv.targetPlatform.isDarwin "-framework CoreFoundation";
postInstall = lib.optionalString stdenv.targetPlatform.isLinux ''
wrapProgram $out/bin/${pname} \
--prefix PATH : ${lib.makeBinPath [ bash ]} \
--set LD_LIBRARY_PATH ${lib.makeLibraryPath buildInputs}
'';
doCheck = false;
meta = {
description = "Cross-platform WSYWIG Game Engine";
license = lib.licenses.mit;
platforms = lib.platforms.all;
mainProgram = "zenyx";
};
}

View file

@ -48,6 +48,12 @@
packages = {
inherit (pkgs) zenyx;
default = pkgs.zenyx;
windows = let
pkgsCross = import nixpkgs {
system = "x86_64-linux";
crossSystem = nixpkgs.lib.systems.examples.mingwW64;
};
in pkgsCross.callPackage ./default.nix {};
};
devShells.default = pkgs.mkShell {