Hello!
I'm trying to use swift-mmio, but I seem to be encountering some issues trying to build it for aarch64-none-none-elf
without a memory allocator. I actually want to use Swift to write a memory allocator, so I can't really have one already.
I'm using SwiftPM to create a static library for the part of my project written in Swift, which does build successfully, but then I link that with the ARM cross-compiler to the assembly and C startup code, which... fails since I don't have a memory allocator. So I tried to build my Swift code with the build option -Xswiftc -no-allocations
, since it worked with the Swift compiler, but that seems to fail too saying -no-allocations is only applicable with embedded Swift.
So now I don't really know what to do, I don't know if swift-mmio just doesn't work without a memory allocator, if my toolchain is misbehaving (happened before), or if I'm doing something wrong.
I know that in the swift-embedded-examples, the projects get built for *-apple-none-macho
triples, so maybe the solution is an arm64-apple-none-macho
build?, but for now I'm trying to get this one working.
My Package.swift:
// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "app",
platforms: [
.macOS(.v14),
],
products: [
.library(name: "appSwift", type: .static, targets: ["appSwift"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-mmio.git", branch: "swift-embedded-examples"),
],
targets: [
.target(
name: "appSwift",
dependencies: [
.product(name: "MMIO", package: "swift-mmio"),
],
path: "./src/swift",
swiftSettings: [
.enableExperimentalFeature("Embedded"),
.unsafeFlags(["-wmo", "-no-allocations", "-disable-cmo", "-Xfrontend", "-gnone", "-Xfrontend", "-disable-stack-protector", "-no-allocations"])
]
),
]
)
My build command (working):
swift build --configuration release --verbose --triple aarch64-none-none-elf -Xswiftc -Xfrontend -Xswiftc -disable-stack-protector
Other build command (not working):
swift build --configuration release --verbose --triple aarch64-none-none-elf -Xswiftc -Xfrontend -Xswiftc -disable-stack-protector -Xswiftc -no-allocations
Lastly the file I'm trying to compile:
import MMIO
@_cdecl("asd")
public func asd(x: Int) -> Int {
return x + 1
}
If I'm overlooking something trivial, I'm really sorry to bother y'all with this. I understand that both Swift Embedded and swift-mmio are in relatively early development, so they might have bugs or might not have certain features yet, which is totally fine, I just want to make sure if I should continue pursuing this at the moment or not.
Thanks for the help!