generated from lf-lang/lf-riot-uc-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.nix
109 lines (96 loc) · 3.31 KB
/
shell.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
{ pkgs }:
let
arm-pkgs = pkgs.pkgsCross.armhf-embedded;
buildPackages = arm-pkgs.buildPackages;
newlib-nano = arm-pkgs.stdenv.mkDerivation (finalAttrs: {
pname = "newlib";
version = "4.3.0.20230120";
src = pkgs.fetchurl {
url = "ftp://sourceware.org/pub/newlib/newlib-${finalAttrs.version}.tar.gz";
sha256 = "sha256-g6Yqma9Z4465sMWO0JLuJNcA//Q6IsA+QzlVET7zUVA=";
};
patches = [
# https://bugs.gentoo.org/723756
(pkgs.fetchpatch {
name = "newlib-3.3.0-no-nano-cxx.patch";
url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/sys-libs/newlib/files/newlib-3.3.0-no-nano-cxx.patch?id=9ee5a1cd6f8da6d084b93b3dbd2e8022a147cfbf";
sha256 = "sha256-S3mf7vwrzSMWZIGE+d61UDH+/SK/ao1hTPee1sElgco=";
})
];
depsBuildBuild = [
buildPackages.stdenv.cc
pkgs.texinfo
];
preConfigure =
''
export CC=cc
substituteInPlace configure --replace 'noconfigdirs target-newlib target-libgloss' 'noconfigdirs'
substituteInPlace configure --replace 'cross_only="target-libgloss target-newlib' 'cross_only="'
'';
configurePlatforms = [
"build"
"target"
];
configureFlags =
[
"--with-newlib"
"--host=${arm-pkgs.targetPlatform.config}"
"--disable-newlib-fseek-optimization"
"--disable-newlib-fvwrite-in-streamio"
"--disable-newlib-supplied-syscalls"
"--disable-newlib-unbuf-stream-opt"
"--disable-newlib-wide-orient"
"--disable-nls"
"--enable-lite-exit"
"--enable-newlib-global-atexit"
"--enable-newlib-nano-formatted-io"
"--enable-newlib-nano-malloc"
"--enable-newlib-reent-check-verify"
"--enable-newlib-reent-small"
"--enable-newlib-retargetable-locking"
];
enableParallelBuilding = true;
dontDisableStatic = true;
postInstall = ''
mkdir -p $out${finalAttrs.passthru.incdir}/newlib-nano
cp $out${finalAttrs.passthru.incdir}/newlib.h $out${finalAttrs.passthru.incdir}/newlib-nano/
(
cd $out${finalAttrs.passthru.libdir}
for f in librdimon.a libc.a libg.a; do
# Some libraries are only available for specific architectures.
# For example, librdimon.a is only available on ARM.
echo $f
echo "=========================================================="
[ -f "$f" ] && cp "$f" "''${f%%\.a}_nano.a"
done
)
''
+ ''[ "$(find $out -type f | wc -l)" -gt 0 ] || (echo '$out is empty' 1>&2 && exit 1)'';
passthru = {
incdir = "/${arm-pkgs.targetPlatform.config}/include";
libdir = "/${arm-pkgs.targetPlatform.config}/lib";
};
meta = with pkgs.lib; {
description = "C library intended for use on embedded systems";
homepage = "https://sourceware.org/newlib/";
license = licenses.gpl2Plus;
};
});
in
pkgs.mkShell {
buildInputs = with pkgs; [
pkg-config
gnumake
openocd
python312Packages.pyserial
buildPackages.gcc-arm-embedded
buildPackages.binutils
buildPackages.libcCross
newlib-nano
];
shellHook = ''
export REACTOR_UC_PATH=../reactor-uc
export OBJDUMP=${buildPackages.gcc-arm-embedded}/arm-none-eabi/bin/objdump
export OBJCOPY=${buildPackages.gcc-arm-embedded}/arm-none-eabi/bin/objcopy
'';
}