Update C Flake, Meson wrap fetch, cleaner deps

This commit is contained in:
2024-04-06 14:59:28 -04:00
parent 5a2f120cf1
commit e061d32b3b
2 changed files with 84 additions and 62 deletions

View File

@@ -1,90 +1,90 @@
{ {
description = "Syzygui - Cross Platform Vulkan Based GUI Framework"; description = "C Project Flake";
inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs, flake-utils }: outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system: let flake-utils.lib.eachDefaultSystem (system: let
version = "0.0.1"; version = "0.0.1";
name = "PACKAGE"; name = "cproj";
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
}; };
deps = (with pkgs; [ pkgs-windows = pkgs.pkgsCross.mingwW64;
]);
# For Linux Specific Dependencies
linux' = pkgs.lib.optional pkgs.stdenv.isLinux;
# For MacOS Specific Dependencies
darwin' = pkgs.lib.optional pkgs.stdenv.isDarwin;
nativeBuildInputs = with pkgs; [
meson
ninja
pkg-config
];
bDeps = p: with p; [
] ++ (linux' [
]) ++ (darwin' ([
] ++ (with darwin.apple_sdk.frameworks; [
])));
propDeps = (with pkgs; [ pbDeps = p: with p; [
];
]) ++ (pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ sharedEnv = let
])); mesonWrapCache = let
mesonPy = pkgs.python3.withPackages (p: [p.meson]);
project = pkgs.stdenv.mkDerivation { in import (pkgs.runCommand "meson-wrap-${name}-${version}" {} ''
${mesonPy}/bin/${mesonPy.executable} ${./mesonWrapFetch.py} ${./.} > $out
'') { inherit pkgs; };
in {
pname = name; pname = name;
inherit version; inherit version;
src = ./.; src = self;
nativeBuildInputs = with pkgs; [ inherit nativeBuildInputs;
meson
ninja preConfigure = ''
pkg-config mkdir subprojects/packagecache
]; ${builtins.concatStringsSep ";" (builtins.attrValues (builtins.mapAttrs (n: v: "cp ${v} subprojects/packagecache/${n}") mesonWrapCache))}
buildInputs = deps ++ (with pkgs; [
]);
propagatedBuildInputs = propDeps ++ (with pkgs; [
]);
};
# Pseudo Dev for Not Rebuilding During Development
project-dev = pkgs.stdenv.mkDerivation {
name = "${name}-dev";
src = ./include;
installPhase = ''
mkdir -p $out/include
cp -r * $out/include
''; '';
}; };
project-examples = pkgs.stdenv.mkDerivation { cproj = pkgs.stdenv.mkDerivation (sharedEnv // {
pname = "${name}-examples"; buildInputs = bDeps pkgs;
inherit version; propagatedBuildInputs = pbDeps pkgs;
src = ./examples; });
nativeBuildInputs = with pkgs; [
meson
ninja
pkg-config
];
buildInputs = deps ++ (with pkgs; [ cproj-exe = pkgs-windows.stdenv.mkDerivation ( sharedEnv // {
"${name}" buildInputs = bDeps pkgs-windows;
]); propagatedBuildInputs = pbDeps pkgs-windows;
});
in {
packages = {
default = cproj;
inherit cproj cproj-exe;
Cproj = mkImage "latest";
Cproj-Test = mkImage "dev";
}; };
in { apps = rec {
packages = { default = flake-utils.lib.mkApp { drv = self.packages.${system}.default; };
default = project; };
examples = if (builtins.pathExists ./examples) then project-examples else pkgs.writeText "No Examples" ''
No "examples" in root directory, make an examples dir for examples.
'';
};
apps = rec {
default = flake-utils.lib.mkApp { drv = self.packages.${system}.default; };
};
devShells.default = pkgs.mkShell { devShells = {
C_INCLUDE_PATH = "./include"; default = pkgs.mkShell {
packages = deps ++ propDeps ++ (with pkgs; [ inputsFrom = [ cproj ];
project-dev packages = (with pkgs; [
clang-tools clang-tools
meson
]); ]);
}; };
} inherit cproj;
); };
});
} }

View File

@@ -0,0 +1,22 @@
from glob import glob
from mesonbuild.wrap.wrap import PackageDefinition
import sys
print("{ pkgs, ... }: {")
for wrap in glob(f"{sys.argv[1]}/subprojects/*.wrap"):
wrap = PackageDefinition(wrap)
if wrap.wrap_section == "wrap-file":
print(f""" "{wrap.values['source_filename']}" = pkgs.fetchurl {{
url = "{wrap.values['source_url']}";
sha256 = "{wrap.values['source_hash']}";
}};""")
if 'patch_url' in wrap.values:
print(f""" "{wrap.values['patch_filename']}" = pkgs.fetchurl {{
url = "{wrap.values['patch_url']}";
sha256 = "{wrap.values['patch_hash']}";
}};""")
print("}")