-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathsdk.nix
More file actions
204 lines (173 loc) · 4.49 KB
/
Copy pathsdk.nix
File metadata and controls
204 lines (173 loc) · 4.49 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
sdk':
let
inherit (sdk') version;
baseURL = "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${version}";
getToolchainPlatform =
stdenv:
let
gnuPrefix = (if builtins.compareVersions version "1.0.0" >= 0 then "gnu_" else "");
in
if stdenv.isLinux then
"${gnuPrefix}linux"
else if stdenv.isDarwin then
"${gnuPrefix}macos"
else
throw "Unsupported platform";
getPlatform =
stdenv:
if stdenv.isLinux then
"linux"
else if stdenv.isDarwin then
"macos"
else
throw "Unsupported platform";
getArch =
stdenv:
if stdenv.isAarch64 then
"aarch64"
else if stdenv.isx86_64 then
"x86_64"
else
throw "Unsupported arch";
fetchSDKFile' =
fetchurl: file:
fetchurl {
url = "${baseURL}/${file}";
sha256 = sdk'.files.${file};
};
in
{
lib,
python3,
newScope,
ncurses,
libxcrypt-legacy,
}:
lib.makeScope newScope (self: let
inherit (self) callPackage;
in {
# Pre-packaged Zephyr SDK.
sdk =
callPackage ({
stdenv,
which,
cmake,
autoPatchelfHook,
python3,
fetchurl,
lib,
targets ? [ ],
}:
let
toolchainPlatform = getToolchainPlatform stdenv;
platform = getPlatform stdenv;
arch = getArch stdenv;
fetchSDKFile = fetchSDKFile' fetchurl;
in
stdenv.mkDerivation {
pname = "zephyr-sdk";
inherit version;
srcs = [
(fetchSDKFile "zephyr-sdk-${version}_${platform}-${arch}_minimal.tar.xz")
] ++ map fetchSDKFile (map (target: "toolchain_${toolchainPlatform}-${arch}_${target}.tar.xz") targets);
passthru = {
inherit platform arch targets;
};
nativeBuildInputs = [
which
cmake
] ++ lib.optional (!stdenv.isDarwin) autoPatchelfHook;
buildInputs = [
stdenv.cc.cc
python3
ncurses
libxcrypt-legacy
];
dontBuild = true;
dontUseCmakeConfigure = true;
sourceRoot = ".";
installPhase = ''
runHook preInstall
rm -f zephyr-sdk-$version/zephyr-sdk-${arch}-hosttools-standalone-*.sh
rm -f env-vars
mv zephyr-sdk-$version $out
if [ -n "$(ls -A .)" ]; then
${if builtins.compareVersions version "1.0.0" >= 0 then ''
mkdir -p $out/gnu
# Move gnu toolchains
for item in *-*zephyr-*; do
[ -e "$item" ] && mv "$item" $out/gnu/
done
# Move any remaining items
for item in *; do
[ -e "$item" ] && mv "$item" $out/ || true
done
'' else ''
mv * $out
''}
fi
mkdir -p $out/nix-support
cat <<EOF >> $out/nix-support/setup-hook
export ZEPHYR_SDK_INSTALL_DIR=$out
EOF
runHook postInstall
'';
}) {
inherit python3;
};
# SDK with all targets selected
sdkFull =
let
toolchainPlatform = getToolchainPlatform self.sdk.stdenv;
inherit (self.sdk.passthru) arch;
mToolchain = builtins.match "toolchain_${toolchainPlatform}-${arch}_(.+)\.tar\.xz";
allTargets =
builtins.concatMap
(filename: let
m = mToolchain filename;
in
if m == null then [ ]
else [
(builtins.head m)
]
)
(lib.attrNames sdk'.files);
in
self.sdk.override {
targets = allTargets;
};
# Binary host tools provided by the Zephyr project.
hosttools =
callPackage ({
stdenv,
which,
autoPatchelfHook,
python3,
lib,
fetchurl,
}:
let
platform = getPlatform stdenv;
arch = getArch stdenv;
fetchSDKFile = fetchSDKFile' fetchurl;
in
stdenv.mkDerivation {
pname = "zephyr-sdk-hosttools";
inherit version;
src = fetchSDKFile "hosttools_${platform}-${arch}.tar.xz";
nativeBuildInputs = [ which ] ++ lib.optional (!stdenv.isDarwin) autoPatchelfHook;
buildInputs = [ python3 ];
dontBuild = true;
dontFixup = true;
sourceRoot = ".";
installPhase = ''
runHook preInstall
mkdir -p $out/usr/share/zephyr/hosttools
./zephyr-sdk-${arch}-hosttools-standalone-*.sh -d $out/usr/share/zephyr/hosttools
ln -s $out/usr/share/zephyr/hosttools/sysroots/${arch}-pokysdk-${platform}/usr/bin $out/bin
runHook postInstall
'';
}) {
inherit python3;
};
})