Skip to content

[embedded] Start building embedded support on Linux/ELF, expand archs of the embedded stdlib to cover common embedded targets, take 2 #70064

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmake/modules/SwiftSetIfArchBitness.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ function(set_if_arch_bitness var_name)
"${SIA_ARCH}" STREQUAL "x86" OR
"${SIA_ARCH}" STREQUAL "armv5" OR
"${SIA_ARCH}" STREQUAL "armv6" OR
"${SIA_ARCH}" STREQUAL "armv6m" OR
"${SIA_ARCH}" STREQUAL "armv7" OR
"${SIA_ARCH}" STREQUAL "armv7k" OR
"${SIA_ARCH}" STREQUAL "arm64_32" OR
"${SIA_ARCH}" STREQUAL "armv7m" OR
"${SIA_ARCH}" STREQUAL "armv7em" OR
"${SIA_ARCH}" STREQUAL "armv7s" OR
"${SIA_ARCH}" STREQUAL "riscv32" OR
"${SIA_ARCH}" STREQUAL "wasm32" OR
"${SIA_ARCH}" STREQUAL "powerpc")
set("${var_name}" "${SIA_CASE_32_BIT}" PARENT_SCOPE)
Expand Down
32 changes: 28 additions & 4 deletions stdlib/public/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ option(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB
"Enable build of the embedded Swift standard library and runtime"
TRUE)

if(NOT SWIFT_HOST_VARIANT STREQUAL "macosx")
if((NOT SWIFT_HOST_VARIANT STREQUAL "macosx") AND (NOT SWIFT_HOST_VARIANT STREQUAL "linux"))
set(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB FALSE)
elseif(NOT SWIFT_INCLUDE_TOOLS)
# Temporarily, only build embedded stdlib when building the compiler, to
Expand All @@ -151,12 +151,36 @@ endif()
if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
set(EMBEDDED_STDLIB_TARGET_TRIPLES
# arch module_name target triple
"armv6 armv6-apple-none-macho armv6-apple-none-macho"
"armv6m armv6m-apple-none-macho armv6m-apple-none-macho"
"armv7 armv7-apple-none-macho armv7-apple-none-macho"
"armv7em armv7em-apple-none-macho armv7em-apple-none-macho"
"arm64 arm64-apple-none-macho arm64-apple-none-macho"
"x86_64 x86_64-apple-macos x86_64-apple-macos10.13"
"arm64 arm64-apple-macos arm64-apple-macos10.13"
"arm64e arm64e-apple-macos arm64e-apple-macos10.13"

# the following are all ELF targets
"armv6 armv6-none-none-eabi armv6-none-none-eabi"
"armv6m armv6m-none-none-eabi armv6-none-none-eabi"
"armv7 armv7-none-none-eabi armv7-none-none-eabi"
"armv7em armv7em-none-none-eabi armv7em-none-none-eabi"
"aarch64 aarch64-none-none-elf aarch64-none-none-elf"
"riscv32 riscv32-none-none-eabi riscv32-none-none-eabi"
"riscv64 riscv64-none-none-eabi riscv64-none-none-eabi"
)

if (SWIFT_HOST_VARIANT STREQUAL "linux")
set(EMBEDDED_STDLIB_TARGET_TRIPLES ${EMBEDDED_STDLIB_TARGET_TRIPLES}
"${SWIFT_HOST_VARIANT_ARCH} ${SWIFT_HOST_VARIANT_ARCH}-unknown-linux-gnu ${SWIFT_HOST_VARIANT_ARCH}-unknown-linux-gnu"
# In practice this expands to either:
# "x86_64 x86_64-unknown-linux-gnu x86_64-unknown-linux-gnu"
# "aarch64 aarch64-unknown-linux-gnu aarch64-unknown-linux-gnu"
)
elseif (SWIFT_HOST_VARIANT STREQUAL "macosx")
set(EMBEDDED_STDLIB_TARGET_TRIPLES ${EMBEDDED_STDLIB_TARGET_TRIPLES}
"x86_64 x86_64-apple-macos x86_64-apple-macos10.13"
"arm64 arm64-apple-macos arm64-apple-macos10.13"
"arm64e arm64e-apple-macos arm64e-apple-macos10.13"
)
endif()
endif()

if(SWIFT_BUILD_STDLIB)
Expand Down
20 changes: 14 additions & 6 deletions stdlib/public/Concurrency/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,18 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC
list(GET list 1 mod)
list(GET list 2 triple)

# TODO: Only build embedded Swift Concurrency for macOS, for now.
if(NOT "${mod}" MATCHES "-macos$")
continue()
if (SWIFT_HOST_VARIANT STREQUAL "linux")
if(NOT "${mod}" MATCHES "-linux-gnu$")
continue()
endif()
set(extra_c_compile_flags)
set(extra_swift_compile_flags)
elseif (SWIFT_HOST_VARIANT STREQUAL "macosx")
if(NOT "${mod}" MATCHES "-macos$")
continue()
endif()
set(extra_c_compile_flags -D__MACH__ -D__APPLE__ -ffreestanding)
set(extra_swift_compile_flags -Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding)
endif()

set(SWIFT_SDK_embedded_ARCH_${mod}_MODULE "${mod}")
Expand Down Expand Up @@ -242,12 +251,11 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC
TaskCancellation.swift

SWIFT_COMPILE_FLAGS
-Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding -enable-experimental-feature Embedded
${extra_swift_compile_flags} -enable-experimental-feature Embedded
-parse-stdlib -DSWIFT_CONCURRENCY_EMBEDDED
${SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS}
C_COMPILE_FLAGS
-D__MACH__ -D__APPLE__ -ffreestanding
${SWIFT_RUNTIME_CONCURRENCY_C_FLAGS} -DSWIFT_CONCURRENCY_EMBEDDED=1
${extra_c_compile_flags} ${SWIFT_RUNTIME_CONCURRENCY_C_FLAGS} -DSWIFT_CONCURRENCY_EMBEDDED=1
MODULE_DIR "${CMAKE_BINARY_DIR}/lib/swift/embedded"
SDK "embedded"
ARCHITECTURE "${mod}"
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/array-builtins-exec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

import Builtin

Expand Down
3 changes: 1 addition & 2 deletions test/embedded/array-to-pointer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

@_silgen_name("putchar")
func putchar(_: UInt8)
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/array-zero-size-struct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

// REQUIRES: swift_in_compiler
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

public struct MyStruct {
}
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/arrays.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

@_silgen_name("putchar")
func putchar(_: UInt8)
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/class-func.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

@main
struct Main {
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/classes-arrays.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

class MyClass {
init() { print("MyClass.init") }
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/classes-stack-promotion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

public class MyClass {
public init() { print("MyClass.init") }
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/classes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

class MyClass {
init() { print("MyClass.init") }
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/closures-heap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

public class MyClass {
var handler: (()->())? = nil
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

@_silgen_name("putchar")
func putchar(_: UInt8)
Expand Down
1 change: 0 additions & 1 deletion test/embedded/concurrency-actors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// REQUIRES: executable_test
// REQUIRES: swift_in_compiler
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx

import _Concurrency
Expand Down
1 change: 0 additions & 1 deletion test/embedded/concurrency-async-let.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// REQUIRES: executable_test
// REQUIRES: swift_in_compiler
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx

import _Concurrency
Expand Down
1 change: 0 additions & 1 deletion test/embedded/concurrency-builtins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

// REQUIRES: swift_in_compiler
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx

import Builtin
Expand Down
1 change: 0 additions & 1 deletion test/embedded/concurrency-simple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// REQUIRES: executable_test
// REQUIRES: swift_in_compiler
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx

import _Concurrency
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/custom-print.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

@_silgen_name("putchar")
func putchar(_: UInt8)
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/debuginfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

// REQUIRES: swift_in_compiler
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

public func foo<T>(_ array: inout [T]) {
array.withUnsafeMutableBytes {
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/deserialize-vtables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

@main
struct Main {
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/dynamic-self.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// RUN: %target-swift-emit-ir %s -enable-experimental-feature Embedded -parse-as-library -module-name main | %FileCheck %s

// REQUIRES: swift_in_compiler
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

class MyClass {
init() {
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/fno-builtin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

// REQUIRES: swift_in_compiler
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

public func foo() -> [Int] {
var a = [1, 2, 3]
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/generic-classes-debuginfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

struct User {
let o: BaseClass
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/generic-classes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

protocol Fooable {
func foo()
Expand Down
1 change: 0 additions & 1 deletion test/embedded/lto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx

// For LTO, the linker dlopen()'s the libLTO library, which is a scenario that
Expand Down
3 changes: 1 addition & 2 deletions test/embedded/metatypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

// REQUIRES: swift_in_compiler
// REQUIRES: optimized_stdlib
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

public func sink<T>(t: T) {}

Expand Down
3 changes: 1 addition & 2 deletions test/embedded/modules-classes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

// BEGIN MyModule.swift

Expand Down
3 changes: 1 addition & 2 deletions test/embedded/modules-globals-exec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

// BEGIN MyModule.swift

Expand Down
5 changes: 2 additions & 3 deletions test/embedded/modules-globals-many.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
// RUN: %target-swift-frontend -emit-ir -I %t %t/Main.swift -enable-experimental-feature Embedded -parse-as-library | %FileCheck %s

// REQUIRES: swift_in_compiler
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

// Dependencies look like this:
//
Expand Down Expand Up @@ -44,4 +43,4 @@ public func main() {
MyModuleC.foo()
}

// CHECK: @"$s9MyModuleA6globalSivp" = global %TSi zeroinitializer
// CHECK: @"$s9MyModuleA6globalSivp" = {{.*}}global %TSi zeroinitializer
11 changes: 5 additions & 6 deletions test/embedded/modules-globals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
// RUN: %target-swift-frontend -emit-ir -I %t %t/Main.swift -enable-experimental-feature Embedded -parse-as-library | %FileCheck %s

// REQUIRES: swift_in_compiler
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

// BEGIN MyModule.swift

Expand All @@ -31,7 +30,7 @@ public func main() {
foo()
}

// CHECK: @"$s4Main022global_in_client_used_c1_D0Sivp" = global %TSi zeroinitializer
// CHECK: @"$s4Main024global_in_client_unused_c1_D0Sivp" = global %TSi zeroinitializer
// CHECK: @"$s8MyModule022global_in_module_used_d1_E0Sivp" = global %TSi zeroinitializer
// CHECK: @"$s8MyModule024global_in_module_unused_d1_E0Sivp" = global %TSi zeroinitializer
// CHECK: @"$s4Main022global_in_client_used_c1_D0Sivp" = {{.*}}global %TSi zeroinitializer
// CHECK: @"$s4Main024global_in_client_unused_c1_D0Sivp" = {{.*}}global %TSi zeroinitializer
// CHECK: @"$s8MyModule022global_in_module_used_d1_E0Sivp" = {{.*}}global %TSi zeroinitializer
// CHECK: @"$s8MyModule024global_in_module_unused_d1_E0Sivp" = {{.*}}global %TSi zeroinitializer
3 changes: 1 addition & 2 deletions test/embedded/modules-print-exec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

// BEGIN MyModule.swift

Expand Down
3 changes: 1 addition & 2 deletions test/embedded/no-autolink.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// RUN: %target-swift-frontend -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s

// REQUIRES: swift_in_compiler
// REQUIRES: VENDOR=apple
// REQUIRES: OS=macosx
// REQUIRES: OS=macosx || OS=linux-gnu

public func staticstring() -> StaticString {
return "hello"
Expand Down
Loading