Files
swift-mirror/test/embedded/modules-used.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

51 lines
1.7 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %{python} %utils/split_file.py -o %t %s
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -emit-sil | %FileCheck %s --check-prefix CHECK-SIL
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -c -o %t/a.o
// RUN: %target-clang %t/a.o %target-embedded-posix-shim -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: OS=macosx
// REQUIRES: swift_feature_Embedded
// BEGIN MyModule.swift
@used
@section("__DATA,__mysection")
let i_am_not_referenced = 42
// BEGIN Main.swift
import MyModule
@_silgen_name(raw: "section$start$__DATA$__mysection")
var mysection_start: Int
@_silgen_name(raw: "section$end$__DATA$__mysection")
var mysection_end: Int
@main
struct Main {
static func main() {
let start = UnsafeRawPointer(&mysection_start)
let end = UnsafeRawPointer(&mysection_end)
let size = end - start
let count = size / (Int.bitWidth / 8)
print("count: \(count)")
let linker_set = UnsafeBufferPointer(start: start.bindMemory(to: Int.self, capacity: count), count: count)
for i in 0 ..< linker_set.count {
print("mysection[\(i)]: \(linker_set[i])")
}
}
}
// CHECK-SIL: // i_am_not_referenced
// CHECK-SIL-NEXT: sil_global [serialized] [let] [used] [section "__DATA,__mysection"] @$e8MyModule19i_am_not_referencedSivp : $Int = {
// CHECK: count: 1
// CHECK: mysection[0]: 42