-
Notifications
You must be signed in to change notification settings - Fork 20
/
Dockerfile
168 lines (139 loc) · 5.11 KB
/
Dockerfile
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
FROM debian:buster-slim
# -------------------------------------------------------------------
# Toolchain Version Config
# -------------------------------------------------------------------
# Espressif toolchain
ARG ESP_VERSION="1.22.0-80-g6c4433a-5.2.0"
# esp-idf framework
ARG IDF_VERSION="v3.3-beta3"
# llvm-xtensa
ARG CLANG_VERSION="248d9ce8765248d953c3e5ef4022fb350bbe6c51"
ARG LLVM_VERSION="757e18f722dbdcd98b8479e25041b1eee1128ce9"
# rust-xtensa
ARG RUSTC_VERSION="b365cff41a60df8fd5f1237ef71897edad0375dd"
# -------------------------------------------------------------------
# Toolchain Path Config
# -------------------------------------------------------------------
ARG TOOLCHAIN="/home/esp32-toolchain"
ARG ESP_BASE="${TOOLCHAIN}/esp"
ENV ESP_PATH "${ESP_BASE}/esp-toolchain"
ENV IDF_PATH "${ESP_BASE}/esp-idf"
ARG LLVM_BASE="${TOOLCHAIN}/llvm"
ARG LLVM_PATH="${LLVM_BASE}/llvm_xtensa"
ARG LLVM_BUILD_PATH="${LLVM_BASE}/llvm_build"
ARG LLVM_INSTALL_PATH="${LLVM_BASE}/llvm_install"
ARG RUSTC_BASE="${TOOLCHAIN}/rustc"
ARG RUSTC_PATH="${RUSTC_BASE}/rust_xtensa"
ARG RUSTC_BUILD_PATH="${RUSTC_BASE}/rust_build"
ENV PATH "/root/.cargo/bin:${ESP_PATH}/bin:${PATH}"
# -------------------------------------------------------------------
# Install expected depdendencies
# -------------------------------------------------------------------
RUN apt-get update \
&& apt-get install -y \
bison \
cmake \
curl \
flex \
g++ \
gcc \
git \
gperf \
libncurses-dev \
make \
ninja-build \
python \
python-pip \
wget \
&& rm -rf /var/lib/apt/lists/*
# -------------------------------------------------------------------
# Setup esp32 toolchain
# -------------------------------------------------------------------
WORKDIR "${ESP_BASE}"
RUN curl \
--proto '=https' \
--tlsv1.2 \
-sSf \
-o "${ESP_PATH}.tar.gz" \
"https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-${ESP_VERSION}.tar.gz" \
&& mkdir "${ESP_PATH}" \
&& tar -xzf "${ESP_PATH}.tar.gz" -C "${ESP_PATH}" --strip-components 1 \
&& rm -rf "${ESP_PATH}.tar.gz"
# -------------------------------------------------------------------
# Setup esp-idf
# -------------------------------------------------------------------
WORKDIR "${ESP_BASE}"
RUN git clone \
--recursive --single-branch -b "${IDF_VERSION}" \
https://github.com/espressif/esp-idf.git \
&& pip install --user -r "${IDF_PATH}/requirements.txt"
# -------------------------------------------------------------------
# Build llvm-xtensa
# -------------------------------------------------------------------
WORKDIR "${LLVM_BASE}"
RUN mkdir "${LLVM_PATH}" \
&& cd "${LLVM_PATH}" \
&& git init \
&& git remote add origin https://github.com/espressif/llvm-xtensa.git \
&& git fetch --depth 1 origin "${LLVM_VERSION}" \
&& git checkout FETCH_HEAD \
&& mkdir -p "${LLVM_PATH}/tools/clang" \
&& cd "${LLVM_PATH}/tools/clang" \
&& git init \
&& git remote add origin https://github.com/espressif/clang-xtensa.git \
&& git fetch --depth 1 origin "${CLANG_VERSION}" \
&& git checkout FETCH_HEAD \
&& mkdir -p "${LLVM_BUILD_PATH}" \
&& cd "${LLVM_BUILD_PATH}" \
&& cmake "${LLVM_PATH}" \
-DLLVM_TARGETS_TO_BUILD="Xtensa;X86" \
-DLLVM_INSTALL_UTILS=ON \
-DLLVM_BUILD_TESTS=0 \
-DLLVM_INCLUDE_TESTS=0 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${LLVM_BASE}/llvm_install" \
-DCMAKE_CXX_FLAGS="-w" \
-G "Ninja" \
&& ninja install \
&& rm -rf "${LLVM_PATH}" "${LLVM_BUILD_PATH}"
# -------------------------------------------------------------------
# Build rust-xtensa
# -------------------------------------------------------------------
WORKDIR "${RUSTC_BASE}"
RUN git clone \
--recursive --single-branch \
https://github.com/MabezDev/rust-xtensa.git \
"${RUSTC_PATH}" \
&& mkdir -p "${RUSTC_BUILD_PATH}" \
&& cd "${RUSTC_PATH}" \
&& git reset --hard "${RUSTC_VERSION}" \
&& ./configure \
--llvm-root "${LLVM_INSTALL_PATH}" \
--prefix "${RUSTC_BUILD_PATH}" \
&& python ./x.py build \
&& python ./x.py install
# -------------------------------------------------------------------
# Setup rustup toolchain
# -------------------------------------------------------------------
RUN curl \
--proto '=https' \
--tlsv1.2 \
-sSf \
https://sh.rustup.rs \
| sh -s -- -y --default-toolchain stable \
&& rustup component add rustfmt \
&& rustup toolchain link xtensa "${RUSTC_BUILD_PATH}" \
&& cargo install cargo-xbuild bindgen
# -------------------------------------------------------------------
# Our Project
# -------------------------------------------------------------------
ENV PROJECT="/home/project/"
ENV XARGO_RUST_SRC="${RUSTC_PATH}/src"
ENV TEMPLATES="${TOOLCHAIN}/templates"
ENV LIBCLANG_PATH="${LLVM_INSTALL_PATH}/lib"
ENV CARGO_HOME="${PROJECT}target/cargo"
VOLUME "${PROJECT}"
WORKDIR "${PROJECT}"
COPY bindgen-project build-project create-project image-project xbuild-project flash-project /usr/local/bin/
COPY templates/ "${TEMPLATES}"
CMD ["/usr/local/bin/build-project"]