I recently wanted to learn golang, as it seems like a rather good choice in term of size, speed and supported architecure to build against. While I was embarking on the journey to learn the basics it struck me that it would be nice to build some small apps for my old kobo, which I have mentioned in earlier posts. After some research ( because I didn’t want to reinvent the wheel) I came across Koreader.
The Koreader project does build for Kobo, and they have a docker for this specific reason, so we can use it as a base. It has everything set to build C source code. To make that work for us I tinkered with it in order to build go projects as well into static binaries. Here is an early version of the base Dockerfile for our builder:
FROM koreader/kokobo:0.2.2
#First install golang
ARG GOLANG_VERSION=1.17.3
USER root
RUN apt update && apt install -y bash musl-dev libssl-dev ca-certificates && update-ca-certificates
USER ko
WORKDIR /home/ko
RUN wget https://dl.google.com/go/go$GOLANG_VERSION.linux-amd64.tar.gz && tar -C /home/ko -xzf go$GOLANG_VERSION.linux-amd64.tar.gz && rm /home/ko/go$GOLANG_VERSION.linux-amd64.tar.gz
RUN mkdir -p /home/ko/src
# SET our environment to build against this target architecture
ENV GOROOT=/home/ko/go \
GOPATH=/home/ko/src/ \
PATH=$PATH:/home/ko/go/bin \
CC=arm-linux-gnueabihf-gcc \
CXX=arm-linux-gnueabihf-g++ \
GOOS=linux \
GOARCH=arm \
CGO_ENABLED=1
#SET our workdir where our source code will go.
WORKDIR /home/ko/src
Running a simple sudo docker build -t kokobogo
will give us a Docker image as our foundation. Next lets enter the directory where our source code is and then run sudo docker run -ti -v $PWD:/home/ko/src kokobogo bash
And here we are in a restricted bash, where we can run a simple go mod download && go build
and in the same directory our static binary appears. Of course later on we will need to resolve some permissions issues. However we have a working build environment for ourselves, which can even be turned into a nice CL/CI pipeline to produce binaries.
Above all that on the kobo we need components to write things on the screen and understand the inputs from the touchscreen. For that we have two projects. For the input we have the project shermp/go-kobo-input and for displaying things we have NiLuJe/FBInk. The only downside of the FBInk project that it has no golang implementation. (A workaround later can be using the C library or just calling cli binary). So with these two projects and with the whole pipeline, we have a pretty high success rate to make some interesting applications for our old kobo device. Hopefully by the end of 2022Q1 I will be able to publish some example skeleton codes and docker images for building for the kobo devices which can be easy to use. At this point it seems challenging, as I would need to bake in the FBink C library into my projects.