Skip to content

Commit

Permalink
Provide build example
Browse files Browse the repository at this point in the history
  • Loading branch information
taraspos committed Feb 17, 2024
1 parent e2bbc42 commit 2de5313
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Binaries
example/example
example/main
example/build
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ import "github.com/shermp/go-fbink-v2/gofbink"
```
Note, you will need to enable cgo support when building your project, by setting the `CGO_ENABLED=1` environment variable when building, along with setting the `CC` and `CXX` environment variables to your ARM toolchain's GCC and G++ paths respectively, as well as setting the proper target architecture with `GOARCH=arm`.

A simple example program has been provided in `example/main.go`
A simple example program has been provided in [`example/`](./example/)

You can refer to the original documentation found in the `fbink.h` file, which can be found at `gofbink/fbink.h`.

The primary usage difference from FBInk is that where appropriate, go-fbink returns an error, or nil, rather than an integer to indicate success or failure. Note that the error string contains the C error code name (eg: "EXIT_FAILURE").

The only function that is unavailable in go-fbink is `fbink_printf()`. This is because cgo does not support variadic parameters. So, if that functionality is required, a simple `s := fmt.Sprintf("String %d", 1)` should do the trick...


11 changes: 11 additions & 0 deletions example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.22

RUN apt update && apt install -y unzip
RUN curl -sSL -o /tmp/kobo-tc.zip https://github.com/koreader/koxtoolchain/releases/download/2021.12/kobo.zip && \
cd /tmp && \
unzip /tmp/kobo-tc.zip && \
tar -xzvf /tmp/kobo.tar.gz -C /opt/ && \
rm -rf /tmp/kobo*

ENV PATH=/opt/x-tools/arm-kobo-linux-gnueabihf/bin:$PATH
ENV CROSS_COMPILE=arm-kobo-linux-gnueabihf
15 changes: 15 additions & 0 deletions example/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: default
default: build.docker ;

.PHONY: build
build: export GOOS=linux
build: export GOARCH=arm
build: export CGO_ENABLED=1
build: export CC=${CROSS_COMPILE}-gcc
build: export CXX=${CROSS_COMPILE}-g++
build:
go build -o build/app main.go

build.docker:
docker build -t go-fbink-build .
docker run -it --rm -v $(PWD)/..:/go/src/app --workdir /go/src/app/example go-fbink-build make build
8 changes: 8 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Build example

[koxtoolchain is recommended](https://github.com/shermp/go-fbink-v2/issues/13#issuecomment-894638113) for ARM cross-compilation.

- Run `make` to build this example application using docker
- See [`main.go`](./main.go) for example usage of go-fbink-v2
- See [`Dockerfile`](./Dockerfile) for build environment configuration
- See [`Makefile`](./Makefile) for build commands

0 comments on commit 2de5313

Please sign in to comment.