From 74b2ffdde285d90dd143bfeb7fe8ca64b4a2a147 Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Tue, 10 Sep 2024 13:20:09 -0700 Subject: [PATCH 1/4] .gitmodules: use https urls for all public repos --- .gitmodules | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index cfee0c72..6cc372ef 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,10 +10,10 @@ shallow = true [submodule "components/autopilot/ardupilot"] path = components/autopilot/ardupilot - url = git@github.com:ArduPilot/ardupilot.git + url = https://github.com/ArduPilot/ardupilot.git [submodule "components/message_bus/czmq"] path = components/message_bus/czmq - url = git@github.com:zeromq/czmq.git + url = https://github.com/zeromq/czmq.git [submodule "src/pkvm_setup/vhost-device"] path = src/pkvm_setup/vhost-device url = git@github.com:GaloisInc/verse-vhost-device.git From edb407e8310b75e5cbcd4871e7123a6c0de8115c Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Tue, 10 Sep 2024 13:17:28 -0700 Subject: [PATCH 2/4] ardupilot: add to package.sh and CI --- .github/workflows/main.yml | 37 ++++++++++++ components/autopilot/ardupilot_build.sh | 18 ++++++ .../autopilot/ardupilot_init_submodules.sh | 22 +++++++ .../autopilot/ardupilot_install_deps.sh | 57 +++++++++++++++++++ src/pkvm_setup/package.sh | 22 +++++++ 5 files changed, 156 insertions(+) create mode 100644 components/autopilot/ardupilot_build.sh create mode 100644 components/autopilot/ardupilot_init_submodules.sh create mode 100644 components/autopilot/ardupilot_install_deps.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 11686687..c1a6d464 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -410,3 +410,40 @@ jobs: rust-version: 1.74 - name: Run MPS tests run: RUST_LOG=trace MPS_DEBUG=1 python3 src/vm_runner/tests/mps/run_tests.py + + ardupilot: + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Checkout submodules + run: | + git submodule update --init components/autopilot/ardupilot + - name: Hash inputs + id: hash + run: | + cache_key="$(bash src/pkvm_setup/package.sh cache_key ardupilot)" + echo "Cache key: $cache_key" + echo "CACHE_KEY=$cache_key" >>$GITHUB_OUTPUT + echo "CACHE_KEY=$cache_key" >>$GITHUB_ENV + - name: Cache results + id: cache + uses: actions/cache@v3 + with: + key: ${{ env.CACHE_KEY }} + path: packages/${{ env.CACHE_KEY }}.tar.gz + - if: ${{ steps.cache.outputs.cache-hit != 'true' }} + name: Install dependencies + run: | + BUILD_ONLY=1 bash components/autopilot/ardupilot_install_deps.sh + - if: ${{ steps.cache.outputs.cache-hit != 'true' }} + name: Fetch additional submodules for build + run: | + bash components/autopilot/ardupilot_init_submodules.sh + - if: ${{ steps.cache.outputs.cache-hit != 'true' }} + name: Build ArduPilot + run: | + bash src/pkvm_setup/package.sh full_build ardupilot + outputs: + CACHE_KEY: ${{ steps.hash.outputs.CACHE_KEY }} + diff --git a/components/autopilot/ardupilot_build.sh b/components/autopilot/ardupilot_build.sh new file mode 100644 index 00000000..89bdd256 --- /dev/null +++ b/components/autopilot/ardupilot_build.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -euo pipefail + +# Script for installing ArduPilot build dependencies. + +cd "$(dirname "$0")/ardupilot" + +edo() { + echo " >> $*" 1>&2 + "$@" +} + +. venv/bin/activate +export CC=aarch64-linux-gnu-gcc +export CXX=aarch64-linux-gnu-g++ +export LD=aarch64-linux-gnu-g++ +./waf -o build.aarch64 configure --board sitl +./waf -o build.aarch64 build --target bin/arduplane diff --git a/components/autopilot/ardupilot_init_submodules.sh b/components/autopilot/ardupilot_init_submodules.sh new file mode 100644 index 00000000..75c82ace --- /dev/null +++ b/components/autopilot/ardupilot_init_submodules.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -euo pipefail + +# Initialize additional submodules that are needed for the ArduPilot build. + +cd "$(dirname "$0")/ardupilot" + +edo() { + echo " >> $*" 1>&2 + "$@" +} + +modules=( + waf + DroneCAN/dronecan_dsdlc + DroneCAN/pydronecan + DroneCAN/DSDL + DroneCAN/libcanard +) +for x in "${modules[@]}"; do + edo git submodule update --init "modules/$x" +done diff --git a/components/autopilot/ardupilot_install_deps.sh b/components/autopilot/ardupilot_install_deps.sh new file mode 100644 index 00000000..4af56fc2 --- /dev/null +++ b/components/autopilot/ardupilot_install_deps.sh @@ -0,0 +1,57 @@ +#!/bin/bash +set -euo pipefail + +# Script for installing ArduPilot build dependencies. + +cd "$(dirname "$0")/ardupilot" + +edo() { + echo " >> $*" 1>&2 + "$@" +} + +first() { + echo "$1" +} + +install_if_missing() { + local package="$1" + local file="$2" + + # If `$2` is a glob pattern, expand it to the first matching file if one + # exists. + if [[ ! -f "$(IFS='' first $file)" ]]; then + echo "missing $file - need to install package $package" 1>&2 + edo sudo apt-get install -y "$package" + if [[ ! -f "$(IFS='' first $file)" ]]; then + echo "actual contents of $package:" 1>&2 + dpkg-query -L "$package" 1>&2 + echo "error: expected package $package to provide $file, but it did not" 1>&2 + return 1 + fi + fi +} + +# Create Python virtualenv if it doesn't yet exist. +if [[ ! -d venv ]]; then + edo install_if_missing python3-virtualenv /usr/bin/virtualenv + virtualenv venv +fi + +# Install Python dependencies into the virtualenv. `pip install` is a no-op if +# the package is already installed. +( + . venv/bin/activate + pip3 install pexpect empy==3.3.4 future + if [[ -z "${BUILD_ONLY:+x}" ]]; then + pip3 install pymavlink MAVProxy opencv-python matplotlib + + # Extra system package needed for building wxPython + edo install_if_missing libgtk-3-dev /usr/lib/*/pkgconfig/gtk+-3.0.pc + # Note: the wxPython install builds from source, which takes a while + pip3 install wxPython + fi +) + +install_if_missing gcc-aarch64-linux-gnu /usr/bin/aarch64-linux-gnu-gcc +install_if_missing g++-aarch64-linux-gnu /usr/bin/aarch64-linux-gnu-g++ diff --git a/src/pkvm_setup/package.sh b/src/pkvm_setup/package.sh index 3c087fdc..18a07bdf 100644 --- a/src/pkvm_setup/package.sh +++ b/src/pkvm_setup/package.sh @@ -247,6 +247,28 @@ vm_images_list_outputs() { } +# ardupilot + +ardupilot_get_input_hashes() { + ( + cd components/autopilot + sha1sum ardupilot_build.sh + sha1sum ardupilot_init_submodules.sh + sha1sum ardupilot_install_deps.sh + ) + ( cd components/autopilot/ardupilot && git rev-parse HEAD:./ ) +} + +ardupilot_build() { + bash components/autopilot/ardupilot_build.sh +} + +ardupilot_list_outputs() { + echo components/autopilot/ardupilot/build.aarch64/sitl/bin/arduplane + echo components/autopilot/ardupilot/Tools/autotest/models/plane.parm +} + + # Actions. Each `do_foo` function can be called via `bash package.sh foo # package_name`. From e4de5aba76a115e40bdefa892685d5e273147de8 Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Tue, 10 Sep 2024 16:54:14 -0700 Subject: [PATCH 3/4] ardupilot: add more comments to build scripts --- components/autopilot/ardupilot_build.sh | 2 +- components/autopilot/ardupilot_init_submodules.sh | 3 ++- components/autopilot/ardupilot_install_deps.sh | 10 +++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/components/autopilot/ardupilot_build.sh b/components/autopilot/ardupilot_build.sh index 89bdd256..a38028d4 100644 --- a/components/autopilot/ardupilot_build.sh +++ b/components/autopilot/ardupilot_build.sh @@ -1,7 +1,7 @@ #!/bin/bash set -euo pipefail -# Script for installing ArduPilot build dependencies. +# Build the ArduPilot SITL binary for aarch64. cd "$(dirname "$0")/ardupilot" diff --git a/components/autopilot/ardupilot_init_submodules.sh b/components/autopilot/ardupilot_init_submodules.sh index 75c82ace..9bc67988 100644 --- a/components/autopilot/ardupilot_init_submodules.sh +++ b/components/autopilot/ardupilot_init_submodules.sh @@ -1,7 +1,7 @@ #!/bin/bash set -euo pipefail -# Initialize additional submodules that are needed for the ArduPilot build. +# Initialize ArduPilot submodules that are needed for the SITL build. cd "$(dirname "$0")/ardupilot" @@ -17,6 +17,7 @@ modules=( DroneCAN/DSDL DroneCAN/libcanard ) + for x in "${modules[@]}"; do edo git submodule update --init "modules/$x" done diff --git a/components/autopilot/ardupilot_install_deps.sh b/components/autopilot/ardupilot_install_deps.sh index 4af56fc2..f020b4b5 100644 --- a/components/autopilot/ardupilot_install_deps.sh +++ b/components/autopilot/ardupilot_install_deps.sh @@ -1,7 +1,10 @@ #!/bin/bash set -euo pipefail -# Script for installing ArduPilot build dependencies. +# Script for installing ArduPilot build dependencies. Run with `BUILD_ONLY=1` +# to install only the dependencies required to build ArduPilot SITL binaries; +# the default is to install these and also dependencies of the mavproxy ground +# station software. cd "$(dirname "$0")/ardupilot" @@ -10,10 +13,15 @@ edo() { "$@" } +# Echo the first argument. This is useful for expanding a (possible) glob +# pattern to a single concrete filename. first() { echo "$1" } +# Install a package with `apt-get`, but only if a certain file is missing from +# the system. Running `apt-get install` on an already-installed package is a +# no-op, but we'd like to avoid asking for `sudo` privileges unnecessarily. install_if_missing() { local package="$1" local file="$2" From 5f84a4f66dfef45cf237006dce45d57b3b3e9307 Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Wed, 18 Sep 2024 12:01:11 -0700 Subject: [PATCH 4/4] autopilot: update build script to support native builds --- components/autopilot/ardupilot_build.sh | 25 ++++++++++++++++++++----- src/pkvm_setup/package.sh | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/components/autopilot/ardupilot_build.sh b/components/autopilot/ardupilot_build.sh index a38028d4..696fbe33 100644 --- a/components/autopilot/ardupilot_build.sh +++ b/components/autopilot/ardupilot_build.sh @@ -3,6 +3,16 @@ set -euo pipefail # Build the ArduPilot SITL binary for aarch64. +target= +if [[ "$#" -ne 0 ]]; then + target="$1" +fi + +build_dir=build +if [[ -n "$target" ]]; then + build_dir="$build_dir.$target" +fi + cd "$(dirname "$0")/ardupilot" edo() { @@ -10,9 +20,14 @@ edo() { "$@" } +case "$target" in + aarch64) + export CC=aarch64-linux-gnu-gcc + export CXX=aarch64-linux-gnu-g++ + export LD=aarch64-linux-gnu-g++ + ;; +esac + . venv/bin/activate -export CC=aarch64-linux-gnu-gcc -export CXX=aarch64-linux-gnu-g++ -export LD=aarch64-linux-gnu-g++ -./waf -o build.aarch64 configure --board sitl -./waf -o build.aarch64 build --target bin/arduplane +./waf -o "${build_dir}" configure --board sitl +./waf -o "${build_dir}" build --target bin/arduplane diff --git a/src/pkvm_setup/package.sh b/src/pkvm_setup/package.sh index 18a07bdf..a0912983 100644 --- a/src/pkvm_setup/package.sh +++ b/src/pkvm_setup/package.sh @@ -260,7 +260,7 @@ ardupilot_get_input_hashes() { } ardupilot_build() { - bash components/autopilot/ardupilot_build.sh + bash components/autopilot/ardupilot_build.sh aarch64 } ardupilot_list_outputs() {