Files
swift-mirror/test/embedded/dependencies.swift
T
Doug Gregor ae1e3d0865 Build a static library that implements the Embedded Swift platform layer on POSIX
The new library, swiftEmbeddedPlatformPOSIX, implements all of the
_swift_XYZ functions needed to support Embedded Swift as shims on top
of a POSIX system that provides posix_memalign, free, putchar, and so
on. This offers an easier way to bridge between the prior ad hoc
requirements of Embedded Swift and the newer platform abstraction
layer.

Part of rdar://164057124
2026-03-03 09:05:30 -08:00

84 lines
2.2 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: split-file %s %t
// RUN: %target-swift-frontend -parse-as-library -enable-experimental-feature Extern -enable-experimental-feature Embedded %t/test.swift -c -o %t/a.o
// RUN: %llvm-nm --undefined-only --format=just-symbols %t/a.o | sort | tee %t/actual-dependencies.txt
// Fail if there is any entry in actual-dependencies.txt that's not in allowed-dependencies.txt
// RUN: %if OS=linux-gnu %{ comm -13 %t/allowed-dependencies_linux.txt %t/actual-dependencies.txt > %t/extra.txt %} %else %{ comm -13 %t/allowed-dependencies_macos.txt %t/actual-dependencies.txt > %t/extra.txt %}
// RUN: test ! -s %t/extra.txt
// Expects the POSIX-based dependencies, not the Embedded Swift platform ones.
// XFAIL: swift_embedded_platform
//--- allowed-dependencies_macos.txt
___stack_chk_fail
___stack_chk_guard
_free
_memmove
_memset
_posix_memalign
_putchar
//--- allowed-dependencies_linux.txt
__stack_chk_fail
__stack_chk_guard
free
memmove
memset
posix_memalign
putchar
//--- test.swift
// RUN: %target-clang -x c -c %S/Inputs/print.c -o %t/print.o
// RUN: %target-clang %t/a.o %t/print.o -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: OS=macosx || OS=linux-gnu
// REQUIRES: swift_feature_Embedded
// REQUIRES: swift_feature_Extern
// UNSUPPORTED: OS=linux-gnu && CPU=aarch64
@_extern(c, "putchar")
@discardableResult
func putchar(_: CInt) -> CInt
public func print(_ s: StaticString, terminator: StaticString = "\n") {
var p = s.utf8Start
while p.pointee != 0 {
putchar(CInt(p.pointee))
p += 1
}
p = terminator.utf8Start
while p.pointee != 0 {
putchar(CInt(p.pointee))
p += 1
}
}
class MyClass {
func foo() { print("MyClass.foo") }
}
class MySubClass: MyClass {
override func foo() { print("MySubClass.foo") }
}
@main
struct Main {
static var objects: [MyClass] = []
static func main() {
print("Hello Embedded Swift!")
// CHECK: Hello Embedded Swift!
objects.append(MyClass())
objects.append(MySubClass())
for o in objects {
o.foo()
}
// CHECK: MyClass.foo
// CHECK: MySubClass.foo
}
}