Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
env:
# For workflow dispatches the value will be overridden by the input.
PACKAGES:
DISTRO: ubuntu22.04

steps:
- name: Set packages variable
Expand All @@ -36,7 +37,7 @@ jobs:
id: runcmd
with:
arch: ${{ matrix.arch }}
distro: ubuntu22.04
distro: ${{ env.DISTRO }}

# Not required, but speeds up builds by storing container images in
# a GitHub package registry.
Expand Down Expand Up @@ -71,16 +72,16 @@ jobs:
${{env.PACKAGES}}

shell: /bin/bash

run: |
cd /
shopt -s extglob
tar c -zf /artifacts/sysroot-${{ matrix.arch }}.tar.gz *(lib|include) usr/*(lib|include) usr/local/*(lib|include)
cp /artifacts/sysroot-${{ matrix.arch }}.tar.gz /artifacts/sysroot-${{ matrix.arch }}-${{ env.DISTRO }}.tar.gz

- uses: actions/upload-artifact@v7
with:
name: sysroot-${{ matrix.arch }}
path: artifacts/sysroot-${{ matrix.arch }}.tar.gz
path: artifacts/sysroot-${{ matrix.arch }}*.tar.gz

- name: Upload release artifacts
if: |
Expand All @@ -89,7 +90,8 @@ jobs:
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: artifacts/sysroot-${{ matrix.arch }}.tar.gz
file: artifacts/sysroot-${{ matrix.arch }}*.tar.gz
file_glob: true
tag: ${{ github.ref }}
overwrite: true

Expand All @@ -108,6 +110,10 @@ jobs:
echo "PACKAGES=${{ github.event.inputs.packages }}" >> $GITHUB_ENV

- uses: actions/checkout@v6

- name: Get version
run: |
echo "VERSION=$(third_party/rpi/sysroot.py --distro raspbian --print-default-version)" >> $GITHUB_ENV

- name: Build
run: |
Expand All @@ -116,7 +122,7 @@ jobs:
third_party/rpi/sysroot.py \
--distro raspbian \
--sysroot $(realpath .) \
libc6-dev libstdc++-6-dev \
libc6-dev libstdc++-10-dev \
libgpiod-dev \
$PACKAGES

Expand All @@ -127,12 +133,13 @@ jobs:
bash <<'EOF'
shopt -s extglob
tar c -zf sysroot-raspbian.tar.gz *(lib|include) usr/*(lib|include)
cp sysroot-raspbian.tar.gz sysroot-raspbian-${{ env.VERSION }}.tar.gz
EOF

- uses: actions/upload-artifact@v7
with:
name: sysroot-raspbian
path: sysroot-raspbian.tar.gz
path: sysroot-raspbian*.tar.gz

- name: Upload release artifacts
if: |
Expand All @@ -141,7 +148,8 @@ jobs:
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: sysroot-raspbian.tar.gz
file: sysroot-raspbian*.tar.gz
file_glob: true
tag: ${{ github.ref }}
overwrite: true

Expand All @@ -154,6 +162,10 @@ jobs:
ARM_LINUX_GNUEABI_GCC_TOOLCHAIN_URL: https://releases.linaro.org/components/toolchain/binaries/latest-7/arm-linux-gnueabi/gcc-linaro-7.5.0-2019.12-i686_arm-linux-gnueabi.tar.xz

steps:
- name: Get version
run: |
VERSION=$(echo ${{ env.ARM_LINUX_GNUEABI_SYSROOT_URL }} | grep -oP 'glibc-linaro-\K[0-9.]+(?=-)')
echo "VERSION=glibc$VERSION" >> $GITHUB_ENV
- name: Download
run: |
curl --location --output sysroot.tar.xz $ARM_LINUX_GNUEABI_SYSROOT_URL
Expand All @@ -177,12 +189,13 @@ jobs:
arm-linux-gnueabi/*(lib|include) \
arm-linux-gnueabi/libc/*(lib|include) \
arm-linux-gnueabi/libc/usr/*(lib|include)
cp sysroot-arm-linux-gnueabi.tar.gz sysroot-arm-linux-gnueabi-${{ env.VERSION }}.tar.gz
EOF

- uses: actions/upload-artifact@v7
with:
name: sysroot-arm-linux-gnueabi
path: sysroot-arm-linux-gnueabi.tar.gz
path: sysroot-arm-linux-gnueabi*.tar.gz

- name: Upload release artifacts
if: |
Expand All @@ -191,6 +204,7 @@ jobs:
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: sysroot-arm-linux-gnueabi.tar.gz
file: sysroot-arm-linux-gnueabi*.tar.gz
file_glob: true
tag: ${{ github.ref }}
overwrite: true
54 changes: 38 additions & 16 deletions third_party/rpi/sysroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
from urllib.parse import urlparse
from gzip import GzipFile
from pathlib import Path
import subprocess
import subprocess
import tarfile
import shutil
import pickle
import os

# WARNING: this script does not verify integrity and signature of packages!

RASPBIAN_VERSION = "buster"
RASPBIAN_VERSION = "bullseye"
RASPBIAN_ARCHIVE = "http://archive.raspberrypi.org/debian"
RASPBIAN_MAIN = "http://raspbian.raspberrypi.org/raspbian"

UBUNTU_VERSION = "bionic"
UBUNTU_VERSION = "jammy"
UBUNTU_MAIN = "http://ports.ubuntu.com/ubuntu-ports"
UBUNTU_RPI = "http://ppa.launchpad.net/ubuntu-raspi2/ppa/ubuntu"

Expand Down Expand Up @@ -156,13 +156,23 @@ def resolve(package, packages, db):


def install(distro, version, target, sysroot, packages):

sysroot = Path(sysroot)
cache = sysroot / ".db.pickle"
if version is None:
if distro == "raspbian":
version = RASPBIAN_VERSION
elif distro == "ubuntu":
version = UBUNTU_VERSION
elif distro == "alpine":
version = ALPINE_VERSION

cache_name = f".db.{distro}.{version}.pickle"
if target:
cache_name = f".db.{distro}.{version}.{target}.pickle"
cache = sysroot / cache_name

if cache.is_file():
print("Loading package database...")

with open(cache, "rb") as f:
db = pickle.load(f)

Expand All @@ -171,18 +181,14 @@ def install(distro, version, target, sysroot, packages):

else:
print("Downloading package database...")

db = {}

if distro == "raspbian":
if version is None:
version = RASPBIAN_VERSION
deb_collect_packages(RASPBIAN_ARCHIVE, version, "main", db)
deb_collect_packages(RASPBIAN_MAIN, version, "main", db)

elif distro == "ubuntu":
if version is None:
version = UBUNTU_VERSION
deb_collect_packages(UBUNTU_RPI, version, "main", db)
for section in ["main", "universe"]:
deb_collect_packages(UBUNTU_MAIN, version, section, db)
Expand All @@ -201,10 +207,8 @@ def install(distro, version, target, sysroot, packages):

for repo in ALARM_REPOS:
alarm_collect_packages(arch, repo, db)

elif distro == "alpine":
if version is None:
version = ALPINE_VERSION
if target is None:
raise Exception("ALPINE target not specified (use --target argument)")
elif target.startswith("aarch64"):
Expand Down Expand Up @@ -271,9 +275,27 @@ def install(distro, version, target, sysroot, packages):
ap.add_argument("--distro", required=True, choices=["raspbian", "ubuntu", "alarm", "alpine"], help="distribution to use")
ap.add_argument("--version", help=f"distribution version to use for raspbian/ubuntu/alpine (default: {RASPBIAN_VERSION}/{UBUNTU_VERSION}/{ALPINE_VERSION})")
ap.add_argument("--target", help="target to download for alarm or alpine (ex: armv6l-unknown-linux-gnueabihf)")
ap.add_argument("--sysroot", required=True, help="sysroot folder")
ap.add_argument("packages", nargs="+")
ap.add_argument("--sysroot", help="sysroot folder")
ap.add_argument("--print-default-version", action="store_true", help="print default version for the given distro")
ap.add_argument("packages", nargs="*")
args = ap.parse_args()

if args.print_default_version:
if args.distro == "raspbian":
print(RASPBIAN_VERSION)
elif args.distro == "ubuntu":
print(UBUNTU_VERSION)
elif args.distro == "alpine":
print(ALPINE_VERSION)
else:
raise Exception(f"No default version for {args.distro}")
exit(0)

if not args.packages:
ap.error("the following arguments are required: packages")

if not args.sysroot:
ap.error("the following arguments are required: --sysroot")

os.makedirs(args.sysroot, exist_ok=True)
install(args.distro, args.version, args.target, args.sysroot, args.packages)
Loading