cross compile for windows and macOS

This commit is contained in:
Chance 2025-04-01 18:05:07 -04:00 committed by BitSyndicate
parent 87cef23366
commit cb7a5058dc
Signed by: bitsyndicate
GPG key ID: 443E4198D6BBA6DE
2 changed files with 61 additions and 36 deletions

View file

@ -1,5 +1,4 @@
{ { lib,
lib,
rustPlatform, rustPlatform,
nix-gitignore, nix-gitignore,
bash, bash,
@ -11,6 +10,8 @@
pkg-config, pkg-config,
libxkbcommon, libxkbcommon,
pkgs, pkgs,
stdenv,
targetPackages ? pkgs,
}: let }: let
version = (builtins.fromTOML (builtins.readFile ./engine/Cargo.toml)).package.version; version = (builtins.fromTOML (builtins.readFile ./engine/Cargo.toml)).package.version;
src = nix-gitignore.gitignoreSource [] ./.; src = nix-gitignore.gitignoreSource [] ./.;
@ -19,35 +20,53 @@ in
pname = "zenyx"; pname = "zenyx";
inherit src version; inherit src version;
cargoLock.lockFile = ./Cargo.lock; cargoLock.lockFile = ./Cargo.lock;
nativeBuildInputs = [ nativeBuildInputs = [
makeWrapper
pkg-config pkg-config
] ++ lib.optionals stdenv.targetPlatform.isDarwin [
targetPackages.darwin.apple_sdk.frameworks.CoreServices
]; ];
buildInputs = with pkgs; [
wayland buildInputs = with targetPackages; [
dav1d
] ++ lib.optionals (stdenv.targetPlatform.isLinux || stdenv.targetPlatform.isWindows) [
vulkan-loader vulkan-loader
] ++ lib.optionals stdenv.targetPlatform.isLinux [
makeWrapper
wayland
libxkbcommon libxkbcommon
libGL libGL
libxkbcommon
xorg.libXcursor xorg.libXcursor
xorg.libXrandr xorg.libXrandr
xorg.libXi xorg.libXi
xorg.libX11 xorg.libX11
xorg.libxcb xorg.libxcb
bash bash
dav1d ] ++ 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
]; ];
doCheck = false;
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath buildInputs}";
fixupPhase = '' CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER =
wrapProgram $out/bin/${pname} --set PATH ${bash}/bin:\$PATH --set LD_LIBRARY_PATH ${pkgs.lib.makeLibraryPath buildInputs} 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 = { meta = {
description = "Test"; description = "Cross-platform WSYWIG Game Engine";
license = lib.licenses.mit; license = lib.licenses.mit;
platforms = lib.platforms.linux; platforms = lib.platforms.all;
mainProgram = "zenyx"; mainProgram = "zenyx";
}; };
} }

View file

@ -48,6 +48,12 @@
packages = { packages = {
inherit (pkgs) zenyx; inherit (pkgs) zenyx;
default = 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 { devShells.default = pkgs.mkShell {