Available target triples for cross compilation

I’m trying to make swiftc build for the ‘xtensa’ architecture (ESP32).

It appears that the latest nightly snapshot (from march 7th) is aware of the ‘xtensa’ architecture, which I understand that LLVM supports from release 16. Or at least I get a different error message when using the latest public release of swift 5.10 and the nightly snapshot.

But I cannot make swiftc accept a target triple like ‘xtensa-none-none-eabi’.

Is there any place I could find a list of supported triples?

1 Like

You can start with clang, which could be a first approximation for what architectures LLVM used in swiftc supports: clang -print-targets.

I'm not aware of a flag that makes swiftc print all available triples. An unknown triple that can be parsed in the embedded mode will trigger error output listing available embedded triples:

❯ touch test.swift
❯ swiftc -enable-experimental-feature Embedded \
  -wmo test.swift \
  -target m68k-none-none-eabi
<unknown>:0: error: could not find module 'Swift' for target 'm68k-none-none-eabi'; found: 
riscv32-none-none-eabi, x86_64-unknown-windows-coff, riscv64-none-none-eabi, i686-unknown-none-elf, armv7-apple-none-macho, armv6m-none-none-eabi, aarch64-none-none-elf, wasm64-unknown-none-wasm, arm64-apple-macos, x86_64-unknown-none-elf, arm64-apple-none-macho, armv7-none-none-eabi, armv7em-none-none-eabi, arm64e-apple-macos, x86_64-apple-macos, i686-unknown-windows-coff, armv6-apple-none-macho, armv6m-apple-none-macho, wasm32-unknown-none-wasm, armv7em-apple-none-macho, armv6-none-none-eabi, at: ~/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-03-07-a.xctoolchain/usr/lib/swift/embedded/Swift.swiftmodule

Another indicator is triple parsing code in Swift Driver, it doesn't have any mentions of xtensa: swift-driver/Sources/SwiftDriver/Utilities/Triple.swift at main · apple/swift-driver · GitHub

Thank you, @Max_Desiatov ! :blush:

I saw a post about xtensa support in llvm 16 and thought that I might be lucky that it was supported in Swift:

I found an ESP32 developer board in a drawer and hoped to be able to play around with getting Swift up and running for it. :grin: Without otherwise knowing what that would entail… :grimacing:

1 Like

It is worth noting that ESP32 comes in two flavors: riscv32 and xtensa. I don't think xtensa targets are supported yet in the llvm/clang swift uses (yet). The last time I looked at it there was a decent amount of work to do for getting that merged in, but maybe now that merge has occurred it is a bit less.

1 Like

The xtensa backend is WIP https://github.com/espressif/llvm-project

1 Like