-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
126 lines (107 loc) · 4.71 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
crane.inputs.nixpkgs.follows = "nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
name = "mtfg-rs";
release-version = "0.0.3"; # must match version in Cargo.toml
release-rev = "0866d97e0baed68078059488cee007d7e4226479";
git = "https://github.com/michael-mueller-git/mtfg-rs";
rust-version = "1.65.0";
cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml));
cargo-name = "${cargoToml.package.name}";
overlays = [
rust-overlay.overlays.default
(self: super: {
opencv = super.opencv.overrideAttrs (old: rec {
buildInputs = old.buildInputs ++ [ pkgs.qt6.full ];
cmakeFlags = old.cmakeFlags ++ [ "-DWITH_QT=6" ];
});
})
];
pkgs = import nixpkgs {
inherit system overlays;
};
craneLib = crane.lib.${system};
pkgsMingw = pkgs.pkgsCross.mingwW64;
opencv-win = pkgsMingw.callPackage ./opencv-win.nix {
pthreads = pkgsMingw.windows.mingw_w64_pthreads;
};
buildWindowsPlatformInputs = with pkgs; [
(rust-bin.stable.${rust-version}.default.override {
extensions = [ "rust-src" "llvm-tools-preview" "rust-analysis" ];
targets = [ "x86_64-pc-windows-gnu" ];
})
rust-analyzer
dbus
xorg.libxcb
opencv-win
pkgsMingw.windows.mcfgthreads
];
wineLibPaths = (builtins.map (a: ''${a};'') [
"${pkgsMingw.stdenv.cc.cc}/x86_64-w64-mingw32/lib/"
"${pkgsMingw.windows.mcfgthreads}/bin/"
]) ++ [ "${opencv-win}/bin/" ];
winePath = builtins.foldl' (x: y: x + y) "" wineLibPaths;
mtfg-rs-release-artifact = craneLib.downloadCargoPackageFromGit {
inherit git;
rev = "${release-rev}";
};
mtfg-rs-build-args = {
buildInputs = [ pkgs.opencv ];
nativeBuildInputs = [ pkgs.pkg-config pkgs.clang ];
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
};
mtfg-rs-linux-latest = craneLib.buildPackage (mtfg-rs-build-args // {
src = craneLib.cleanCargoSource (craneLib.path ./.);
});
mtfg-rs-linux-release = craneLib.buildPackage (mtfg-rs-build-args // {
inherit name;
version = "${release-version}";
src = craneLib.cleanCargoSource (craneLib.path "${mtfg-rs-release-artifact}/${name}-${release-version}");
});
in
{
formatter = nixpkgs.legacyPackages.x86_64-linux.nixpkgs-fmt;
packages.default = mtfg-rs-linux-latest;
packages.latest = mtfg-rs-linux-latest;
packages.release = mtfg-rs-linux-release;
packages.opencv-win = opencv-win;
devShells.build-windows = pkgsMingw.mkShell {
packages = buildWindowsPlatformInputs;
buildInputs = buildWindowsPlatformInputs;
depsBuildBuild = with pkgs; [
llvmPackages.clang
];
WIN_PTHREADS = "${pkgsMingw.windows.mingw_w64_pthreads}/lib";
RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [
pkgsMingw.windows.mcfgthreads
]) ++ (builtins.map (a: ''-l ${a}'') [
"mcfgthread"
]);
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER = "${pkgs.wineWowPackages.stable}/bin/wine64";
OPENCV_INCLUDE_PATHS = "${opencv-win}/include/opencv4";
OPENCV_LINK_PATHS = "${opencv-win}/lib";
OPENCV_LINK_LIBS = "opencv_highgui470,opencv_videoio470,opencv_video470,opencv_imgcodecs470,opencv_imgproc470,opencv_core470,opencv_tracking470,opencv_img_hash470,opencv_bioinspired470,opencv_line_descriptor470";
OPENCV_DISABLE_PROBES = "vcpkg_cmake,vcpkg,cmake";
LIBCLANG_PATH = "${pkgs.llvmPackages_11.libclang.lib}/lib";
WINEPATH = winePath;
shellHook = ''
export PATH=$PATH:$HOME/.cargo/bin
cargo build --release --target x86_64-pc-windows-gnu
export BUILD_RESULT_CODE=$?
mkdir -p target/x86_64-pc-windows-gnu/release
cp -fv ${opencv-win}/bin/*.dll target/x86_64-pc-windows-gnu/release
cp -fv ${pkgsMingw.stdenv.cc.cc}/x86_64-w64-mingw32/lib/*.dll target/x86_64-pc-windows-gnu/release
cp -fv ${pkgsMingw.windows.mcfgthreads}/bin/*.dll target/x86_64-pc-windows-gnu/release
exit $BUILD_RESULT_CODE
'';
};
});
}