Skip to content

Commit 79b4a9f

Browse files
Add macOS ARM support for Thunderscope (UBC-Thunderbots#3496)
* add DS_Store to gitignore * add macos setup script * setup cross compiler headers * selectively ignore evdev * add chrono clock compat * add compat flags * do not link lstdc * add evdev import guards * selectively set network interface based on platform * revert requirements.txt and generate mac specific * resolve ubuntu failure * update req lock for linux * change bazelrc * [pre-commit.ci lite] apply automatic fixes * add cpp template type * [pre-commit.ci lite] apply automatic fixes * refactor setup script * address comments --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 22ca1ac commit 79b4a9f

26 files changed

Lines changed: 387 additions & 59 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,7 @@ src/.clangd
158158

159159
# external is a special directory for bazel so it should be ignored
160160
src/external
161+
162+
# macOS folder info
163+
.DS_Store
164+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ansible-lint==24.12.2
2+
pyqtgraph==0.13.7
3+
thefuzz==0.19.0
4+
iterfzf==0.5.0.20.0
5+
python-Levenshtein==0.25.1
6+
psutil==5.9.0
7+
PyOpenGL==3.1.6
8+
ruff==0.5.5
9+
pyqt-toast-notification==1.3.2
10+
grpcio-tools==1.71.0
11+
platformio==6.1.18
12+
pyqt6==6.9.1
13+

environment_setup/setup_software.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ print_status_msg "Done setting up cross compiler for robot software"
164164

165165
print_status_msg "Setting Up Python Development Headers"
166166
install_python_dev_cross_compile_headers $g_arch
167+
install_python_toolchain_headers
167168
print_status_msg "Done Setting Up Python Development Headers"
168169

169170
print_status_msg "Setting Up PlatformIO"
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
3+
# UBC Thunderbots macOS Software Setup
4+
#
5+
# This script will install all required libraries and dependencies to build
6+
# and run the Thunderbots codebase on macOS, including the AI and unit tests.
7+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
8+
9+
# Save the parent dir of this script
10+
CURR_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
11+
cd "$CURR_DIR" || exit
12+
13+
source util.sh
14+
15+
# Since we only support MacOS Arm chips (M series), we can use "Darwin" as the identifier
16+
# for mac setup procedures and ignore the architecture for now.
17+
sys=$(uname -s)
18+
19+
print_status_msg "Installing Utilities and Dependencies"
20+
21+
# Update Homebrew
22+
brew update
23+
24+
# Install required packages
25+
host_software_packages=(
26+
cmake@4
27+
python@3.12
28+
bazelisk
29+
openjdk@21
30+
pyqt@6
31+
qt@6
32+
node@20
33+
go@1.24
34+
clang-format@20
35+
)
36+
37+
for pkg in "${host_software_packages[@]}"; do
38+
if ! brew list "$pkg" &>/dev/null; then
39+
print_status_msg "Installing $pkg..."
40+
brew install "$pkg"
41+
else
42+
print_status_msg "$pkg already installed, skipping..."
43+
fi
44+
done
45+
46+
# Set up cache
47+
mkdir /tmp/tbots_download_cache
48+
49+
# Set up Python
50+
print_status_msg "Setting Up Python Environment"
51+
52+
# Create virtual environment
53+
sudo python3.12 -m venv /opt/tbotspython
54+
chmod
55+
source /opt/tbotspython/bin/activate
56+
57+
# Install Python dependencies
58+
sudo pip install --upgrade pip
59+
sudo pip install -r macos_requirements.txt
60+
61+
print_status_msg "Done Setting Up Python Environment"
62+
63+
print_status_msg "Fetching game controller"
64+
install_gamecontroller $sys
65+
66+
print_status_msg "Setting up TIGERS AutoRef"
67+
install_autoref $sys
68+
sudo chmod +x "$CURR_DIR/../src/software/autoref/run_autoref.sh"
69+
sudo cp "$CURR_DIR/../src/software/autoref/DIV_B.txt" "/opt/tbotspython/autoReferee/config/geometry/DIV_B.txt"
70+
print_status_msg "Finished setting up AutoRef"
71+
72+
print_status_msg "Setting up cross compiler for robot software"
73+
install_cross_compiler $sys
74+
print_status_msg "Done setting up cross compiler for robot software"
75+
76+
print_status_msg "Setting Up Python Development Headers"
77+
install_python_toolchain_headers
78+
print_status_msg "Done Setting Up Python Development Headers"
79+
80+
print_status_msg "Granting Permissions to /opt/tbotspython"
81+
sudo chown -R $(id -u):$(id -g) /opt/tbotspython
82+
print_status_msg "Done Granting Permissions to /opt/tbotspython"
83+
84+
print_status_msg "Set up ansible-lint"
85+
/opt/tbotspython/bin/ansible-galaxy collection install ansible.posix
86+
print_status_msg "Finished setting up ansible-lint"
87+
88+
print_status_msg "Software Setup Complete"
89+
print_status_msg "Note: Some changes require a new terminal session to take effect"
90+

environment_setup/util.sh

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
install_autoref() {
2-
autoref_commit=b30660b78728c3ce159de8ae096181a1ec52e9ba
3-
wget -N https://github.com/TIGERs-Mannheim/AutoReferee/archive/${autoref_commit}.zip -O /tmp/tbots_download_cache/autoReferee.zip
4-
unzip -q -o -d /tmp/tbots_download_cache/ /tmp/tbots_download_cache/autoReferee.zip
2+
if is_darwin $1; then
3+
autoref_version=1.5.5
4+
curl -L https://github.com/TIGERs-Mannheim/AutoReferee/releases/download/${autoref_version}/autoReferee.zip -o /tmp/tbots_download_cache/autoReferee.zip
5+
unzip -q -o -d /tmp/tbots_download_cache/ /tmp/tbots_download_cache/autoReferee.zip
56

6-
/tmp/tbots_download_cache/AutoReferee-${autoref_commit}/./gradlew installDist -p /tmp/tbots_download_cache/AutoReferee-${autoref_commit} -Dorg.gradle.java.home=/opt/tbotspython/bin/jdk
7-
mv /tmp/tbots_download_cache/AutoReferee-${autoref_commit}/build/install/autoReferee /opt/tbotspython/
8-
rm -rf /tmp/tbots_download_cache/autoReferee.zip /tmp/tbots_download_cache/AutoReferee-${autoref_commit}
7+
sudo mv /tmp/tbots_download_cache/autoReferee /opt/tbotspython/
8+
rm -rf /tmp/tbots_download_cache/autoReferee.zip
9+
else
10+
autoref_commit=b30660b78728c3ce159de8ae096181a1ec52e9ba
11+
wget -N https://github.com/TIGERs-Mannheim/AutoReferee/archive/${autoref_commit}.zip -O /tmp/tbots_download_cache/autoReferee.zip
12+
unzip -q -o -d /tmp/tbots_download_cache/ /tmp/tbots_download_cache/autoReferee.zip
13+
14+
/tmp/tbots_download_cache/AutoReferee-${autoref_commit}/./gradlew installDist -p /tmp/tbots_download_cache/AutoReferee-${autoref_commit} -Dorg.gradle.java.home=/opt/tbotspython/bin/jdk
15+
mv /tmp/tbots_download_cache/AutoReferee-${autoref_commit}/build/install/autoReferee /opt/tbotspython/
16+
rm -rf /tmp/tbots_download_cache/autoReferee.zip /tmp/tbots_download_cache/AutoReferee-${autoref_commit}
17+
fi
918
}
1019

1120
install_bazel() {
@@ -25,25 +34,47 @@ install_clang_format() {
2534

2635
install_cross_compiler() {
2736
file_name=aarch64-tbots-linux-gnu-for-aarch64
28-
if is_x86 $1; then
29-
file_name=aarch64-tbots-linux-gnu-for-x86
37+
if is_darwin $1; then
38+
full_file_name=$file_name.tar.xz
39+
curl -L "https://raw.githubusercontent.com/UBC-Thunderbots/Software-External-Dependencies/refs/heads/main/toolchain/$full_file_name" \
40+
-o /tmp/tbots_download_cache/$full_file_name
41+
tar -xf /tmp/tbots_download_cache/$full_file_name -C /tmp/tbots_download_cache/
42+
sudo mv /tmp/tbots_download_cache/aarch64-tbots-linux-gnu /opt/tbotspython
43+
rm /tmp/tbots_download_cache/$full_file_name
44+
else
45+
if is_x86 $1; then
46+
file_name=aarch64-tbots-linux-gnu-for-x86
47+
fi
48+
full_file_name=$file_name.tar.xz
49+
wget https://raw.githubusercontent.com/UBC-Thunderbots/Software-External-Dependencies/refs/heads/main/toolchain/$full_file_name -O /tmp/tbots_download_cache/$full_file_name
50+
tar -xf /tmp/tbots_download_cache/$full_file_name -C /tmp/tbots_download_cache/
51+
sudo mv /tmp/tbots_download_cache/aarch64-tbots-linux-gnu /opt/tbotspython
52+
rm /tmp/tbots_download_cache/$full_file_name
3053
fi
31-
full_file_name=$file_name.tar.xz
32-
wget https://raw.githubusercontent.com/UBC-Thunderbots/Software-External-Dependencies/refs/heads/main/toolchain/$full_file_name -O /tmp/tbots_download_cache/$full_file_name
33-
tar -xf /tmp/tbots_download_cache/$full_file_name -C /tmp/tbots_download_cache/
34-
sudo mv /tmp/tbots_download_cache/aarch64-tbots-linux-gnu /opt/tbotspython
35-
rm /tmp/tbots_download_cache/$full_file_name
3654
}
3755

3856
install_gamecontroller () {
39-
arch=arm64
40-
if is_x86 $1; then
41-
arch=amd64
42-
fi
57+
if is_darwin $1; then
58+
curl -L https://github.com/RoboCup-SSL/ssl-game-controller/archive/refs/tags/v3.17.0.zip -o /tmp/tbots_download_cache/ssl-game-controller.zip
59+
unzip -q -o -d /tmp/tbots_download_cache/ /tmp/tbots_download_cache/ssl-game-controller.zip
60+
cd /tmp/tbots_download_cache/ssl-game-controller-3.17.0
61+
make install
62+
go build cmd/ssl-game-controller/main.go
63+
sudo mv main /opt/tbotspython/gamecontroller
64+
sudo chmod +x /opt/tbotspython/gamecontroller
65+
66+
cd -
67+
sudo rm -rf /tmp/tbots_download_cache/ssl-game-controller-3.17.0 /tmp/tbots_download_cache/go /tmp/tbots_download_cache/go.tar.gz /tmp/tbots_download_cache/ssl-game-controller.zip
68+
else
69+
arch=arm64
70+
if is_x86 $1; then
71+
arch=amd64
72+
fi
4373

44-
wget https://github.com/RoboCup-SSL/ssl-game-controller/releases/download/v3.16.1/ssl-game-controller_v3.16.1_linux_${arch} -O /tmp/tbots_download_cache/gamecontroller
45-
sudo mv /tmp/tbots_download_cache/gamecontroller /opt/tbotspython/gamecontroller
46-
sudo chmod +x /opt/tbotspython/gamecontroller
74+
wget https://github.com/RoboCup-SSL/ssl-game-controller/releases/download/v3.16.1/ssl-game-controller_v3.16.1_linux_${arch} -O /tmp/tbots_download_cache/gamecontroller
75+
sudo mv /tmp/tbots_download_cache/gamecontroller /opt/tbotspython/gamecontroller
76+
sudo chmod +x /opt/tbotspython/gamecontroller
77+
fi
4778
}
4879

4980
install_java () {
@@ -90,6 +121,11 @@ install_python_dev_cross_compile_headers() {
90121
rm -rf /tmp/tbots_download_cache/python-3.12.0.tar.xz
91122
}
92123

124+
install_python_toolchain_headers() {
125+
sudo mkdir -p /opt/tbotspython/py_headers/include/
126+
sudo ln -sfn "$(python3.12-config --includes | awk '{for(i=1;i<=NF;++i) if ($i ~ /^-I/) print substr($i, 3)}' | head -n1)" /opt/tbotspython/py_headers/include/
127+
}
128+
93129
is_x86() {
94130
if [[ $1 == "x86_64" ]]; then
95131
return 0
@@ -98,6 +134,14 @@ is_x86() {
98134
fi
99135
}
100136

137+
is_darwin() {
138+
if [[ $1 == "Darwin" ]]; then
139+
return 0
140+
else
141+
return 1
142+
fi
143+
}
144+
101145
print_status_msg () {
102146
echo "================================================================"
103147
echo $1

src/.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ build --incompatible_remove_legacy_whole_archive=False
6666

6767
# Escalate Warnings to fail Compile for Thunderbots code
6868
build --features=external_include_paths
69-
build --per_file_copt=proto/.*,proto/message_translation/.*,proto/primitive/.*,software/.*,shared/.*,-external/.*@-Wall,-Wextra,-Wno-unused-parameter,-Wno-deprecated,-Werror,-Wno-deprecated-declarations
69+
build:linux --per_file_copt=proto/.*,proto/message_translation/.*,proto/primitive/.*,software/.*,shared/.*,-external/.*@-Wall,-Wextra,-Wno-unused-parameter,-Wno-deprecated,-Werror,-Wno-deprecated-declarations
7070
# TODO: #3492
7171
# build --per_file_copt=software/.*,shared/.*,-external/.*@-Wconversion
7272

src/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ new_local_repository(
268268
new_local_repository(
269269
name = "py_cc_toolchain_host",
270270
build_file = "@//extlibs:py_cc_toolchain.BUILD",
271-
path = "/usr/include/python3.12/",
271+
path = "/opt/tbotspython/py_headers/include/python3.12/",
272272
)
273273

274274
new_local_repository(

src/extlibs/er_force_sim/src/amun/simulator/simulator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,13 @@ void Simulator::handleSimulatorSetupCommand(const std::unique_ptr<amun::Command>
677677

678678
if (realism.has_vision_delay())
679679
{
680-
m_visionDelay = std::max(0l, realism.vision_delay());
680+
m_visionDelay = std::max<int64_t>(0l, realism.vision_delay());
681681
}
682682

683683
if (realism.has_vision_processing_time())
684684
{
685-
m_visionProcessingTime = std::max(0l, realism.vision_processing_time());
685+
m_visionProcessingTime =
686+
std::max<int64_t>(0l, realism.vision_processing_time());
686687
}
687688

688689
if (realism.has_simulate_dribbling())

src/software/ai/hl/stp/play/play.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ std::unique_ptr<TbotsProto::PrimitiveSet> Play::get(
207207
new_primitives_to_assign->robot_primitives())
208208
{
209209
primitives_to_run->mutable_robot_primitives()->insert(
210-
google::protobuf::MapPair(robot_id, primitive));
210+
google::protobuf::MapPair<uint32_t, TbotsProto::Primitive>(
211+
robot_id, primitive));
211212
}
212213

213214
robots = remaining_robots;

src/software/logger/BUILD

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ cc_library(
99
"log_merger.h",
1010
],
1111
deps = [
12+
":compat_flags",
1213
"@g3log",
1314
],
1415
)
@@ -19,9 +20,13 @@ cc_library(
1920
"custom_logging_levels.h",
2021
"logger.h",
2122
],
22-
linkopts = ["-lstdc++fs"],
23+
linkopts = select({
24+
"@platforms//os:linux": ["-lstdc++fs"],
25+
"//conditions:default": [],
26+
}),
2327
deps = [
2428
":coloured_cout_sink",
29+
":compat_flags",
2530
":csv_sink",
2631
":log_merger",
2732
":plotjuggler_sink",
@@ -103,6 +108,7 @@ cc_library(
103108
"custom_logging_levels.h",
104109
],
105110
deps = [
111+
":compat_flags",
106112
"@g3log",
107113
],
108114
)
@@ -182,10 +188,16 @@ cc_library(
182188
"proto_logger.h",
183189
],
184190
deps = [
191+
":compat_flags",
185192
"//proto:tbots_cc_proto",
186193
"//software/multithreading:thread_safe_buffer",
187194
"@base64",
188195
"@boost//:filesystem",
189196
"@zlib",
190197
],
191198
)
199+
200+
cc_library(
201+
name = "compat_flags",
202+
srcs = ["compat_flags.h"],
203+
)

0 commit comments

Comments
 (0)