Skip to content

Commit

Permalink
Support python 3.10 and Ubuntu 22.04
Browse files Browse the repository at this point in the history
Ubuntu 22.04 only ships libbcm_host.so on aarch64, *not*
libbcm_host.so.0, which is what Raspberry Pi OS ships (in addition to
libbcm_host.so).  Work around that by forcing the LD requires to only
point to libbcm_host.so for our python extension library.
  • Loading branch information
jpieper committed Jul 12, 2023
1 parent 4a1fc1b commit 24e55f2
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 14 deletions.
11 changes: 9 additions & 2 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- python -*-

# Copyright 2020-2022 Josh Pieper, [email protected].
# Copyright 2020-2023 Josh Pieper, [email protected].
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,7 +57,7 @@ test_suite(
"cpu": arch,
},
)
for pyver in ['3.7', '3.9']
for pyver in ['3.7', '3.9', '3.10']
for arch in ['armeabihf', 'aarch64']
]

Expand All @@ -74,3 +74,10 @@ config_setting(
"define": "PYTHON=3.9",
},
)

config_setting(
name = "python310",
values = {
"define": "PYTHON=3.10",
},
)
11 changes: 8 additions & 3 deletions lib/python/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- python -*-

# Copyright 2020-2022 Josh Pieper, [email protected].
# Copyright 2020-2023 Josh Pieper, [email protected].
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -22,17 +22,20 @@ load("//tools/workspace:template_file.bzl", "template_file")

VERSION="0.3.26"

PYTHON_SHORT_VERSIONS = ['37', '39']
PYTHON_SHORT_VERSIONS = ['37', '39', '310']
ARCHITECTURES = ['armv7l', 'aarch64']
ABITAG = {
'37': 'abi3',
'39': 'cp39',
'310': 'cp310',
}
PTAG = {
'37_armv7l': 'linux',
'37_aarch64': 'manylinux_2_17',
'39_armv7l': 'manylinux_2_17',
'39_aarch64': 'manylinux_2_17',
'310_armv7l': 'manylinux_2_17',
'310_aarch64': 'manylinux_2_17',
}


Expand Down Expand Up @@ -84,7 +87,7 @@ pkg_tar(
"tar xf $(location wheel_tar) -C $$BUILDDIR && " +
"cp $(location setup_{pyshortver}.py) $(location README.md) $$BUILDDIR && " +
"cd $$BUILDDIR && " +
"python3.9 setup_{pyshortver}.py bdist_wheel " +
"python3 setup_{pyshortver}.py bdist_wheel " +
" --plat-name {ptag}_{architecture} " +
" --py-limited-api cp{pyshortver} " +
" --dist-dir .. " +
Expand Down Expand Up @@ -114,5 +117,7 @@ filegroup(
"//:python37_aarch64" : [":bdist_wheel_37_aarch64"],
"//:python39_armeabihf" : [":bdist_wheel_39_armv7l"],
"//:python39_aarch64" : [":bdist_wheel_39_aarch64"],
"//:python310_armeabihf" : [":bdist_wheel_310_armv7l"],
"//:python310_aarch64" : [":bdist_wheel_310_aarch64"],
}),
)
3 changes: 2 additions & 1 deletion lib/python/moteus_pi3hat/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- python -*-

# Copyright 2020-2021 Josh Pieper, [email protected].
# Copyright 2020-2023 Josh Pieper, [email protected].
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,7 @@ cc_binary(
"//conditions:default" : [],
"//:python37" : ["@com_github_pybind_pybind11//:pybind11_37"],
"//:python39" : ["@com_github_pybind_pybind11//:pybind11_39"],
"//:python310" : ["@com_github_pybind_pybind11//:pybind11_310"],
}),
linkshared = True,
)
Expand Down
4 changes: 2 additions & 2 deletions make_release.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python3

# Copyright 2020-2022 Josh Pieper, [email protected].
# Copyright 2020-2023 Josh Pieper, [email protected].
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,7 +54,7 @@ def main():

run(f'cp bazel-bin/fw/pi3_hat.elf {outdir}/{datestr}-pi3hat-{git_hash}.elf')

for pyver in ['3.7', '3.9']:
for pyver in ['3.7', '3.9', '3.10']:
for arch in ['pi', 'pi64']:
pyarch = {
'pi' : 'armv7l',
Expand Down
4 changes: 2 additions & 2 deletions tools/workspace/bazel_deps/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ def bazel_deps_repository(name):
github_archive(
name = name,
repo = "mjbots/bazel_deps",
commit = "0d73d14eeb80b6555eedda769094afde6b147dc3",
sha256 = "dabb0dccc3a8d15cc1f72896c15c2e313d0e917d8b84a70a9a21bae294e41f34",
commit = "6c9ba1867b5d0ab5e59a7f1205adfd750a6c3610",
sha256 = "617989e5ca59c691d4e3e601dc899745aa9ace4c21d0f70b6128cc8125754cbd",
)
9 changes: 9 additions & 0 deletions tools/workspace/pybind11/package.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ cc_library(
"@python39//:headers",
],
)

cc_library(
name = "pybind11_310",
hdrs = glob(["include/**"]),
includes = ["include"],
deps = [
"@python310//:headers",
],
)
4 changes: 2 additions & 2 deletions tools/workspace/pybind11/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def pybind11_repository(name):
github_archive(
name = name,
repo = "pybind/pybind11",
commit = "0964a9093a728dbf67b9b98c6371752b1a346f25",
sha256 = "cf4cd95f8bb70dc205dd906e4c849f9fbc6a292653e4488860b18b9a581ebec2",
commit = "6d22dba82f1789f11a8eb2c2debbcbd4d2d8a969",
sha256 = "ecbce06af56a59f0c6bac5241c655fd67d8a107c9aa46249e90ea4ed0fb36c98",
build_file = Label("//tools/workspace/pybind11:package.BUILD"),
)
19 changes: 17 additions & 2 deletions tools/workspace/raspberrypi-firmware/package.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ config_setting(
values = {"cpu" : "aarch64"},
)

# Some distros, like Ubuntu, only have libbcm_host.so without a .0,
# however the official raspberry pi package expects the aarch64
# version to be libbcm_host.so.0.
#
# Make things work on both of them by manually patching the soname
# before linking. This will result in any libraries that link against
# this only requiring "libbcm_host.so".
genrule(
name = "soless_bcm_host",
outs = ["libbcm_host.so"],
srcs = ["aarch64/usr/lib/aarch64-linux-gnu/libbcm_host.so"],
cmd = "cp $< $@ && patchelf --set-soname libbcm_host.so $@",
)


cc_library(
name = "bcm_host",
hdrs = select({
Expand All @@ -42,7 +57,7 @@ cc_library(
}),
srcs = select({
":armeabihf" : ["hardfp/opt/vc/lib/libbcm_host.so"],
":aarch64" : ["aarch64/usr/lib/aarch64-linux-gnu/libbcm_host.so"],
":aarch64" : [":soless_bcm_host"],
}),
includes = select({
":armeabihf" : [
Expand All @@ -51,7 +66,7 @@ cc_library(
"aarch64" : [
"aarch64/usr/include",
],
})
}),
)

cc_library(
Expand Down

0 comments on commit 24e55f2

Please sign in to comment.