-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
138 lines (126 loc) · 4.5 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
127
128
129
130
131
132
133
134
135
136
137
138
{
description = "SyncDisBoi";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
nixpkgs,
flake-utils,
naersk,
fenix,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [fenix.overlays.default];
};
toolchain = with fenix.packages.${system};
combine [
default.rustc
default.cargo
default.clippy
default.rustfmt
targets.x86_64-unknown-linux-musl.latest.rust-std
targets.x86_64-pc-windows-gnu.latest.rust-std
targets.aarch64-unknown-linux-musl.latest.rust-std
];
naersk' = naersk.lib.${system}.override {
cargo = toolchain;
rustc = toolchain;
};
naerskBuildPackage = args:
naersk'.buildPackage (
args
// cargoConfig
);
naerskBuildPackageT = target: args: naerskBuildPackage (args // {CARGO_BUILD_TARGET = target;});
cargoConfig = {
# Tells Cargo to enable static compilation.
# (https://doc.rust-lang.org/cargo/reference/config.html#targettriplerustflags)
#
# Note that the resulting binary might still be considered dynamically
# linked by ldd, but that's just because the binary might have
# position-independent-execution enabled.
# (see: https://github.com/rust-lang/rust/issues/79624#issuecomment-737415388)
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGS = "-C target-feature=+crt-static";
# Tells Cargo that it should use Wine to run tests.
# (https://doc.rust-lang.org/cargo/reference/config.html#targettriplerunner)
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER = pkgs.writeScript "wine-wrapper" ''
export WINEPREFIX="$(mktemp -d)"
exec wine64 $@
'';
};
fnBuildInputs = pkgs: with pkgs; [openssl];
shellPkgs = with pkgs; [
wineWowPackages.stable
];
in rec {
defaultPackage = naerskBuildPackage {
src = ./.;
#doCheck = true;
buildInputs =
(fnBuildInputs pkgs)
++ (with pkgs;
lib.optionals stdenv.isDarwin
[
darwin.apple_sdk.frameworks.CoreFoundation
darwin.apple_sdk.frameworks.CoreServices
darwin.apple_sdk.frameworks.SystemConfiguration
darwin.apple_sdk.frameworks.Security
]);
};
packages.x86_64-unknown-linux-musl = naerskBuildPackageT "x86_64-unknown-linux-musl" {
src = ./.;
#doCheck = true;
nativeBuildInputs = with pkgs; [pkgsStatic.stdenv.cc];
buildInputs = fnBuildInputs pkgs.pkgsCross.musl64.pkgsStatic;
};
packages.aarch64-unknown-linux-musl = with pkgs.pkgsCross.aarch64-multiplatform-musl;
naerskBuildPackageT "aarch64-unknown-linux-musl" {
src = ./.;
strictDeps = true;
#doCheck = true;
depsBuildBuild = [
stdenv.cc
];
"CC_aarch64_unknown_linux_musl" = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER" = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
buildInputs = fnBuildInputs pkgsStatic;
};
packages.x86_64-pc-windows-gnu = naerskBuildPackageT "x86_64-pc-windows-gnu" {
src = ./.;
strictDeps = true;
#doCheck = true;
depsBuildBuild = with pkgs; [
pkgsCross.mingwW64.stdenv.cc
pkgsCross.mingwW64.windows.pthreads
];
nativeBuildInputs = with pkgs; [
# We need Wine to run tests:
wineWowPackages.stable
];
buildInputs = fnBuildInputs pkgs.pkgsCross.mingwW64;
};
devShell = pkgs.mkShell (
{
inputsFrom = [defaultPackage];
packages = shellPkgs;
#CARGO_BUILD_TARGET = "x86_64-unknown-linux-gnu";
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath (fnBuildInputs pkgs)}";
}
// cargoConfig
);
}
);
}