forked from rodrigodzf/xc-bela-container
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
supports both default bela make and custom cmake
- Loading branch information
Showing
11 changed files
with
98 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
LIB_FULL_SO = libbelafull.so | ||
LIB_FULL_A = libbelafull.a | ||
LIB_FULL_OBJS = build/*/*.o libraries/*/build/*.o | ||
|
||
lib/$(LIB_FULL_SO): $(LIB_FULL_OBJS) | ||
$(AT) echo Building lib/$(LIB_FULL_SO) | ||
$(AT) $(CXX) $(BELA_LDFLAGS) $(LDFLAGS) -shared -Wl,-soname,$(LIB_FULL_SO) -o lib/$(LIB_FULL_SO) $(LIB_FULL_OBJS) $(LDLIBS) $(BELA_EXTRA_LDLIBS) | ||
$(AT) ldconfig $(BELA_DIR)/$@ | ||
|
||
lib/$(LIB_FULL_A): $(LIB_FULL_OBJS) $(PRU_OBJS) $(LIB_DEPS) | ||
$(AT) echo Building lib/$(LIB_FULL_A) | ||
$(AT) ar rcs lib/$(LIB_FULL_A) $(LIB_FULL_OBJS) | ||
|
||
libbelafull: lib/libbelafull.so lib/libbelafull.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NO_PROJECT_TARGETS+=lib/libbelafull.a libbelafull |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,60 @@ | |
|
||
Docker image for [Bela](https://bela.io/) development and cross-compilation. Uses GCC 10, CMake and Make for a fast and modular build. By containerizing the cross-compilation toolchain, Bela code can be written and compiled on any host OS that can run Docker, and is compiled much faster and with more flexibility than in the Bela IDE. | ||
|
||
## Quickstart | ||
## Quickstart and basic usage | ||
|
||
**You can pull the xc-bela-container image from the Docker image hub:** | ||
|
||
```bash | ||
docker pull pelinski/xc-bela-container:v1.0.0 | ||
docker pull pelinski/xc-bela-container:v1.1.0 | ||
``` | ||
There are images for both `amd64` and `arm64` architectures, the pull command will pull the correct one for your machine. If you are on a different machine you will have to build the image yourself (see below). | ||
|
||
You can then start a container with (replace the `BBB_HOSTNAME` with the IP address of your Bela – if you are on Windows, it's `192.168.6.2`): | ||
|
||
```bash | ||
docker run -it --name bela-container -e BBB_HOSTNAME=192.168.7.2 pelinski/xc-bela-container:v1.0.0 | ||
docker run -it --name bela-container -e BBB_HOSTNAME=192.168.7.2 pelinski/xc-bela-container:v1.1.0 | ||
``` | ||
|
||
## Building the docker image and starting a container | ||
You can quit the container with `Ctrl+D` or `exit`. You can start it again with: | ||
|
||
```bash | ||
docker start -ia bela-container | ||
``` | ||
|
||
|
||
## Usage tutorial | ||
In this quick tutorial we will cross-compile the `basic` example project in this repo. First we need to copy our project to the Bela projects folder in the container. | ||
|
||
```bash | ||
docker cp basic bela-container:/sysroot/root/Bela/projects/ | ||
``` | ||
|
||
Now we need to log into the container: | ||
|
||
```bash | ||
docker start -ia bela-container | ||
``` | ||
|
||
Inside the container, we can compile the project with the following commands (note that these commands are the same you would use in Bela): | ||
|
||
```bash | ||
cd /sysroot/root/Bela | ||
make PROJECT=basic -j5 | ||
``` | ||
|
||
Now we can copy the compiled project to Bela: | ||
|
||
```bash | ||
rsync -av /sysroot/root/Bela/projects/basic [email protected]:Bela/projects/ | ||
``` | ||
|
||
and run it: | ||
```bash | ||
ssh -t [email protected] ./Bela/projects/basic/basic | ||
``` | ||
|
||
## Building the docker image | ||
|
||
You will need to have [Docker](https://docs.docker.com/get-docker/) installed and running. | ||
|
||
|
@@ -42,60 +80,47 @@ Once the image is built is built you can start a container with: | |
```bash | ||
docker run -it --name bela-container -e BBB_HOSTNAME=192.168.7.2 xc-bela | ||
``` | ||
## Advanced stuff | ||
### Cross-compiling with cmake | ||
If you want to build more complex projects, you can use CMakeLists instead of the default Bela Makefile. | ||
|
||
You can quit it with `Ctrl+D` or `exit`. You can start it again with: | ||
|
||
```bash | ||
docker start -ia bela-container | ||
``` | ||
|
||
## Usage tutorial | ||
In this quick tutorial we will cross-compile the `example-project` in this repo (it's the Bela `fundamentals/sinetone` example). | ||
|
||
### Copy libbelafull.so to Bela | ||
|
||
First, for the cross-compiled binaries to run in your Bela, you will need to copy the `libbelafull.so` library from the Docker container into your Bela. You can do so by running, inside the Docker container: | ||
First, you will need to copy the `libbelafull.so` library from the Docker container into your Bela. You can do so by running, inside the Docker container (you can start it with `docker start -ia bela-container`): | ||
|
||
```bash | ||
scp /sysroot/root/Bela/lib/libbelafull.so root@$BBB_HOSTNAME:Bela/lib/libbelafull.so | ||
``` | ||
|
||
### Copy Bela project into Docker | ||
|
||
To cross-compile a project in Docker, copy the project folder into docker. | ||
Now you can copy the project to the container (since we are using CMake, we don't need to copy it into `sysroot/root/Bela/projects/`): | ||
|
||
```bash | ||
docker cp example-project bela-container:/workspace/ | ||
docker cp basic bela-container:/sysroot/root/ | ||
``` | ||
|
||
### Cross-compile project | ||
|
||
To cross-compile the project, we need to tell the compiler that we are cross-compiling for Bela. That information is inside the docker, in the `/workspace/Toolchain.cmake` file. | ||
To cross-compile the project, we need to tell the compiler that we are cross-compiling for Bela. That information is inside the container, in the `/sysroot/root/Bela/Toolchain.cmake` file. | ||
|
||
You can cross-compile a project by running the following commands inside the docker container (you can access it with `docker start -ia bela`): | ||
You can cross-compile a project by running the following commands inside the container: | ||
|
||
```shell | ||
cd /workspace/example-project | ||
cd /sysroot/root/basic # path to the project | ||
mkdir build && cd build | ||
cmake -DCMAKE_TOOLCHAIN_FILE=/workspace/Toolchain.cmake -DPROJECT_NAME=sinetone ../ | ||
cmake -DCMAKE_TOOLCHAIN_FILE=/sysroot/root/Bela/Toolchain.cmake -DPROJECT_NAME=basic ../ | ||
cmake --build . | ||
``` | ||
|
||
You can then copy the compiled project to Bela by running: | ||
|
||
```bash | ||
rsync --timeout=10 -avzP /workspace/example-project/build/sinetone [email protected]:~/Bela/projects/sinetone | ||
rsync --timeout=10 -avzP /sysroot/root/basic/build/basic [email protected]:~/ | ||
``` | ||
|
||
You can now run the project in Bela: | ||
|
||
```bash | ||
ssh [email protected] | ||
cd Bela/projects | ||
./sinetone | ||
ssh -t [email protected] ./basic | ||
``` | ||
|
||
## Advanced: building docker images for different architectures | ||
|
||
### Building docker images for different architectures | ||
When you build the docker image, it will be built for the architecture of your host machine. If you want to build a docker image for a different architecture, you can use the `buildx` command. | ||
|
||
First, you need to enable the `buildx` command. You can do so by running (these commands have been tested on a MacbookPro Intel): | ||
|
@@ -105,6 +130,8 @@ docker buildx create --name xc-builder --use --driver docker-container | |
docker run --privileged linuxkit/binfmt:v1.0.0 | ||
docker buildx inspect --bootstrap | ||
``` | ||
(If you get an error saying that the `xc-builder` already exists, you can remove it by running `docker buildx rm xc-builder`.) | ||
|
||
|
||
Then, you can build the image for a different architecture by running (replace the `linux/arm64` with the architecture you want to build for): | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash -e | ||
|
||
source build_settings | ||
BBB_ADDRESS=root@$BBB_HOSTNAME | ||
|
||
rsync \ | ||
--timeout=10 \ | ||
-avzP /tmp/CustomMakefile* \ | ||
$BBB_ADDRESS:Bela/ | ||
|
||
ssh $BBB_ADDRESS "cd Bela && make libbelafull" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
BBB_HOSTNAME=192.168.7.2 | ||
BELA_COMMIT=7005724 | ||
BELA_COMMIT=4875233 |