Skip to content

Commit 644d204

Browse files
feat: rMPP support (#58)
* feat: rMPP support * fix/builder.py: fix arch detection * feat/test: test for rMPP things too * fix/builder: use startwith per Eeems' suggestion * fix/docs: per suggestions * feat/builder: auto switch aarch64 envvars * feat: rMPPM support too * fix: setting build env * feat: arch test case * feat: arch test case actually * fix: run formatter to please linter * fix: run formatter to please linter, part 2 * fix: run formatter to please linter, part 3 * fix: now black strikes again! * fix: remove unneeded manual arch switch guide
1 parent e1d930e commit 644d204

File tree

7 files changed

+155
-11
lines changed

7 files changed

+155
-11
lines changed

docs/recipe-format.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ The following values are accepted:
4040

4141
Name | Meaning
4242
--------|-------------------------------------------------------------------------
43-
`rmall` | Packages which work on all reMarkable devices without modification.
43+
`rmall` | Packages which work on all reMarkable devices without modification. These packages must be cpu architecture independent, which generally means that they do not contain binaries, only scripts and configuration files.
4444
`rm1` | Packages requiring reMarkable 1-specific resources or compilation flags.
4545
`rm2` | Packages requiring reMarkable 2-specific resources or compilation flags.
46+
`rmpp` | Packages requiring reMarkable Paper Pro-specific resources or compilation flags.
47+
`rmppm` | Packages requiring reMarkable Paper Pro Move-specific resources or compilation flags.
4648

4749
For example, use `archs=(rm1)` for a package that only works on reMarkable 1, or `archs=(rm1 rm2)` for a package that works both on reMarkable 1 and reMarkable 2 but needs different dependencies or compilation flags for each of those.
4850

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[project]
22
name = "toltecmk"
3-
version = "0.3.7"
3+
version = "0.4.0"
44
authors = [
55
{ name="Mattéo Delabre", email="[email protected]" },
66
{ name="Eeems", email="[email protected]" },
7+
{ name="Noa Himesaka", email="[email protected]" },
78
]
89
description = "Build system used for the Toltec community repository"
910
requires-python = ">=3.11"

tests/fixtures/hello/package

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ license=MIT
1111
pkgver=0.0.1-1
1212
section="utils"
1313
flags=()
14+
archs=(rm1 rmpp)
1415

15-
image=base:v2.1
16+
image=base:v4.0
1617
source=(hello.c)
1718
sha256sums=(SKIP)
1819

tests/recipe_parsers/test_installdepends.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_installdepends(self) -> None:
3535
with open(path.join(rec_path, "package"), "w") as rec_def_file:
3636
rec_def_file.write(
3737
"""
38-
archs=(rmall rmallos2 rmallos3 rm1 rm1os2 rm1os3 rm2 rm2os2 rm2os3)
38+
archs=(rmall rmallos2 rmallos3 rm1 rm1os2 rm1os3 rm2 rm2os2 rm2os3 rmpp rmppos3 rmppm rmppmos3)
3939
pkgnames=(toltec-base)
4040
pkgdesc="Metapackage defining the base set of packages in a Toltec install"
4141
url=https://toltec-dev.org/
@@ -49,6 +49,10 @@ def test_installdepends(self) -> None:
4949
installdepends_rm1os3=(open-remarkable-shutdown)
5050
installdepends_rm2os2=(rm2-suspend-fix)
5151
installdepends_rm2os3=(rm2-suspend-fix)
52+
installdepends_rmpp=(rmpp-make-root-rw)
53+
installdepends_rmppos3=(rmpp-make-root-rw)
54+
installdepends_rmppm=(rmpp-make-root-rw)
55+
installdepends_rmppmos3=(rmpp-make-root-rw)
5256
5357
image=base:v2.1
5458
source=("https://example.org/toltec/${pkgnames[0]}/release-${pkgver%-*}.zip")
@@ -80,6 +84,8 @@ def test_installdepends(self) -> None:
8084
Dependency(DependencyKind.HOST, "open-remarkable-shutdown")
8185
]
8286
rm2_depends = [Dependency(DependencyKind.HOST, "rm2-suspend-fix")]
87+
rmpp_depends = [Dependency(DependencyKind.HOST, "rmpp-make-root-rw")]
88+
rmppm_depends = [Dependency(DependencyKind.HOST, "rmpp-make-root-rw")]
8389

8490
recipes = parse_recipe(rec_path)
8591

@@ -95,6 +101,10 @@ def test_installdepends(self) -> None:
95101
"rm2",
96102
"rm2os2",
97103
"rm2os3",
104+
"rmpp",
105+
"rmppos3",
106+
"rmppm",
107+
"rmppmos3",
98108
],
99109
)
100110
recipe = recipes["rmall"]
@@ -177,3 +187,39 @@ def test_installdepends(self) -> None:
177187
package.installdepends,
178188
set(basic_depends + rm2_depends),
179189
)
190+
191+
recipe = recipes["rmpp"]
192+
self.assertIs(type(recipe), Recipe)
193+
package = recipe.packages["toltec-base"]
194+
self.assertEqual(list(recipe.packages.keys()), ["toltec-base"])
195+
self.assertEqual(
196+
package.installdepends,
197+
set(basic_depends + rmpp_depends),
198+
)
199+
200+
recipe = recipes["rmppos3"]
201+
self.assertIs(type(recipe), Recipe)
202+
package = recipe.packages["toltec-base"]
203+
self.assertEqual(list(recipe.packages.keys()), ["toltec-base"])
204+
self.assertEqual(
205+
package.installdepends,
206+
set(basic_depends + rmpp_depends),
207+
)
208+
209+
recipe = recipes["rmppm"]
210+
self.assertIs(type(recipe), Recipe)
211+
package = recipe.packages["toltec-base"]
212+
self.assertEqual(list(recipe.packages.keys()), ["toltec-base"])
213+
self.assertEqual(
214+
package.installdepends,
215+
set(basic_depends + rmppm_depends),
216+
)
217+
218+
recipe = recipes["rmppmos3"]
219+
self.assertIs(type(recipe), Recipe)
220+
package = recipe.packages["toltec-base"]
221+
self.assertEqual(list(recipe.packages.keys()), ["toltec-base"])
222+
self.assertEqual(
223+
package.installdepends,
224+
set(basic_depends + rmppm_depends),
225+
)

tests/test_arch.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright (c) 2023 The Toltec Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
import unittest
5+
import subprocess
6+
7+
from os import path
8+
from tempfile import TemporaryDirectory
9+
from elftools.elf.elffile import ELFFile
10+
11+
12+
class TestBuild(unittest.TestCase):
13+
def setUp(self) -> None:
14+
self.dir = path.dirname(path.realpath(__file__))
15+
self.fixtures_dir = path.join(self.dir, "fixtures")
16+
17+
def test_arch(self) -> None:
18+
with TemporaryDirectory() as tmp_dir:
19+
rec_dir = path.join(self.fixtures_dir, "hello")
20+
work_dir = path.join(tmp_dir, "build")
21+
dist_dir = path.join(tmp_dir, "dist")
22+
23+
result = subprocess.run(
24+
[
25+
"python3",
26+
"-m",
27+
"toltec",
28+
"--work-dir",
29+
work_dir,
30+
"--dist-dir",
31+
dist_dir,
32+
"--",
33+
rec_dir,
34+
],
35+
capture_output=True,
36+
check=False,
37+
)
38+
self.assertEqual(
39+
result.returncode, 0, result.stderr.decode("utf-8")
40+
)
41+
self.assertEqual(result.stdout.decode("utf-8"), "")
42+
with open(
43+
path.join(tmp_dir, "build", "rm1", "src", "hello"), "rb"
44+
) as f:
45+
self.assertEqual(ELFFile(f).get_machine_arch(), "ARM")
46+
with open(
47+
path.join(tmp_dir, "build", "rmpp", "src", "hello"), "rb"
48+
) as f:
49+
self.assertEqual(ELFFile(f).get_machine_arch(), "AArch64")

toltec/builder.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ def _prepare(recipe: Recipe, src_dir: str) -> None:
274274
)
275275
bash.pipe_logs(logger, logs, "prepare()")
276276

277+
# pylint: disable=too-many-locals
277278
def _build(self, recipe: Recipe, src_dir: str) -> None:
278279
"""Build artifacts for a recipe."""
279280
if not recipe.build:
@@ -316,13 +317,31 @@ def _build(self, recipe: Recipe, src_dir: str) -> None:
316317
)
317318

318319
if host_deps:
319-
opkg_conf_path = "$SYSROOT/etc/opkg/opkg.conf"
320+
opkg_conf_path = (
321+
"$SYSROOT_AARCH64/etc/opkg/opkg.conf"
322+
if recipe.arch.startswith("rmpp")
323+
else "$SYSROOT/etc/opkg/opkg.conf"
324+
)
325+
opkg_exec = (
326+
"opkg-aarch64" if recipe.arch.startswith("rmpp") else "opkg"
327+
)
328+
opkg_arch = (
329+
"aarch64-3.10"
330+
if recipe.arch.startswith("rmpp")
331+
else "armv7-3.2"
332+
)
333+
opkg_src = (
334+
"aarch64-k3.10"
335+
if recipe.arch.startswith("rmpp")
336+
else "armv7sf-k3.2"
337+
)
338+
320339
pre_script.extend(
321340
(
322341
'echo -n "dest root /',
323342
"arch all 100",
324-
"arch armv7-3.2 160",
325-
"src/gz entware https://bin.entware.net/armv7sf-k3.2",
343+
f"arch {opkg_arch} 160",
344+
f"src/gz entware https://bin.entware.net/{opkg_src}",
326345
"arch rmall 200",
327346
"src/gz toltec-rmall file:///repo/rmall",
328347
f'" > "{opkg_conf_path}"',
@@ -340,12 +359,15 @@ def _build(self, recipe: Recipe, src_dir: str) -> None:
340359

341360
pre_script.extend(
342361
(
343-
"opkg update --verbosity=0",
344-
"opkg install --verbosity=0 --no-install-recommends"
362+
f"{opkg_exec} update --verbosity=0",
363+
f"{opkg_exec} install --verbosity=0 --no-install-recommends"
345364
" -- " + " ".join(host_deps),
346365
)
347366
)
348367

368+
if recipe.arch.startswith("rmpp"):
369+
pre_script.append(("source /opt/x-tools/switch-aarch64.sh"))
370+
349371
logs = bash.run_script_in_container(
350372
self.docker,
351373
image=self.IMAGE_PREFIX + recipe.image,

toltec/hooks/strip.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
logger = logging.getLogger(__name__)
2121

2222
MOUNT_SRC = "/src"
23-
TOOLCHAIN = "toolchain:v3.1"
23+
TOOLCHAIN = "toolchain:v4.0"
2424

2525

2626
def walk_elfs(src_dir: str, for_each: Callable) -> None:
@@ -73,6 +73,7 @@ def post_build( # pylint: disable=too-many-locals,too-many-branches
7373

7474
# Search for binary objects that can be stripped
7575
strip_arm: List[str] = []
76+
strip_aarch64: List[str] = []
7677
strip_x86: List[str] = []
7778

7879
def filter_elfs(info: ELFFile, file_path: str) -> None:
@@ -81,12 +82,14 @@ def filter_elfs(info: ELFFile, file_path: str) -> None:
8182
return
8283
if info.get_machine_arch() == "ARM":
8384
strip_arm.append(file_path)
85+
elif info.get_machine_arch() == "AArch64":
86+
strip_aarch64.append(file_path)
8487
elif info.get_machine_arch() in ("x86", "x64"):
8588
strip_x86.append(file_path)
8689

8790
walk_elfs(src_dir, filter_elfs)
8891

89-
if not strip_arm and not strip_x86:
92+
if not strip_arm and not strip_aarch64 and not strip_x86:
9093
logger.debug("Skipping, no binaries found")
9194
return
9295

@@ -139,6 +142,26 @@ def docker_file_path(file_path: str) -> str:
139142
os.path.relpath(file_path, src_dir),
140143
)
141144

145+
if strip_aarch64:
146+
script.extend(
147+
(
148+
"source /opt/x-tools/switch-aarch64.sh",
149+
'"${CROSS_COMPILE}strip" --strip-all -- '
150+
+ " ".join(
151+
docker_file_path(file_path)
152+
for file_path in strip_aarch64
153+
),
154+
)
155+
)
156+
157+
logger.debug("AArch64 binaries to be stripped:")
158+
159+
for file_path in strip_aarch64:
160+
logger.debug(
161+
" - %s",
162+
os.path.relpath(file_path, src_dir),
163+
)
164+
142165
run_in_container(builder, src_dir, logger, script)
143166

144167
# Restore original mtimes

0 commit comments

Comments
 (0)