Skip to content

Commit 6668d70

Browse files
committed
sdk: Prepare for split LTS & latest release manifests
1 parent fceaebe commit 6668d70

File tree

3 files changed

+178
-142
lines changed

3 files changed

+178
-142
lines changed

default.nix

Lines changed: 6 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,162 +1,30 @@
11
{ zephyr-src
22
, pyproject-nix
33
, lib
4-
, fetchurl
5-
, python310
64
, newScope
75
, openocd
86
, gcc_multi
97
, autoreconfHook
108
, fetchFromGitHub
9+
, pkgs
1110
}:
1211

13-
let
14-
sdk' = lib.importJSON ./sdk.json;
15-
inherit (sdk') version;
16-
17-
getPlatform = stdenv:
18-
if stdenv.isLinux then "linux"
19-
else if stdenv.isDarwin then "macos"
20-
else throw "Unsupported platform";
21-
22-
getArch = stdenv:
23-
if stdenv.isAarch64 then "aarch64"
24-
else if stdenv.isx86_64 then "x86_64"
25-
else throw "Unsupported arch";
26-
27-
baseURL = "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${version}";
28-
29-
fetchSDKFile = file: fetchurl {
30-
url = "${baseURL}/${file}";
31-
sha256 = sdk'.files.${file};
32-
};
12+
lib.makeScope newScope (self: let
13+
inherit (self) callPackage;
3314

34-
sdkArgs = {
35-
python3 = python310;
15+
sdk = callPackage (import ./sdk.nix (lib.importJSON ./sdk.json)) {
16+
python3 = pkgs.python310;
3617
};
3718

38-
in
39-
lib.makeScope newScope (self: let
40-
inherit (self) callPackage;
4119
in {
20+
inherit (sdk) sdk sdkFull hosttools;
4221

4322
# Zephyr/west Python environment.
4423
pythonEnv = callPackage ./python.nix {
4524
inherit zephyr-src;
4625
inherit pyproject-nix;
4726
};
4827

49-
# Pre-package Zephyr SDK.
50-
sdk = callPackage
51-
({ stdenv
52-
, which
53-
, cmake
54-
, autoPatchelfHook
55-
, libxcrypt-legacy
56-
, ncurses
57-
, python3
58-
, targets ? [ ]
59-
}:
60-
let
61-
platform = getPlatform stdenv;
62-
arch = getArch stdenv;
63-
in
64-
stdenv.mkDerivation {
65-
pname = "zephyr-sdk";
66-
inherit version;
67-
68-
srcs = [
69-
(fetchSDKFile "zephyr-sdk-${version}_${platform}-${arch}_minimal.tar.xz")
70-
] ++ map fetchSDKFile (map (target: "toolchain_${platform}-${arch}_${target}.tar.xz") targets);
71-
72-
passthru = {
73-
inherit platform arch targets;
74-
};
75-
76-
nativeBuildInputs =
77-
[ which cmake ]
78-
++ lib.optional (!stdenv.isDarwin) autoPatchelfHook
79-
;
80-
81-
buildInputs = [ stdenv.cc.cc ncurses libxcrypt-legacy python3 ];
82-
83-
dontBuild = true;
84-
dontUseCmakeConfigure = true;
85-
86-
sourceRoot = ".";
87-
88-
installPhase = ''
89-
runHook preInstall
90-
91-
rm -f zephyr-sdk-$version/zephyr-sdk-${arch}-hosttools-standalone-*.sh
92-
rm -f env-vars
93-
94-
mv zephyr-sdk-$version $out
95-
96-
if [ -n "$(ls -A .)" ]; then
97-
mv * $out
98-
fi
99-
100-
mkdir -p $out/nix-support
101-
cat <<EOF >> $out/nix-support/setup-hook
102-
export ZEPHYR_SDK_INSTALL_DIR=$out
103-
EOF
104-
105-
runHook postInstall
106-
'';
107-
})
108-
sdkArgs;
109-
110-
# # SDK with all targets selected
111-
sdkFull =
112-
let
113-
inherit (self.sdk.passthru) platform arch;
114-
mToolchain = builtins.match "toolchain_${platform}-${arch}_(.+)\.tar\.xz";
115-
allTargets = map (x: builtins.head (mToolchain x)) (builtins.filter (f: mToolchain f != null) (lib.attrNames sdk'.files));
116-
in
117-
self.sdk.override {
118-
targets = allTargets;
119-
};
120-
121-
# Binary host tools provided by the Zephyr project.
122-
hosttools = callPackage
123-
({ stdenv
124-
, which
125-
, autoPatchelfHook
126-
, python3
127-
}:
128-
let
129-
platform = getPlatform stdenv;
130-
arch = getArch stdenv;
131-
in
132-
stdenv.mkDerivation {
133-
pname = "zephyr-sdk-hosttools";
134-
inherit version;
135-
136-
src = fetchSDKFile "hosttools_${platform}-${arch}.tar.xz";
137-
138-
nativeBuildInputs =
139-
[ which ]
140-
++ lib.optional (!stdenv.isDarwin) autoPatchelfHook
141-
;
142-
143-
buildInputs = [ python3 ];
144-
145-
dontBuild = true;
146-
dontFixup = true;
147-
148-
sourceRoot = ".";
149-
150-
installPhase = ''
151-
runHook preInstall
152-
mkdir -p $out/usr/share/zephyr/hosttools
153-
./zephyr-sdk-${arch}-hosttools-standalone-*.sh -d $out/usr/share/zephyr/hosttools
154-
ln -s $out/usr/share/zephyr/hosttools/sysroots/${arch}-pokysdk-${platform}/usr/bin $out/bin
155-
runHook postInstall
156-
'';
157-
})
158-
sdkArgs;
159-
16028
openocd-zephyr = openocd.overrideAttrs(old: let
16129
pname = "openocd-zephyr";
16230
version = "20220611";

sdk.nix

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
sdk':
2+
let
3+
inherit (sdk') version;
4+
5+
baseURL = "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${version}";
6+
7+
getPlatform =
8+
stdenv:
9+
if stdenv.isLinux then
10+
"linux"
11+
else if stdenv.isDarwin then
12+
"macos"
13+
else
14+
throw "Unsupported platform";
15+
16+
getArch =
17+
stdenv:
18+
if stdenv.isAarch64 then
19+
"aarch64"
20+
else if stdenv.isx86_64 then
21+
"x86_64"
22+
else
23+
throw "Unsupported arch";
24+
25+
fetchSDKFile' =
26+
fetchurl: file:
27+
fetchurl {
28+
url = "${baseURL}/${file}";
29+
sha256 = sdk'.files.${file};
30+
};
31+
32+
in
33+
{
34+
lib,
35+
python3,
36+
newScope,
37+
ncurses,
38+
libxcrypt-legacy,
39+
}:
40+
lib.makeScope newScope (self: let
41+
inherit (self) callPackage;
42+
in {
43+
44+
# Pre-packaged Zephyr SDK.
45+
sdk =
46+
callPackage ({
47+
stdenv,
48+
which,
49+
cmake,
50+
autoPatchelfHook,
51+
python3,
52+
fetchurl,
53+
lib,
54+
targets ? [ ],
55+
}:
56+
let
57+
platform = getPlatform stdenv;
58+
arch = getArch stdenv;
59+
60+
fetchSDKFile = fetchSDKFile' fetchurl;
61+
62+
in
63+
stdenv.mkDerivation {
64+
pname = "zephyr-sdk";
65+
inherit version;
66+
67+
srcs = [
68+
(fetchSDKFile "zephyr-sdk-${version}_${platform}-${arch}_minimal.tar.xz")
69+
] ++ map fetchSDKFile (map (target: "toolchain_${platform}-${arch}_${target}.tar.xz") targets);
70+
71+
passthru = {
72+
inherit platform arch targets;
73+
};
74+
75+
nativeBuildInputs = [
76+
which
77+
cmake
78+
] ++ lib.optional (!stdenv.isDarwin) autoPatchelfHook;
79+
80+
buildInputs = [
81+
stdenv.cc.cc
82+
python3
83+
ncurses
84+
libxcrypt-legacy
85+
];
86+
87+
dontBuild = true;
88+
dontUseCmakeConfigure = true;
89+
90+
sourceRoot = ".";
91+
92+
installPhase = ''
93+
runHook preInstall
94+
95+
rm -f zephyr-sdk-$version/zephyr-sdk-${arch}-hosttools-standalone-*.sh
96+
rm -f env-vars
97+
98+
mv zephyr-sdk-$version $out
99+
100+
if [ -n "$(ls -A .)" ]; then
101+
mv * $out
102+
fi
103+
104+
mkdir -p $out/nix-support
105+
cat <<EOF >> $out/nix-support/setup-hook
106+
export ZEPHYR_SDK_INSTALL_DIR=$out
107+
EOF
108+
109+
runHook postInstall
110+
'';
111+
}) {
112+
inherit python3;
113+
};
114+
115+
# SDK with all targets selected
116+
sdkFull =
117+
let
118+
inherit (self.sdk.passthru) platform arch;
119+
mToolchain = builtins.match "toolchain_${platform}-${arch}_(.+)\.tar\.xz";
120+
allTargets = map (x: builtins.head (mToolchain x)) (builtins.filter (f: mToolchain f != null) (lib.attrNames sdk'.files));
121+
in
122+
self.sdk.override {
123+
targets = allTargets;
124+
};
125+
126+
# Binary host tools provided by the Zephyr project.
127+
hosttools =
128+
callPackage ({
129+
stdenv,
130+
which,
131+
autoPatchelfHook,
132+
python3,
133+
lib,
134+
fetchurl,
135+
}:
136+
let
137+
platform = getPlatform stdenv;
138+
arch = getArch stdenv;
139+
fetchSDKFile = fetchSDKFile' fetchurl;
140+
in
141+
stdenv.mkDerivation {
142+
pname = "zephyr-sdk-hosttools";
143+
inherit version;
144+
145+
src = fetchSDKFile "hosttools_${platform}-${arch}.tar.xz";
146+
147+
nativeBuildInputs = [ which ] ++ lib.optional (!stdenv.isDarwin) autoPatchelfHook;
148+
149+
buildInputs = [ python3 ];
150+
151+
dontBuild = true;
152+
dontFixup = true;
153+
154+
sourceRoot = ".";
155+
156+
installPhase = ''
157+
runHook preInstall
158+
mkdir -p $out/usr/share/zephyr/hosttools
159+
./zephyr-sdk-${arch}-hosttools-standalone-*.sh -d $out/usr/share/zephyr/hosttools
160+
ln -s $out/usr/share/zephyr/hosttools/sysroots/${arch}-pokysdk-${platform}/usr/bin $out/bin
161+
runHook postInstall
162+
'';
163+
}) {
164+
inherit python3;
165+
};
166+
})

update-sdk

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
set -euo pipefail
55

6-
version=$1
6+
# Output file (different output files for LTS & latest SDK)
7+
out=$1
8+
version=$2
79

8-
if [ -z "$version" ]; then
9-
echo "ERROR: missing version argument. For example: ./update-sdk 0.16.6"
10+
if [ -z "$out" ] || [ -z "$version" ]; then
11+
echo "Usage: ./update-sdk sdk.json 0.16.6"
1012
exit 1
1113
fi
1214

1315
curl -L "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v$version/sha256.sum" \
14-
| jq -R -n "[ inputs | split(\" \") | {(.[2]): .[0]} ] | add | { \"files\": ., \"version\": \"$version\"}" > sdk.json
16+
| jq -R -n "[ inputs | split(\" \") | {(.[2]): .[0]} ] | add | { \"files\": ., \"version\": \"$version\"}" > "$out"

0 commit comments

Comments
 (0)