Import Foundation failed

I try to go thru Baremetal example (Documentation) and after some not so smooth digging, almost at the end of setup process and few minutes of compiling I got an error (!):

Building for production...
/Users/lukasz/Documents/STM32/STM32BlinkLed/.build/checkouts/swift-mmio/Sources/MMIO/FixedWidthInteger+Bits.swift:12:8: error: no such module 'Foundation'
10 | //===----------------------------------------------------------------------===//
11 | 
12 | import Foundation
   |        `- error: no such module 'Foundation'
13 | 
14 | extension FixedWidthInteger {

How it's even possible?

I have a fresh:

% swift --version
Apple Swift version 6.2-dev (LLVM d266fd9f80a7945, Swift 665515c781999a8)
Target: arm64-apple-macosx15.0
Build config: +assertions

I have no idea where to dig now.

I don't think Foundation currently supports Embedded mode. You can definitely use the swift standard library (implicitly imported Swift module), including parts of the Concurrency module. However, last time I checked, Foundation wasn't supported. That's because Foundation relies on several system APIs that don't come out of the box with Embedded environments, not to mention the use of features like existential any for protocols.

Error comes from MMIO package, it's hard to avoid it...

1 Like

@typoland Apologies for this, I recently refactored that code out of a different file and Xcode "helpfully" added import Foundation when I created the file. Removing the import is the correct solution and I'll put up a PR to resolve this right now.

I'm also looking into a general solution for embedded CI testing for swiftlang repos to avoid breaks like this in the future.

edit: Remove spurious foundation import by rauhul ¡ Pull Request #168 ¡ apple/swift-mmio ¡ GitHub

edit 2: merged

8 Likes