RPi example

This commit is contained in:
Milan Nikolic 2017-02-22 12:11:18 +01:00
parent d066ee87dc
commit 17941ec954
6 changed files with 118 additions and 9 deletions

View file

@ -28,6 +28,10 @@ On OS X system OpenAL framework is used.
[Android example](https://github.com/gen2brain/raylib-go/tree/master/examples/android/example). [Android example](https://github.com/gen2brain/raylib-go/tree/master/examples/android/example).
##### Raspberry Pi
[RPi example](https://github.com/gen2brain/raylib-go/tree/master/examples/rpi/basic_window).
### Installation ### Installation
go get -v github.com/gen2brain/raylib-go/raylib go get -v github.com/gen2brain/raylib-go/raylib

3
examples/README.md Normal file
View file

@ -0,0 +1,3 @@
## Examples
Live (web/emscripten) examples are available on [raylib website](http://www.raylib.com/examples.html).

View file

@ -22,28 +22,28 @@ export PATH=${INSTALL_PREFIX}/android-arm7/bin:${INSTALL_PREFIX}/android-arm64/b
BUILD_DIR=`mktemp -d` BUILD_DIR=`mktemp -d`
mkdir -p ${BUILD_DIR}/bootstrap mkdir -p ${BUILD_DIR}/bootstrap
echo "Make standalone android toolchains" echo "##### Make standalone android toolchains"
${ANDROID_NDK_HOME}/build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=${INSTALL_PREFIX}/android-arm7 --toolchain=arm-linux-androideabi-4.9 ${ANDROID_NDK_HOME}/build/tools/make-standalone-toolchain.sh --platform=android-9 --install-dir=${INSTALL_PREFIX}/android-arm7 --toolchain=arm-linux-androideabi-4.9
${ANDROID_NDK_HOME}/build/tools/make-standalone-toolchain.sh --platform=android-21 --install-dir=${INSTALL_PREFIX}/android-arm64 --toolchain=aarch64-linux-android-4.9 ${ANDROID_NDK_HOME}/build/tools/make-standalone-toolchain.sh --platform=android-21 --install-dir=${INSTALL_PREFIX}/android-arm64 --toolchain=aarch64-linux-android-4.9
echo "Download Go binaries" echo "##### Download Go binaries"
cd ${BUILD_DIR}/bootstrap && curl -s -L http://storage.googleapis.com/golang/${GO_VERSION}.${GO_OS}-${GO_ARCH}.tar.gz | tar xz cd ${BUILD_DIR}/bootstrap && curl -s -L http://storage.googleapis.com/golang/${GO_VERSION}.${GO_OS}-${GO_ARCH}.tar.gz | tar xz
echo "Download Go source" echo "##### Download Go source"
cd ${BUILD_DIR} && curl -s -L http://storage.googleapis.com/golang/${GO_VERSION}.src.tar.gz | tar xz && cd ${BUILD_DIR}/go/src cd ${BUILD_DIR} && curl -s -L http://storage.googleapis.com/golang/${GO_VERSION}.src.tar.gz | tar xz && cd ${BUILD_DIR}/go/src
echo "Compile Go for host" echo "##### Compile Go for host"
GOROOT_BOOTSTRAP=${BUILD_DIR}/bootstrap/go ./make.bash || exit 1 GOROOT_BOOTSTRAP=${BUILD_DIR}/bootstrap/go ./make.bash || exit 1
echo "Compile Go for arm-linux-androideabi" echo "##### Compile Go for arm-linux-androideabi"
GOROOT_BOOTSTRAP=${BUILD_DIR}/bootstrap/go CC_FOR_TARGET=arm-linux-androideabi-gcc GOOS=android GOARCH=arm CGO_ENABLED=1 ./make.bash --no-clean || exit 1 GOROOT_BOOTSTRAP=${BUILD_DIR}/bootstrap/go CC_FOR_TARGET=arm-linux-androideabi-gcc GOOS=android GOARCH=arm CGO_ENABLED=1 ./make.bash --no-clean || exit 1
echo "Compile Go for aarch64-linux-android" echo "##### Compile Go for aarch64-linux-android"
GOROOT_BOOTSTRAP=${BUILD_DIR}/bootstrap/go CC_FOR_TARGET=aarch64-linux-android-gcc GOOS=android GOARCH=arm64 CGO_ENABLED=1 ./make.bash --no-clean || exit 1 GOROOT_BOOTSTRAP=${BUILD_DIR}/bootstrap/go CC_FOR_TARGET=aarch64-linux-android-gcc GOOS=android GOARCH=arm64 CGO_ENABLED=1 ./make.bash --no-clean || exit 1
cp -r -f ${BUILD_DIR}/go ${INSTALL_PREFIX} cp -r -f ${BUILD_DIR}/go ${INSTALL_PREFIX}
echo "Compile OpenAL" echo "##### Compile OpenAL"
cd ${BUILD_DIR} && curl -s -L http://kcat.strangesoft.net/openal-releases/openal-soft-${OPENAL_VERSION}.tar.bz2 | tar -xj cd ${BUILD_DIR} && curl -s -L http://kcat.strangesoft.net/openal-releases/openal-soft-${OPENAL_VERSION}.tar.bz2 | tar -xj
@ -75,7 +75,7 @@ cd ${BUILD_DIR}/openal-soft-${OPENAL_VERSION}/build-arm64
cmake -DLIBTYPE=STATIC -DCMAKE_TOOLCHAIN_FILE=../android-arm64.cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}/android-arm64 .. cmake -DLIBTYPE=STATIC -DCMAKE_TOOLCHAIN_FILE=../android-arm64.cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}/android-arm64 ..
make -j $(nproc) && make install make -j $(nproc) && make install
echo "Compile android_native_app_glue" echo "##### Compile android_native_app_glue"
mkdir -p ${BUILD_DIR}/native_app_glue/jni mkdir -p ${BUILD_DIR}/native_app_glue/jni
cp -r ${ANDROID_NDK_HOME}/sources/android/native_app_glue/* ${BUILD_DIR}/native_app_glue/jni/ cp -r ${ANDROID_NDK_HOME}/sources/android/native_app_glue/* ${BUILD_DIR}/native_app_glue/jni/
@ -89,5 +89,5 @@ cp ${BUILD_DIR}/native_app_glue/obj/local/arm64-v8a/libandroid_native_app_glue.a
cp ${ANDROID_NDK_HOME}/sources/android/native_app_glue/android_native_app_glue.h ${INSTALL_PREFIX}/android-arm7/include/ cp ${ANDROID_NDK_HOME}/sources/android/native_app_glue/android_native_app_glue.h ${INSTALL_PREFIX}/android-arm7/include/
cp ${ANDROID_NDK_HOME}/sources/android/native_app_glue/android_native_app_glue.h ${INSTALL_PREFIX}/android-arm64/include/ cp ${ANDROID_NDK_HOME}/sources/android/native_app_glue/android_native_app_glue.h ${INSTALL_PREFIX}/android-arm64/include/
echo "Remove build directory" echo "##### Remove build directory"
rm -rf ${BUILD_DIR} rm -rf ${BUILD_DIR}

View file

@ -0,0 +1,20 @@
### Raspberry Pi example
To compile example for Raspberry Pi you will need RPi toolchain and userspace libraries, and Go must be cross compiled for linux/arm with that toolchain.
There is a bootstrap.sh script that you can use to cross compile Go and OpenAL.
Compile Go and OpenAL, /usr/local is prefix where Go and RPi toolchain and libraries will be installed:
./bootstrap.sh /usr/local
After build is complete point GOROOT to new Go installation in /usr/local, and add toolchain bin directory to PATH:
export GOROOT=/usr/local/go
export PATH=/usr/local/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:${PATH}
And compile example:
CGO_CFLAGS="-I/usr/local/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/include -I/usr/local/vc/include -I/usr/local/vc/include/interface/vcos -I/usr/local/vc/include/interface/vmcs_host/linux -I/usr/local/vc/include/interface/vcos/pthreads" \
CGO_LDFLAGS="-L/usr/local/vc/lib -L/usr/local/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/lib -ldl" \
CC=arm-linux-gnueabihf-gcc CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=6 ${GOROOT}/bin/go build -v -x

View file

@ -0,0 +1,61 @@
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: bootstrap.sh <install prefix>"
exit 1
fi
GO_OS="linux"
GO_ARCH="amd64"
GO_VERSION=`curl -s https://golang.org/dl/ | grep 'id="go' | head -n1 | awk -F'"' '{print $4}'`
OPENAL_VERSION="1.17.2"
INSTALL_PREFIX="$1"
export PATH=${INSTALL_PREFIX}/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:${PATH}
BUILD_DIR=`mktemp -d`
mkdir -p ${BUILD_DIR}/bootstrap
echo "##### Download toolchain"
cd ${BUILD_DIR} && git clone --depth=1 --branch=master https://github.com/raspberrypi/tools.git
cp -r -f ${BUILD_DIR}/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64 ${INSTALL_PREFIX}
echo "##### Download userspace libraries"
cd ${BUILD_DIR} && git clone --depth=1 --branch=master https://github.com/raspberrypi/firmware.git
cp -r -f ${BUILD_DIR}/firmware/hardfp/opt/vc ${INSTALL_PREFIX}
echo "##### Download Go binaries"
cd ${BUILD_DIR}/bootstrap && curl -s -L http://storage.googleapis.com/golang/${GO_VERSION}.${GO_OS}-${GO_ARCH}.tar.gz | tar xz
echo "##### Download Go source"
cd ${BUILD_DIR} && curl -s -L http://storage.googleapis.com/golang/${GO_VERSION}.src.tar.gz | tar xz && cd ${BUILD_DIR}/go/src
echo "##### Compile Go for host"
GOROOT_BOOTSTRAP=${BUILD_DIR}/bootstrap/go ./make.bash || exit 1
echo "##### Compile Go for arm-linux-gnueabihf"
GOROOT_BOOTSTRAP=${BUILD_DIR}/bootstrap/go CC_FOR_TARGET=arm-linux-gnueabihf-gcc GOOS=linux GOARCH=arm GOARM=6 CGO_ENABLED=1 ./make.bash --no-clean || exit 1
cp -r -f ${BUILD_DIR}/go ${INSTALL_PREFIX}
echo "##### Compile OpenAL"
cd ${BUILD_DIR} && curl -s -L http://kcat.strangesoft.net/openal-releases/openal-soft-${OPENAL_VERSION}.tar.bz2 | tar -xj
cat << EOF > ${BUILD_DIR}/openal-soft-${OPENAL_VERSION}/linux-rpi.cmake
set(TOOLCHAIN_PREFIX arm-linux-gnueabihf)
set(CMAKE_C_COMPILER \${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_FIND_ROOT_PATH \${INSTALL_PREFIX}/gcc-linaro-arm-linux-gnueabihf-raspbian-x64)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
EOF
mkdir -p ${BUILD_DIR}/openal-soft-${OPENAL_VERSION}/build-rpi
cd ${BUILD_DIR}/openal-soft-${OPENAL_VERSION}/build-rpi
cmake -DLIBTYPE=STATIC -DCMAKE_TOOLCHAIN_FILE=../linux-rpi.cmake -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}/gcc-linaro-arm-linux-gnueabihf-raspbian-x64 ..
make -j $(nproc) && make install
echo "##### Remove build directory"
rm -rf ${BUILD_DIR}

View file

@ -0,0 +1,21 @@
package main
import "github.com/gen2brain/raylib-go/raylib"
func main() {
raylib.InitWindow(800, 450, "raylib [rpi] example - basic window")
raylib.SetTargetFPS(60)
for !raylib.WindowShouldClose() {
raylib.BeginDrawing()
raylib.ClearBackground(raylib.RayWhite)
raylib.DrawText("Congrats! You created your first window!", 190, 200, 20, raylib.LightGray)
raylib.EndDrawing()
}
raylib.CloseWindow()
}