all: add support to Dockerfile for AVR and ARM targets
Signed-off-by: Ron Evans <ron@hybridgroup.com>
Этот коммит содержится в:
родитель
668c1741c3
коммит
ae3535945c
2 изменённых файлов: 76 добавлений и 8 удалений
66
Dockerfile
66
Dockerfile
|
@ -1,4 +1,5 @@
|
||||||
FROM golang:latest
|
# TinyGo base stage just installs LLVM 7 and the TinyGo compiler itself.
|
||||||
|
FROM golang:latest AS tinygo-base
|
||||||
|
|
||||||
RUN wget -O- https://apt.llvm.org/llvm-snapshot.gpg.key| apt-key add - && \
|
RUN wget -O- https://apt.llvm.org/llvm-snapshot.gpg.key| apt-key add - && \
|
||||||
echo "deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch-7 main" >> /etc/apt/sources.list && \
|
echo "deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch-7 main" >> /etc/apt/sources.list && \
|
||||||
|
@ -13,15 +14,68 @@ RUN cd /go/src/github.com/aykevl/tinygo/ && \
|
||||||
dep ensure --vendor-only && \
|
dep ensure --vendor-only && \
|
||||||
go install /go/src/github.com/aykevl/tinygo/
|
go install /go/src/github.com/aykevl/tinygo/
|
||||||
|
|
||||||
FROM golang:latest
|
ENTRYPOINT ["/go/bin/tinygo"]
|
||||||
|
|
||||||
COPY --from=0 /go/bin/tinygo /go/bin/tinygo
|
# tinygo-wasm stage installs the needed dependencies to compile TinyGo programs for WASM.
|
||||||
COPY --from=0 /go/src/github.com/aykevl/tinygo/src /go/src/github.com/aykevl/tinygo/src
|
FROM tinygo-base AS tinygo-wasm
|
||||||
COPY --from=0 /go/src/github.com/aykevl/tinygo/targets /go/src/github.com/aykevl/tinygo/targets
|
|
||||||
|
COPY --from=tinygo-base /go/bin/tinygo /go/bin/tinygo
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/src /go/src/github.com/aykevl/tinygo/src
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/targets /go/src/github.com/aykevl/tinygo/targets
|
||||||
|
|
||||||
RUN wget -O- https://apt.llvm.org/llvm-snapshot.gpg.key| apt-key add - && \
|
RUN wget -O- https://apt.llvm.org/llvm-snapshot.gpg.key| apt-key add - && \
|
||||||
echo "deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch-7 main" >> /etc/apt/sources.list && \
|
echo "deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch-7 main" >> /etc/apt/sources.list && \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y libllvm7 lld-7
|
apt-get install -y libllvm7 lld-7
|
||||||
|
|
||||||
ENTRYPOINT ["/go/bin/tinygo"]
|
# tinygo-avr stage installs the needed dependencies to compile TinyGo programs for AVR microcontrollers.
|
||||||
|
FROM tinygo-base AS tinygo-avr
|
||||||
|
|
||||||
|
COPY --from=tinygo-base /go/bin/tinygo /go/bin/tinygo
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/src /go/src/github.com/aykevl/tinygo/src
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/targets /go/src/github.com/aykevl/tinygo/targets
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/Makefile /go/src/github.com/aykevl/tinygo/
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/tools /go/src/github.com/aykevl/tinygo/tools
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/lib /go/src/github.com/aykevl/tinygo/lib
|
||||||
|
|
||||||
|
RUN cd /go/src/github.com/aykevl/tinygo/ && \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y apt-utils python3 make binutils-avr gcc-avr avr-libc && \
|
||||||
|
make gen-device-avr && \
|
||||||
|
apt-get remove -y python3 make && \
|
||||||
|
apt-get autoremove -y && \
|
||||||
|
apt-get clean
|
||||||
|
|
||||||
|
# tinygo-arm stage installs the needed dependencies to compile TinyGo programs for ARM microcontrollers.
|
||||||
|
FROM tinygo-base AS tinygo-arm
|
||||||
|
|
||||||
|
COPY --from=tinygo-base /go/bin/tinygo /go/bin/tinygo
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/src /go/src/github.com/aykevl/tinygo/src
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/targets /go/src/github.com/aykevl/tinygo/targets
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/Makefile /go/src/github.com/aykevl/tinygo/
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/tools /go/src/github.com/aykevl/tinygo/tools
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/lib /go/src/github.com/aykevl/tinygo/lib
|
||||||
|
|
||||||
|
RUN cd /go/src/github.com/aykevl/tinygo/ && \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y apt-utils python3 make gcc-arm-none-eabi clang-7 && \
|
||||||
|
make gen-device-nrf && make gen-device-stm32 && \
|
||||||
|
apt-get remove -y python3 make && \
|
||||||
|
apt-get autoremove -y && \
|
||||||
|
apt-get clean
|
||||||
|
|
||||||
|
# tinygo-all stage installs the needed dependencies to compile TinyGo programs for all platforms.
|
||||||
|
FROM tinygo-wasm AS tinygo-all
|
||||||
|
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/Makefile /go/src/github.com/aykevl/tinygo/
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/tools /go/src/github.com/aykevl/tinygo/tools
|
||||||
|
COPY --from=tinygo-base /go/src/github.com/aykevl/tinygo/lib /go/src/github.com/aykevl/tinygo/lib
|
||||||
|
|
||||||
|
RUN cd /go/src/github.com/aykevl/tinygo/ && \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y apt-utils python3 make gcc-arm-none-eabi clang-7 binutils-avr gcc-avr avr-libc && \
|
||||||
|
make gen-device && \
|
||||||
|
apt-get remove -y python3 make && \
|
||||||
|
apt-get autoremove -y && \
|
||||||
|
apt-get clean
|
||||||
|
|
||||||
|
|
|
@ -11,5 +11,19 @@ repository::
|
||||||
|
|
||||||
docker run --rm -v $(pwd):/src tinygo/tinygo build -o /src/wasm.wasm -target wasm examples/wasm
|
docker run --rm -v $(pwd):/src tinygo/tinygo build -o /src/wasm.wasm -target wasm examples/wasm
|
||||||
|
|
||||||
Note that you cannot run ``tinygo flash`` from inside the docker container,
|
To compile ``blinky1.hex`` targeting an ARM microcontroller, such as the PCA10040::
|
||||||
so it is less useful for microcontroller development.
|
|
||||||
|
docker run --rm -v $(pwd):/src tinygo/tinygo build -o /src/blinky1.hex -size=short -target=pca10040 examples/blinky1
|
||||||
|
|
||||||
|
To compile ``blinky1.hex`` targeting an AVR microcontroller such as the Arduino::
|
||||||
|
|
||||||
|
docker run --rm -v $(pwd):/src tinygo/tinygo build -o /src/blinky1.hex -size=short -target=arduino examples/blinky1
|
||||||
|
|
||||||
|
Note that for microcontroller development you must flash your hardware devices
|
||||||
|
from your host environment, since you cannot run ``tinygo flash`` from inside
|
||||||
|
the docker container.
|
||||||
|
|
||||||
|
So your workflow could be:
|
||||||
|
|
||||||
|
- Compile TinyGo code using the Docker container into a HEX file.
|
||||||
|
- Flash the HEX file from your host environment to the target microcontroller.
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче