mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This isn't a "complete" port of the standard library for embedded Swift, but something that should serve as a starting point for further iterations on the stdlib. - General CMake logic for building a library as ".swiftmodule only" (ONLY_SWIFTMODULE). - CMake logic in stdlib/public/core/CMakeLists.txt to start building the embedded stdlib for a handful of hardcoded target triples. - Lots of annotations throughout the standard library to make types, functions, protocols unavailable in embedded Swift (@_unavailableInEmbedded). - Mainly this is about stdlib functionality that relies on existentials, type erasure, metatypes, reflection, string interpolations. - We rely on function body removal of unavailable functions to eliminate the actual problematic SIL code (existentials). - Many .swift files are not included in the compilation of embedded stdlib at all, to simplify the scope of the annotations. - EmbeddedStubs.swift is used to stub out (as unavailable and fatalError'd) the missing functionality.
29 lines
763 B
Swift
29 lines
763 B
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-frontend -target arm64-apple-none-macho -Xcc -D__MACH__ -Xcc -D__arm64__ -Xcc -D__APPLE__ \
|
|
// RUN: -enable-experimental-feature Embedded -enforce-exclusivity=none %s -c -o %t/a.o
|
|
// RUN: %target-clang %t/a.o -o %t/a.out
|
|
// RUN: %target-run %t/a.out | %FileCheck %s
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: VENDOR=apple
|
|
// REQUIRES: CPU=arm64
|
|
|
|
@_silgen_name("putchar")
|
|
func putchar(_: UInt8)
|
|
|
|
public func print(_ s: StaticString, terminator: StaticString = "\n") {
|
|
var p = s.utf8Start
|
|
while p.pointee != 0 {
|
|
putchar(p.pointee)
|
|
p += 1
|
|
}
|
|
p = terminator.utf8Start
|
|
while p.pointee != 0 {
|
|
putchar(p.pointee)
|
|
p += 1
|
|
}
|
|
}
|
|
|
|
print("Hello, Embedded Swift!")
|
|
// CHECK: Hello, Embedded Swift!
|