[firmware] compile pybricks too
This commit is contained in:
parent
372a12916d
commit
fb97269cc4
|
@ -1,3 +1,4 @@
|
|||
.idea
|
||||
scratch-blocks
|
||||
scratch-gui
|
||||
pybricks-micropython
|
||||
|
|
78
BUILDING.md
78
BUILDING.md
|
@ -1,78 +0,0 @@
|
|||
# Building PyBlocks
|
||||
|
||||
Compiling pyblocks is a multi-step process. There are generally two options for building any component of PyBlocks.
|
||||
|
||||
Because of the nature of how PyBlocks is compiled (via patching source code of various other projects), it is very easy to leave yourself in a broken state, unable to finish compilation. **If you don't know what you're doing, use PBT.**
|
||||
|
||||
You will need git, nodejs, npm, and python2 (under the command `python2`) installed.
|
||||
|
||||
Python 2 **must** be reachable at `python2` - any other command will *not* work without further patching of the source tree.
|
||||
|
||||
## Option 1: PBT (PyBlocks Build Tool) (Highly Recommended)
|
||||
|
||||
`pbt.sh` is a shell script designed to automate the process of developing PyBlocks. To use PBT, you need to be on a **Unix** (`/`-style paths, rougly POSIX compliant) system, with git, node, npm, and general baseutils available.
|
||||
|
||||
We highly recommend using PBT, as it makes it impossible to mess up the build process and leave you with a broken source tree.
|
||||
|
||||
## Option 2: Manual (For experts only)
|
||||
|
||||
While `pbt.sh` is incredibly useful if you are on a Unix platform, it is still possible to compile PyBlocks on other platforms, you will simply need to follow the compilation instructions manually. Expect things to break permanently if you mess up, requiring you to delete your copy of PyBlocks and start over.
|
||||
|
||||
# Step 1: Downloading sources
|
||||
|
||||
PyBlocks works by applying a set of patches (see `patches/`) to other projects' sourcecode. To do this, you'll need a local copy of their source trees. You have two options:
|
||||
|
||||
## Option 1: PBT (Recommended)
|
||||
|
||||
Run `./pbt.sh clone`. This will download a local copy of the required source code and place it where PBT expects them to be.
|
||||
|
||||
This may take a while, as the files being downloaded are fairly large. A relatively fast internet connection is required for this step.
|
||||
|
||||
## Option 2: Manual
|
||||
|
||||
### Step 1.1: Downloading scratch-blocks
|
||||
|
||||
Clone the scratch-blocks repository into `scratch-blocks`:
|
||||
|
||||
```shell
|
||||
git clone https://github.com/scratchfoundation/scratch-blocks scratch-blocks
|
||||
```
|
||||
|
||||
This may take a while, as the files being downloaded are fairly large. A relatively fast internet connection is required for this step.
|
||||
|
||||
Copy the patchbase for scratch-blocks from the file `patches/blocks/PATCHBASE`, then check it out with the following command:
|
||||
|
||||
```shell
|
||||
cd scratch-blocks
|
||||
git checkout [PATCHBASE GOES HERE]
|
||||
```
|
||||
|
||||
# Patching the source code
|
||||
|
||||
To compile PyBlocks, you need to apply a set of *patches* to the source code you just downloaded. This will convert that code into PyBlocks.
|
||||
|
||||
## Option 1: PBT (Recommended)
|
||||
|
||||
Run `./pbt.sh patch` to apply the patches. This can take a little while, as some of the patches are very large. If you interrupt this command, it is safe to run again.
|
||||
|
||||
## Option 2: Manual
|
||||
|
||||
Apply all of the git patches in `patches/` to their relative repositories:
|
||||
|
||||
- `blocks` goes to `scratch-blocks`
|
||||
|
||||
The way you do this depends on how your system is set up, but patches should be only applied with `git apply`.
|
||||
|
||||
# Compiling scratch-blocks
|
||||
|
||||
**Warning:** This step can take a very long time (up to 10 minutes). **Do not interrupt the build process.** The scratch-blocks compiler has a bug in it that will lock up your computer if you interrupt this build process.
|
||||
|
||||
You only need to run this process once, when you compile scratch-blocks for the first time. Further edits to the source trees do not require this step to be repeated - you generally only need to run it the first time you build PyBlocks.
|
||||
|
||||
## Option 1: PBT (Recommended)
|
||||
|
||||
Run `./pbt.sh compile` to compile scratch-blocks. This will take a very long time. **Do not** interrupt this process.
|
||||
|
||||
## Option 2: Manual
|
||||
|
||||
Run `npm i` in `scratch-blocks/` to install dependencies and compile scratch-blocks. This will take a very long time. **Do not interrupt this process.**
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "pyblocks",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
From f98181e5d46122052bd6096769d219f14163f13b Mon Sep 17 00:00:00 2001
|
||||
From: c0repwn3r <core@coredoes.dev>
|
||||
Date: Wed, 24 May 2023 13:26:34 -0400
|
||||
Subject: [PATCH] fix builds on gcc13
|
||||
|
||||
---
|
||||
py/stackctrl.c | 7 +++++++
|
||||
1 file changed, 7 insertions(+)
|
||||
|
||||
diff --git a/py/stackctrl.c b/py/stackctrl.c
|
||||
index c2f3adb5eedcd77a64dd22835e6f859a333d9d4b..c2566ebad92b84e0421cc77dd65f6c5fa2e04561 100644
|
||||
--- a/py/stackctrl.c
|
||||
+++ b/py/stackctrl.c
|
||||
@@ -28,8 +28,15 @@
|
||||
#include "py/stackctrl.h"
|
||||
|
||||
void mp_stack_ctrl_init(void) {
|
||||
+ #if __GNUC__ >= 13
|
||||
+ #pragma GCC diagnostic push
|
||||
+ #pragma GCC diagnostic ignored "-Wdangling-pointer"
|
||||
+ #endif
|
||||
volatile int stack_dummy;
|
||||
MP_STATE_THREAD(stack_top) = (char *)&stack_dummy;
|
||||
+ #if __GNUC__ >= 13
|
||||
+ #pragma GCC diagnostic pop
|
||||
+ #endif
|
||||
}
|
||||
|
||||
void mp_stack_set_top(void *top) {
|
||||
--
|
||||
2.40.1
|
||||
|
80
pbt.sh
80
pbt.sh
|
@ -11,19 +11,19 @@ job_start() {
|
|||
job_success() {
|
||||
# [*] success! [target]:[job] finished in 241.2s :)
|
||||
end=$(date +%s.%N)
|
||||
time=$( echo "$end - $job_start" | bc -l )
|
||||
time=$(echo "$end - $job_start" | bc -l)
|
||||
echo -e "\e[1m\e[32m[*] success! $1:$2 finished in $time seconds :)\e[0m"
|
||||
}
|
||||
job_fail() {
|
||||
# [x] FAIL! [target]:[job] failed in 241.2s :(
|
||||
end=$(date +%s.%N)
|
||||
time=$( echo "$end - $job_start" | bc -l )
|
||||
time=$(echo "$end - $job_start" | bc -l)
|
||||
echo -e "\e[1m\e[31m[*] FAIL! $1:$2 failed in $time seconds :(\e[0m"
|
||||
}
|
||||
job_skip() {
|
||||
# [-] skipped - [target]:[job] skipped in 241.2s
|
||||
end=$(date +%s.%N)
|
||||
time=$( echo "$end - $job_start" | bc -l )
|
||||
time=$(echo "$end - $job_start" | bc -l)
|
||||
echo -e "\e[1m\e[34m[-] skipped - $1:$2 skipped after $time seconds\e[0m"
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,30 @@ sub_clone() {
|
|||
fi
|
||||
cd .. || exit
|
||||
job_success "scratch-blocks" "checkout"
|
||||
|
||||
job_start "pybricks-micropython" "clone"
|
||||
if [ -d "$(pwd)/pybricks-micropython" ]; then
|
||||
echo "Clone dir already exists"
|
||||
job_skip "pybricks-micropython" "clone"
|
||||
else
|
||||
git clone https://github.com/pybricks/pybricks-micropython pybricks-micropython
|
||||
if [ "$?" != "0" ]; then
|
||||
job_fail "pybricks-micropython" "clone"
|
||||
exit 1
|
||||
fi
|
||||
job_success "pybricks-micropython" "clone"
|
||||
fi
|
||||
job_start "pybricks-micropython" "env"
|
||||
cd "pybricks-micropython" || exit
|
||||
poetry env info | grep 'Python: ' | grep -q "3.10"
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "Your python version is not supported. 3.10.x needed. Your version:"
|
||||
poetry env info | grep 'Python: ' | grep "3.*"
|
||||
echo "Run 'poetry env use /path/to/python3.10' to set the correct version."
|
||||
job_fail "pybricks-micropython" "env"
|
||||
fi
|
||||
cd .. || exit
|
||||
job_success "pybricks-micropython" "env"
|
||||
}
|
||||
|
||||
sub_patch() {
|
||||
|
@ -69,14 +93,37 @@ sub_patch() {
|
|||
exit 1
|
||||
fi
|
||||
|
||||
cd .. || exit
|
||||
|
||||
echo "[*] Patches applied cleanly to scratch-blocks"
|
||||
|
||||
job_success "scratch-blocks" "patch"
|
||||
|
||||
job_start "pybricks-micropython:micropython" "patch"
|
||||
|
||||
cd pybricks-micropython/micropython || exit
|
||||
|
||||
git am --abort >/dev/null 2>&1
|
||||
|
||||
git am --3way "../../patches/mpy/"*.patch
|
||||
if [ "$?" != "0" ]; then
|
||||
echo "One or more patches did not apply cleanly to pybricks-micropython. Check above message and try again".
|
||||
job_fail "pybricks-micropython:micropython" "patch"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[*] Patches applied cleanly to pybricks-micropython"
|
||||
|
||||
job_success "pybricks-micropython:micropython" "patch"
|
||||
|
||||
cd ../.. || exit
|
||||
}
|
||||
|
||||
sub_compile() {
|
||||
sub_patch
|
||||
|
||||
cd scratch-blocks || exit
|
||||
|
||||
job_start "scratch-blocks" "compile"
|
||||
|
||||
NODE_OPTIONS=--openssl-legacy-provider npm i
|
||||
|
@ -86,7 +133,30 @@ sub_compile() {
|
|||
exit 1
|
||||
fi
|
||||
|
||||
cd .. || exit
|
||||
|
||||
job_success "scratch-blocks" "compile"
|
||||
|
||||
job_start "pybricks-micropython" "compile"
|
||||
cd pybricks-micropython || exit
|
||||
|
||||
poetry run make primehub
|
||||
if [ "$?" != "0" ]; then
|
||||
job_fail "pybricks-micropython" "compile"
|
||||
exit 1
|
||||
fi
|
||||
poetry run make technichub
|
||||
if [ "$?" != "0" ]; then
|
||||
job_fail "pybricks-micropython" "compile"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[*] Compile complete!"
|
||||
echo "Wrote technichub firmware to pybricks-micropython/bricks/technichub/build/firmware.zip"
|
||||
echo "Wrote primehub firmware to pybricks-micropython/bricks/primehub/build/firmware.zip"
|
||||
|
||||
cd .. || exit
|
||||
job_success "pybricks-micropython" "compile"
|
||||
}
|
||||
|
||||
sub_patchc() {
|
||||
|
@ -130,10 +200,10 @@ sub_help() {
|
|||
|
||||
subcommand=$1
|
||||
case $subcommand in
|
||||
"" | "-h" | "--help" | "help")
|
||||
"" | "-h" | "--help" | "help")
|
||||
sub_help
|
||||
;;
|
||||
*)
|
||||
*)
|
||||
echo "[*] Running build command $subcommand"
|
||||
shift
|
||||
sub_"${subcommand}" "$@"
|
||||
|
|
Loading…
Reference in New Issue