Skip to content

Commit 8c523d1

Browse files
authored
Add CI via GitHub Actions (swiftlang#77)
Adds CI to ensure we can build the example code hosted in this repo. Additionally adopts the .swift-format config present in swift-mmio.
1 parent fc1942b commit 8c523d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1773
-985
lines changed

.github/workflows/build-esp.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Build ESP Examples
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
schedule:
9+
# Build on Mondays at 9am PST every week
10+
- cron: '0 17 * * 1'
11+
12+
jobs:
13+
build-esp:
14+
runs-on: ubuntu-24.04
15+
container: espressif/idf:latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
example: [esp32-led-blink-sdk, esp32-led-strip-sdk]
20+
swift: [swift-DEVELOPMENT-SNAPSHOT-2024-12-04-a]
21+
22+
steps:
23+
- name: Checkout repo
24+
uses: actions/checkout@v4
25+
26+
- name: Install apt dependencies
27+
run: apt-get -qq update && apt-get -qq -y install pkg-config
28+
29+
- name: Install ${{ matrix.swift }}
30+
run: |
31+
wget -q https://download.swift.org/development/ubuntu2404/${{ matrix.swift }}/${{ matrix.swift }}-ubuntu24.04.tar.gz
32+
tar xzf ${{ matrix.swift }}-ubuntu24.04.tar.gz
33+
export PATH="$PATH:`pwd`/${{ matrix.swift }}-ubuntu24.04/usr/bin/"
34+
echo "PATH=$PATH" >> $GITHUB_ENV
35+
swiftc --version
36+
37+
- name: Build ${{ matrix.example }}
38+
run: |
39+
cd $IDF_PATH
40+
. ./export.sh
41+
cd -
42+
cd ${{ matrix.example }}
43+
idf.py set-target esp32c6
44+
idf.py build

.github/workflows/build-pico-sdk.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Build Pico SDK Examples
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
schedule:
9+
# Build on Mondays at 9am PST every week
10+
- cron: '0 17 * * 1'
11+
12+
jobs:
13+
build-pico-sdk:
14+
runs-on: ubuntu-22.04
15+
container: swiftlang/swift:nightly-main-jammy
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
example:
20+
- name: pico-blink-sdk
21+
board: pico
22+
- name: pico-w-blink-sdk
23+
board: pico_w
24+
25+
steps:
26+
- name: Checkout repo
27+
uses: actions/checkout@v4
28+
29+
- name: Install apt dependencies
30+
run: apt-get -qq update && apt-get -qq -y install curl ninja-build python3
31+
32+
- name: Install CMake 3.30.2
33+
run: |
34+
ARCH=`uname -m`
35+
curl -sL https://github.com/Kitware/CMake/releases/download/v3.30.2/cmake-3.30.2-linux-$ARCH.tar.gz -O
36+
tar xzf cmake-3.30.2-linux-$ARCH.tar.gz
37+
export PATH="`pwd`/cmake-3.30.2-linux-$ARCH/bin:$PATH"
38+
echo "PATH=$PATH" >> $GITHUB_ENV
39+
cmake --version
40+
41+
- name: Clone Pico SDK
42+
run: |
43+
git clone https://github.com/raspberrypi/pico-sdk.git
44+
cd pico-sdk
45+
git submodule update --init --recursive
46+
cd ..
47+
48+
- name: Download GNU ARM toolchain
49+
run: |
50+
ARCH=`uname -m`
51+
curl -sL https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-$ARCH-arm-none-eabi.tar.xz -O
52+
tar xf arm-gnu-toolchain-13.3.rel1-$ARCH-arm-none-eabi.tar.xz
53+
54+
- name: Set Pico environment variables
55+
run: |
56+
ARCH=`uname -m`
57+
echo "PICO_BOARD=${{ matrix.example.board }}" >> $GITHUB_ENV
58+
echo "PICO_SDK_PATH=`pwd`/pico-sdk" >> $GITHUB_ENV
59+
echo "PICO_TOOLCHAIN_PATH=`pwd`/arm-gnu-toolchain-13.3.rel1-$ARCH-arm-none-eabi" >> $GITHUB_ENV
60+
61+
- name: Build ${{ matrix.example.name }}
62+
run: |
63+
cd ${{ matrix.example.name }}
64+
cmake -B build -G Ninja .
65+
cmake --build build

.github/workflows/build-zephyr.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build Zephyr Examples
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
schedule:
9+
# Build on Mondays at 9am PST every week
10+
- cron: '0 17 * * 1'
11+
12+
jobs:
13+
build-zephyr:
14+
runs-on: ubuntu-22.04
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
example: [nrfx-blink-sdk]
20+
swift: [swift-DEVELOPMENT-SNAPSHOT-2024-12-04-a]
21+
22+
steps:
23+
- name: Checkout repo
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: 3.11
30+
31+
- name: Setup Zephyr project
32+
uses: zephyrproject-rtos/action-zephyr-setup@v1
33+
with:
34+
app-path: ${{ matrix.example }}
35+
toolchains: arm-zephyr-eabi
36+
37+
- name: Install ${{ matrix.swift }}
38+
run: |
39+
wget -q https://download.swift.org/development/ubuntu2404/${{ matrix.swift }}/${{ matrix.swift }}-ubuntu24.04.tar.gz
40+
tar xzf ${{ matrix.swift }}-ubuntu24.04.tar.gz
41+
export PATH="$PATH:`pwd`/${{ matrix.swift }}-ubuntu24.04/usr/bin/"
42+
echo "PATH=$PATH" >> $GITHUB_ENV
43+
swiftc --version
44+
45+
- name: Build ${{ matrix.example }}
46+
working-directory: ${{ matrix.example }}
47+
run: west build -b nrf52840dk/nrf52840

.github/workflows/lint.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
jobs:
10+
lint:
11+
name: Lint
12+
runs-on: ubuntu-latest
13+
container: swift:6.0-jammy
14+
15+
steps:
16+
- name: Checkout repo
17+
uses: actions/checkout@v4
18+
19+
- name: Install apt dependencies
20+
run: apt-get -qq update && apt-get -qq -y install curl
21+
22+
- name: Compare against swift-mmio swift-format config
23+
run: |
24+
curl -sL https://raw.githubusercontent.com/apple/swift-mmio/refs/heads/main/SupportingFiles/Tools/swift-format/.swift-format -o .swift-format-mmio
25+
diff .swift-format .swift-format-mmio
26+
27+
- name: Lint
28+
run: swift-format lint --recursive --strict .

.swift-format

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"fileScopedDeclarationPrivacy" : {
3+
"accessLevel" : "private"
4+
},
5+
"indentation" : {
6+
"spaces" : 2
7+
},
8+
"indentConditionalCompilationBlocks" : false,
9+
"indentSwitchCaseLabels" : false,
10+
"lineBreakAroundMultilineExpressionChainComponents" : false,
11+
"lineBreakBeforeControlFlowKeywords" : false,
12+
"lineBreakBeforeEachArgument" : false,
13+
"lineBreakBeforeEachGenericRequirement" : false,
14+
"lineLength" : 80,
15+
"maximumBlankLines" : 1,
16+
"multiElementCollectionTrailingCommas" : true,
17+
"noAssignmentInExpressions" : {
18+
"allowedFunctions" : [
19+
"XCTAssertNoThrow"
20+
]
21+
},
22+
"prioritizeKeepingFunctionOutputTogether" : false,
23+
"respectsExistingLineBreaks" : true,
24+
"rules" : {
25+
"AllPublicDeclarationsHaveDocumentation" : false,
26+
"AlwaysUseLowerCamelCase" : true,
27+
"AmbiguousTrailingClosureOverload" : false,
28+
"BeginDocumentationCommentWithOneLineSummary" : false,
29+
"DoNotUseSemicolons" : true,
30+
"DontRepeatTypeInStaticProperties" : true,
31+
"FileScopedDeclarationPrivacy" : true,
32+
"FullyIndirectEnum" : true,
33+
"GroupNumericLiterals" : true,
34+
"IdentifiersMustBeASCII" : true,
35+
"NeverForceUnwrap" : true,
36+
"NeverUseForceTry" : true,
37+
"NeverUseImplicitlyUnwrappedOptionals" : true,
38+
"NoAccessLevelOnExtensionDeclaration" : true,
39+
"NoAssignmentInExpressions" : true,
40+
"NoBlockComments" : false,
41+
"NoCasesWithOnlyFallthrough" : true,
42+
"NoEmptyTrailingClosureParentheses" : true,
43+
"NoLabelsInCasePatterns" : true,
44+
"NoLeadingUnderscores" : false,
45+
"NoParensAroundConditions" : true,
46+
"NoPlaygroundLiterals" : true,
47+
"NoVoidReturnOnFunctionSignature" : true,
48+
"OmitExplicitReturns" : true,
49+
"OneCasePerLine" : true,
50+
"OneVariableDeclarationPerLine" : true,
51+
"OnlyOneTrailingClosureArgument" : true,
52+
"OrderedImports" : true,
53+
"ReplaceForEachWithForLoop" : true,
54+
"ReturnVoidInsteadOfEmptyTuple" : true,
55+
"TypeNamesShouldBeCapitalized" : true,
56+
"UseEarlyExits" : true,
57+
"UseLetInEveryBoundCaseVariable" : true,
58+
"UseShorthandTypeNames" : true,
59+
"UseSingleLinePropertyGetter" : true,
60+
"UseSynthesizedInitializer" : true,
61+
"UseTripleSlashForDocumentationComments" : true,
62+
"UseWhereClausesInForLoops" : false,
63+
"ValidateDocumentationComments" : true
64+
},
65+
"spacesBeforeEndOfLineComments": 2,
66+
"spacesAroundRangeFormationOperators" : false,
67+
"tabWidth" : 2,
68+
"version" : 1
69+
}

esp32-led-blink-sdk/main/Led.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct Led {
2323
fatalError("cannot reset led")
2424
}
2525
}
26-
func setLed(value:Bool) {
26+
func setLed(value: Bool) {
2727
let level: UInt32 = value ? 1 : 0
2828
gpio_set_level(ledPin, level)
2929
}

esp32-led-blink-sdk/main/Main.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
//
1010
//===----------------------------------------------------------------------===//
1111

12-
//The code will blink an LED on GPIO8. To change the pin, modify Led(gpioPin: 8)
12+
// The code will blink an LED on GPIO8. To change the pin, modify Led(gpioPin: 8)
1313
@_cdecl("app_main")
14-
func app_main() {
15-
print("Hello from Swift on ESP32-C6!")
14+
func main() {
15+
print("Hello from Swift on ESP32-C6!")
1616

17-
var ledValue: Bool = false
18-
let blinkDelayMs: UInt32 = 500
19-
let led = Led(gpioPin: 8)
17+
var ledValue: Bool = false
18+
let blinkDelayMs: UInt32 = 500
19+
let led = Led(gpioPin: 8)
2020

21-
while true {
22-
led.setLed(value: ledValue)
23-
ledValue.toggle() // Toggle the boolean value
24-
vTaskDelay(blinkDelayMs / (1000 / UInt32(configTICK_RATE_HZ)))
25-
}
21+
while true {
22+
led.setLed(value: ledValue)
23+
ledValue.toggle() // Toggle the boolean value
24+
vTaskDelay(blinkDelayMs / (1000 / UInt32(configTICK_RATE_HZ)))
25+
}
2626
}

esp32-led-strip-sdk/main/LedStrip.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// A simple "overlay" to provide nicer APIs in Swift
1313
struct LedStrip {
1414
private let handle: led_strip_handle_t
15+
1516
init(gpioPin: Int, maxLeds: Int) {
1617
var handle = led_strip_handle_t(bitPattern: 0)
1718
var stripConfig = led_strip_config_t(
@@ -26,24 +27,27 @@ struct LedStrip {
2627
spi_bus: SPI2_HOST,
2728
flags: .init(with_dma: 1)
2829
)
29-
guard led_strip_new_spi_device(&stripConfig, &spiConfig, &handle) == ESP_OK else {
30-
fatalError("cannot configure spi device")
31-
}
32-
self.handle = handle!
30+
guard led_strip_new_spi_device(&stripConfig, &spiConfig, &handle) == ESP_OK,
31+
let handle = handle
32+
else { fatalError("cannot configure spi device") }
33+
self.handle = handle
3334
}
3435

35-
struct Color {
36-
var r, g, b: UInt8
36+
struct Color {
3737
static var white = Color(r: 255, g: 255, b: 255)
3838
static var lightWhite = Color(r: 16, g: 16, b: 16)
39-
static var lightRandom: Color {
40-
Color(r: .random(in: 0...16), g: .random(in: 0...16), b: .random(in: 0...16))
39+
static var lightRandom: Color {
40+
Color(
41+
r: .random(in: 0...16), g: .random(in: 0...16), b: .random(in: 0...16))
4142
}
4243
static var off = Color(r: 0, g: 0, b: 0)
44+
45+
var r, g, b: UInt8
4346
}
4447

4548
func setPixel(index: Int, color: Color) {
46-
led_strip_set_pixel(handle, UInt32(index), UInt32(color.r), UInt32(color.g), UInt32(color.b))
49+
led_strip_set_pixel(
50+
handle, UInt32(index), UInt32(color.r), UInt32(color.g), UInt32(color.b))
4751
}
4852

4953
func refresh() { led_strip_refresh(handle) }

esp32-led-strip-sdk/main/Main.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
@_cdecl("app_main")
13-
func app_main() {
13+
func main() {
1414
print("Hello from Swift on ESP32-C6!")
1515

1616
let n = 8
@@ -22,11 +22,11 @@ func app_main() {
2222
colors.removeLast()
2323
colors.insert(.lightRandom, at: 0)
2424

25-
for index in 0 ..< n {
25+
for index in 0..<n {
2626
ledStrip.setPixel(index: index, color: colors[index])
2727
}
2828
ledStrip.refresh()
29-
29+
3030
let blinkDelayMs: UInt32 = 500
3131
vTaskDelay(blinkDelayMs / (1000 / UInt32(configTICK_RATE_HZ)))
3232
}

nrfx-blink-sdk/Main.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ struct Main {
1414
static func main() {
1515
// Note: & in Swift is not the "address of" operator, but on a global variable declared in C
1616
// it will give the correct address of the global.
17-
gpio_pin_configure_dt(&led0, GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH | GPIO_OUTPUT_INIT_LOGICAL)
17+
gpio_pin_configure_dt(
18+
&led0, GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH | GPIO_OUTPUT_INIT_LOGICAL)
1819
while true {
1920
gpio_pin_toggle_dt(&led0)
2021
k_msleep(100)

nrfx-blink-sdk/west.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
manifest:
2+
remotes:
3+
- name: zephyrproject-rtos
4+
url-base: https://github.com/zephyrproject-rtos
5+
6+
projects:
7+
- name: zephyr
8+
remote: zephyrproject-rtos
9+
revision: main
10+
import:
11+
name-allowlist:
12+
- cmsis # required by the ARM port
13+
- hal_nordic # required by the custom_plank board (Nordic based)

pico-blink-sdk/Main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct Main {
1414
static func main() {
1515
let led = UInt32(PICO_DEFAULT_LED_PIN)
1616
gpio_init(led)
17-
gpio_set_dir(led, /*out*/true)
17+
gpio_set_dir(led, /*out*/ true)
1818
while true {
1919
gpio_put(led, true)
2020
sleep_ms(250)

0 commit comments

Comments
 (0)