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
36 changes: 28 additions & 8 deletions .github/actions/install-swift/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ runs:
- name: Setup Environment
shell: bash
run: |
mkdir -p "$HOME/.local/share"

export SWIFTLY_TOOLCHAINS_DIR="$HOME/.local/share/swiftly/toolchains"
echo "SWIFTLY_TOOLCHAINS_DIR=$SWIFTLY_TOOLCHAINS_DIR" >> $GITHUB_ENV
echo "SWIFTLY_TOOLCHAINS_DIR=$SWIFTLY_TOOLCHAINS_DIR" >> $HOME/.bashrc
Expand All @@ -22,15 +24,15 @@ runs:
echo "PATH=$SWIFTLY_BIN_DIR:$PATH" >> $GITHUB_ENV
echo "PATH=\$SWIFTLY_BIN_DIR:\$PATH" >> $HOME/.bashrc

- name: "Restore: Swift"
- name: Restore Swift
uses: actions/cache/restore@v4
id: cache-swift
with:
path: "~/.local/share/swiftly"
key: swift-${{ hashFiles('**/.swift-version') }}
key: swift-${{ runner.os }}-${{ hashFiles('**/.swift-version', '.github/actions/install-swift/action.yml') }}

- name: Install `apt` Dependencies
if: steps.cache-swift.outputs.cache-hit != 'true'
if: runner.os == 'Linux' && steps.cache-swift.outputs.cache-hit != 'true'
shell: bash
run: |
SUDO=$(if [[ $EUID -ne 0 ]]; then echo sudo; fi)
Expand All @@ -40,29 +42,47 @@ runs:
DEBIAN_FRONTEND: noninteractive

- name: Install Swiftly
if: steps.cache-swift.outputs.cache-hit != 'true'
if: runner.os == 'Linux' && steps.cache-swift.outputs.cache-hit != 'true'
shell: bash
run: |
SWIFTLY_VERSION=1.0.1
UNAME=$(uname -m)
curl -O "https://download.swift.org/swiftly/linux/swiftly-$UNAME.tar.gz"
tar zxf "swiftly-$UNAME.tar.gz"
SWIFTLY_TGZ=swiftly-$SWIFTLY_VERSION-$UNAME.tar.gz
curl -O "https://download.swift.org/swiftly/linux/$SWIFTLY_TGZ"
tar zxf "$SWIFTLY_TGZ"
./swiftly init \
--skip-install \
--assume-yes \
--quiet-shell-followup \
--no-modify-profile

- name: Install Swiftly
if: runner.os == 'macOS' && steps.cache-swift.outputs.cache-hit != 'true'
shell: bash
run: |
SWIFTLY_VERSION=1.0.1
SWIFTLY_PKG=swiftly-$SWIFTLY_VERSION.pkg
curl -O "https://download.swift.org/swiftly/darwin/$SWIFTLY_PKG"
pkgutil --check-signature $SWIFTLY_PKG
pkgutil --verbose --expand $SWIFTLY_PKG $SWIFTLY_HOME_DIR
tar -C $SWIFTLY_HOME_DIR -xvf $SWIFTLY_HOME_DIR/swiftly-*/Payload
"$SWIFTLY_BIN_DIR/swiftly" init \
--skip-install \
--assume-yes \
--quiet-shell-followup \
--no-modify-profile

- name: Install Swift
if: steps.cache-swift.outputs.cache-hit != 'true'
shell: bash
run: swiftly install --post-install-file ./out.sh

- name: "Save: Swift"
- name: Save Swift
if: steps.cache-swift.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: "~/.local/share/swiftly"
key: swift-${{ hashFiles('**/.swift-version') }}
key: swift-${{ runner.os }}-${{ hashFiles('**/.swift-version', '.github/actions/install-swift/action.yml') }}

- name: Print Swift Version
shell: bash
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: STM32
name: STM32 ELF

on:
push:
Expand All @@ -15,16 +15,12 @@ jobs:
strategy:
fail-fast: false
matrix:
example: [stm32-blink, stm32-lvgl]
example: [stm32-lvgl]

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Fixup for running locally in act
if: ${{ env.ACT }}
run: echo /opt/acttoolcache/node/18.20.8/x64/bin >> $GITHUB_PATH

- name: Set up Python
uses: actions/setup-python@v5
with:
Expand All @@ -36,21 +32,11 @@ jobs:
- name: Install Swift
uses: ./.github/actions/install-swift

- name: Set environment variables
run: |
echo "STM_BOARD=STM32F746G_DISCOVERY" >> $GITHUB_ENV

- name: Build ${{ matrix.example }}
working-directory: ${{ matrix.example }}
run: |
if [[ -f ./fetch-dependencies.sh ]]; then
./fetch-dependencies.sh
fi

if [[ -f ./build-elf.sh ]]; then
./build-elf.sh
fi

if [[ -f Makefile ]]; then
make
fi
make
34 changes: 34 additions & 0 deletions .github/workflows/build-stm32-macho.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: STM32 Macho

on:
push:
branches: ["main"]
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
workflow_dispatch:

jobs:
build:
name: Build
runs-on: [self-hosted, macos, sequoia, ARM64]

strategy:
fail-fast: false
matrix:
example: [stm32-blink, stm32-lcd-logo, stm32-neopixel, stm32-uart-echo]

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: 3.11

- name: Install Swift
uses: ./.github/actions/install-swift

- name: Build ${{ matrix.example }}
working-directory: ${{ matrix.example }}
run: make
3 changes: 2 additions & 1 deletion .swiftformatignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
./harmony/*
./stm32-lvgl/*
./stm32-blink/Sources/STM32F7X6/*
./stm32-lcd-logo/Sources/STM32F7X6/*
./stm32-lvgl/*
./stm32-lvgl/Sources/Registers/*
./stm32-neopixel/Sources/STM32F7X6/*
./stm32-uart-echo/Sources/STM32F7X6/*
115 changes: 0 additions & 115 deletions stm32-blink/Board.swift

This file was deleted.

42 changes: 0 additions & 42 deletions stm32-blink/Main.swift

This file was deleted.

57 changes: 57 additions & 0 deletions stm32-blink/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift open source project
##
## Copyright (c) 2025 Apple Inc. and the Swift project authors.
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See https://swift.org/LICENSE.txt for license information
##
##===----------------------------------------------------------------------===##

# Paths
REPOROOT := $(shell git rev-parse --show-toplevel)
TOOLSROOT := $(REPOROOT)/Tools
TOOLSET := $(TOOLSROOT)/Toolsets/stm32f74x.json
MACHO2BIN := $(TOOLSROOT)/macho2bin.py
SWIFT_BUILD := swift build

# Flags
ARCH := armv7em
TARGET := $(ARCH)-apple-none-macho
SWIFT_BUILD_ARGS := \
--configuration release \
--triple $(TARGET) \
--toolset $(TOOLSET)
BUILDROOT := $(shell $(SWIFT_BUILD) $(SWIFT_BUILD_ARGS) --show-bin-path)

.PHONY: build
build:
@echo "building..."
$(SWIFT_BUILD) \
$(SWIFT_BUILD_ARGS) \
-Xlinker -map -Xlinker $(BUILDROOT)/Application.mangled.map \
--verbose

@echo "demangling linker map..."
cat $(BUILDROOT)/Application.mangled.map \
| c++filt | swift demangle > $(BUILDROOT)/Application.map

@echo "disassembling..."
otool \
-arch $(ARCH) -v -V -d -t \
$(BUILDROOT)/Application \
| c++filt | swift demangle > $(BUILDROOT)/Application.disassembly

@echo "extracting binary..."
$(MACHO2BIN) \
$(BUILDROOT)/Application \
$(BUILDROOT)/Application.bin \
--base-address 0x20010000 \
--segments '__TEXT,__DATA,__VECTORS'

.PHONY: clean
clean:
@echo "cleaning..."
@swift package clean
@rm -rf .build
Loading
Loading