Skip to content

Unable to build Swift library by adding custom target and dependency #1401

@oleksandr-kosylov

Description

@oleksandr-kosylov

In order to support ability to use Swift programming language with Embedded platform support, I've adjusted CMakeLists according to Example at https://github.com/apple/swift-embedded-examples/tree/main/esp32-led-strip-sdk
and installed dev snapshot of swift toolchain that supports embedded platforms.

Project structure:
src/
Main.swift
Dummy.c
BridgingHeader.h
CMakeLists.txt

platform.ini
[env:esp32-c6-devkitc-1]
platform = espressif32 @ 6.7.0
board = esp32-c6-devkitc-1
framework = espidf

Main idea of approach is to build Swift sources and link to main target.
It's being achieved by next steps:

  1. creating of custom command (add_custom_command) that produces library.o object.
  2. creating of custom target that depends on library.o (add_custom_target)
  3. linking of _idf_main with library.o
  4. setting dependency of _idf_main on custom target (add_dependencies)

This works fine from terminal by idf.py build BUT looks like custom command and target are not being built in VS Code with PlatformIO, I've tried to replace swift build command with test one and it's net being executed.

Build fails because of missing implementation for app_main function that is declared in Main.swift, so because of library wasn't built.

Please advice what can cause an ignoring of custom target and command by build system.
I see that build.ninja contains build commands for custom target and command based on CMakeLists.txt but looks they are not executed.

CMakeLists.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions