Skip to content

Commit a0ec73e

Browse files
committed
[embedded] Start building embedded support on Linux/ELF, expand archs of the embedded stdlib to cover common embedded targets, take 2
1 parent fd63387 commit a0ec73e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+90
-104
lines changed

cmake/modules/SwiftSetIfArchBitness.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ function(set_if_arch_bitness var_name)
1111
"${SIA_ARCH}" STREQUAL "x86" OR
1212
"${SIA_ARCH}" STREQUAL "armv5" OR
1313
"${SIA_ARCH}" STREQUAL "armv6" OR
14+
"${SIA_ARCH}" STREQUAL "armv6m" OR
1415
"${SIA_ARCH}" STREQUAL "armv7" OR
1516
"${SIA_ARCH}" STREQUAL "armv7k" OR
1617
"${SIA_ARCH}" STREQUAL "arm64_32" OR
1718
"${SIA_ARCH}" STREQUAL "armv7m" OR
1819
"${SIA_ARCH}" STREQUAL "armv7em" OR
1920
"${SIA_ARCH}" STREQUAL "armv7s" OR
21+
"${SIA_ARCH}" STREQUAL "riscv32" OR
2022
"${SIA_ARCH}" STREQUAL "wasm32" OR
2123
"${SIA_ARCH}" STREQUAL "powerpc")
2224
set("${var_name}" "${SIA_CASE_32_BIT}" PARENT_SCOPE)

stdlib/public/CMakeLists.txt

+28-4
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ option(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB
138138
"Enable build of the embedded Swift standard library and runtime"
139139
TRUE)
140140

141-
if(NOT SWIFT_HOST_VARIANT STREQUAL "macosx")
141+
if((NOT SWIFT_HOST_VARIANT STREQUAL "macosx") AND (NOT SWIFT_HOST_VARIANT STREQUAL "linux"))
142142
set(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB FALSE)
143143
elseif(NOT SWIFT_INCLUDE_TOOLS)
144144
# Temporarily, only build embedded stdlib when building the compiler, to
@@ -151,12 +151,36 @@ endif()
151151
if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
152152
set(EMBEDDED_STDLIB_TARGET_TRIPLES
153153
# arch module_name target triple
154+
"armv6 armv6-apple-none-macho armv6-apple-none-macho"
155+
"armv6m armv6m-apple-none-macho armv6m-apple-none-macho"
154156
"armv7 armv7-apple-none-macho armv7-apple-none-macho"
157+
"armv7em armv7em-apple-none-macho armv7em-apple-none-macho"
155158
"arm64 arm64-apple-none-macho arm64-apple-none-macho"
156-
"x86_64 x86_64-apple-macos x86_64-apple-macos10.13"
157-
"arm64 arm64-apple-macos arm64-apple-macos10.13"
158-
"arm64e arm64e-apple-macos arm64e-apple-macos10.13"
159+
160+
# the following are all ELF targets
161+
"armv6 armv6-none-none-eabi armv6-none-none-eabi"
162+
"armv6m armv6m-none-none-eabi armv6-none-none-eabi"
163+
"armv7 armv7-none-none-eabi armv7-none-none-eabi"
164+
"armv7em armv7em-none-none-eabi armv7em-none-none-eabi"
165+
"aarch64 aarch64-none-none-elf aarch64-none-none-elf"
166+
"riscv32 riscv32-none-none-eabi riscv32-none-none-eabi"
167+
"riscv64 riscv64-none-none-eabi riscv64-none-none-eabi"
159168
)
169+
170+
if (SWIFT_HOST_VARIANT STREQUAL "linux")
171+
set(EMBEDDED_STDLIB_TARGET_TRIPLES ${EMBEDDED_STDLIB_TARGET_TRIPLES}
172+
"${SWIFT_HOST_VARIANT_ARCH} ${SWIFT_HOST_VARIANT_ARCH}-unknown-linux-gnu ${SWIFT_HOST_VARIANT_ARCH}-unknown-linux-gnu"
173+
# In practice this expands to either:
174+
# "x86_64 x86_64-unknown-linux-gnu x86_64-unknown-linux-gnu"
175+
# "aarch64 aarch64-unknown-linux-gnu aarch64-unknown-linux-gnu"
176+
)
177+
elseif (SWIFT_HOST_VARIANT STREQUAL "macosx")
178+
set(EMBEDDED_STDLIB_TARGET_TRIPLES ${EMBEDDED_STDLIB_TARGET_TRIPLES}
179+
"x86_64 x86_64-apple-macos x86_64-apple-macos10.13"
180+
"arm64 arm64-apple-macos arm64-apple-macos10.13"
181+
"arm64e arm64e-apple-macos arm64e-apple-macos10.13"
182+
)
183+
endif()
160184
endif()
161185

162186
if(SWIFT_BUILD_STDLIB)

stdlib/public/Concurrency/CMakeLists.txt

+14-6
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,18 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB AND SWIFT_SHOULD_BUILD_EMBEDDED_CONCURRENC
198198
list(GET list 1 mod)
199199
list(GET list 2 triple)
200200

201-
# TODO: Only build embedded Swift Concurrency for macOS, for now.
202-
if(NOT "${mod}" MATCHES "-macos$")
203-
continue()
201+
if (SWIFT_HOST_VARIANT STREQUAL "linux")
202+
if(NOT "${mod}" MATCHES "-linux-gnu$")
203+
continue()
204+
endif()
205+
set(extra_c_compile_flags)
206+
set(extra_swift_compile_flags)
207+
elseif (SWIFT_HOST_VARIANT STREQUAL "macosx")
208+
if(NOT "${mod}" MATCHES "-macos$")
209+
continue()
210+
endif()
211+
set(extra_c_compile_flags -D__MACH__ -D__APPLE__ -ffreestanding)
212+
set(extra_swift_compile_flags -Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding)
204213
endif()
205214

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

244253
SWIFT_COMPILE_FLAGS
245-
-Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding -enable-experimental-feature Embedded
254+
${extra_swift_compile_flags} -enable-experimental-feature Embedded
246255
-parse-stdlib -DSWIFT_CONCURRENCY_EMBEDDED
247256
${SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS}
248257
C_COMPILE_FLAGS
249-
-D__MACH__ -D__APPLE__ -ffreestanding
250-
${SWIFT_RUNTIME_CONCURRENCY_C_FLAGS} -DSWIFT_CONCURRENCY_EMBEDDED=1
258+
${extra_c_compile_flags} ${SWIFT_RUNTIME_CONCURRENCY_C_FLAGS} -DSWIFT_CONCURRENCY_EMBEDDED=1
251259
MODULE_DIR "${CMAKE_BINARY_DIR}/lib/swift/embedded"
252260
SDK "embedded"
253261
ARCHITECTURE "${mod}"

test/embedded/array-builtins-exec.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
// REQUIRES: swift_in_compiler
77
// REQUIRES: executable_test
88
// REQUIRES: optimized_stdlib
9-
// REQUIRES: VENDOR=apple
10-
// REQUIRES: OS=macosx
9+
// REQUIRES: OS=macosx || OS=linux-gnu
1110

1211
import Builtin
1312

test/embedded/array-to-pointer.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
// REQUIRES: swift_in_compiler
88
// REQUIRES: executable_test
99
// REQUIRES: optimized_stdlib
10-
// REQUIRES: VENDOR=apple
11-
// REQUIRES: OS=macosx
10+
// REQUIRES: OS=macosx || OS=linux-gnu
1211

1312
@_silgen_name("putchar")
1413
func putchar(_: UInt8)

test/embedded/array-zero-size-struct.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
// REQUIRES: swift_in_compiler
44
// REQUIRES: optimized_stdlib
5-
// REQUIRES: VENDOR=apple
6-
// REQUIRES: OS=macosx
5+
// REQUIRES: OS=macosx || OS=linux-gnu
76

87
public struct MyStruct {
98
}

test/embedded/arrays.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
// REQUIRES: swift_in_compiler
88
// REQUIRES: executable_test
99
// REQUIRES: optimized_stdlib
10-
// REQUIRES: VENDOR=apple
11-
// REQUIRES: OS=macosx
10+
// REQUIRES: OS=macosx || OS=linux-gnu
1211

1312
@_silgen_name("putchar")
1413
func putchar(_: UInt8)

test/embedded/class-func.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
// REQUIRES: swift_in_compiler
44
// REQUIRES: executable_test
55
// REQUIRES: optimized_stdlib
6-
// REQUIRES: VENDOR=apple
7-
// REQUIRES: OS=macosx
6+
// REQUIRES: OS=macosx || OS=linux-gnu
87

98
@main
109
struct Main {

test/embedded/classes-arrays.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
// REQUIRES: swift_in_compiler
77
// REQUIRES: executable_test
88
// REQUIRES: optimized_stdlib
9-
// REQUIRES: VENDOR=apple
10-
// REQUIRES: OS=macosx
9+
// REQUIRES: OS=macosx || OS=linux-gnu
1110

1211
class MyClass {
1312
init() { print("MyClass.init") }

test/embedded/classes-stack-promotion.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
// REQUIRES: swift_in_compiler
88
// REQUIRES: executable_test
99
// REQUIRES: optimized_stdlib
10-
// REQUIRES: VENDOR=apple
11-
// REQUIRES: OS=macosx
10+
// REQUIRES: OS=macosx || OS=linux-gnu
1211

1312
public class MyClass {
1413
public init() { print("MyClass.init") }

test/embedded/classes.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
// REQUIRES: swift_in_compiler
77
// REQUIRES: executable_test
88
// REQUIRES: optimized_stdlib
9-
// REQUIRES: VENDOR=apple
10-
// REQUIRES: OS=macosx
9+
// REQUIRES: OS=macosx || OS=linux-gnu
1110

1211
class MyClass {
1312
init() { print("MyClass.init") }

test/embedded/closures-heap.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
// REQUIRES: swift_in_compiler
77
// REQUIRES: executable_test
88
// REQUIRES: optimized_stdlib
9-
// REQUIRES: VENDOR=apple
10-
// REQUIRES: OS=macosx
9+
// REQUIRES: OS=macosx || OS=linux-gnu
1110

1211
public class MyClass {
1312
var handler: (()->())? = nil

test/embedded/collection.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
// REQUIRES: swift_in_compiler
88
// REQUIRES: executable_test
99
// REQUIRES: optimized_stdlib
10-
// REQUIRES: VENDOR=apple
11-
// REQUIRES: OS=macosx
10+
// REQUIRES: OS=macosx || OS=linux-gnu
1211

1312
@_silgen_name("putchar")
1413
func putchar(_: UInt8)

test/embedded/concurrency-actors.swift

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// REQUIRES: executable_test
88
// REQUIRES: swift_in_compiler
99
// REQUIRES: optimized_stdlib
10-
// REQUIRES: VENDOR=apple
1110
// REQUIRES: OS=macosx
1211

1312
import _Concurrency

test/embedded/concurrency-async-let.swift

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// REQUIRES: executable_test
88
// REQUIRES: swift_in_compiler
99
// REQUIRES: optimized_stdlib
10-
// REQUIRES: VENDOR=apple
1110
// REQUIRES: OS=macosx
1211

1312
import _Concurrency

test/embedded/concurrency-builtins.swift

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
// REQUIRES: swift_in_compiler
44
// REQUIRES: optimized_stdlib
5-
// REQUIRES: VENDOR=apple
65
// REQUIRES: OS=macosx
76

87
import Builtin

test/embedded/concurrency-simple.swift

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// REQUIRES: executable_test
88
// REQUIRES: swift_in_compiler
99
// REQUIRES: optimized_stdlib
10-
// REQUIRES: VENDOR=apple
1110
// REQUIRES: OS=macosx
1211

1312
import _Concurrency

test/embedded/custom-print.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
// REQUIRES: swift_in_compiler
77
// REQUIRES: executable_test
8-
// REQUIRES: VENDOR=apple
9-
// REQUIRES: OS=macosx
8+
// REQUIRES: OS=macosx || OS=linux-gnu
109

1110
@_silgen_name("putchar")
1211
func putchar(_: UInt8)

test/embedded/debuginfo.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
// REQUIRES: swift_in_compiler
99
// REQUIRES: optimized_stdlib
10-
// REQUIRES: VENDOR=apple
11-
// REQUIRES: OS=macosx
10+
// REQUIRES: OS=macosx || OS=linux-gnu
1211

1312
public func foo<T>(_ array: inout [T]) {
1413
array.withUnsafeMutableBytes {

test/embedded/deserialize-vtables.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
// REQUIRES: swift_in_compiler
66
// REQUIRES: executable_test
77
// REQUIRES: optimized_stdlib
8-
// REQUIRES: VENDOR=apple
9-
// REQUIRES: OS=macosx
8+
// REQUIRES: OS=macosx || OS=linux-gnu
109

1110
@main
1211
struct Main {

test/embedded/dynamic-self.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// RUN: %target-swift-emit-ir %s -enable-experimental-feature Embedded -parse-as-library -module-name main | %FileCheck %s
22

33
// REQUIRES: swift_in_compiler
4-
// REQUIRES: VENDOR=apple
5-
// REQUIRES: OS=macosx
4+
// REQUIRES: OS=macosx || OS=linux-gnu
65

76
class MyClass {
87
init() {

test/embedded/fno-builtin.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
// REQUIRES: swift_in_compiler
55
// REQUIRES: optimized_stdlib
6-
// REQUIRES: VENDOR=apple
7-
// REQUIRES: OS=macosx
6+
// REQUIRES: OS=macosx || OS=linux-gnu
87

98
public func foo() -> [Int] {
109
var a = [1, 2, 3]

test/embedded/generic-classes-debuginfo.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
// REQUIRES: executable_test
55
// REQUIRES: optimized_stdlib
6-
// REQUIRES: VENDOR=apple
7-
// REQUIRES: OS=macosx
6+
// REQUIRES: OS=macosx || OS=linux-gnu
87

98
struct User {
109
let o: BaseClass

test/embedded/generic-classes.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
// REQUIRES: swift_in_compiler
55
// REQUIRES: executable_test
66
// REQUIRES: optimized_stdlib
7-
// REQUIRES: VENDOR=apple
8-
// REQUIRES: OS=macosx
7+
// REQUIRES: OS=macosx || OS=linux-gnu
98

109
protocol Fooable {
1110
func foo()

test/embedded/lto.swift

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
// REQUIRES: swift_in_compiler
77
// REQUIRES: executable_test
8-
// REQUIRES: VENDOR=apple
98
// REQUIRES: OS=macosx
109

1110
// For LTO, the linker dlopen()'s the libLTO library, which is a scenario that

test/embedded/metatypes.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
// REQUIRES: swift_in_compiler
44
// REQUIRES: optimized_stdlib
5-
// REQUIRES: VENDOR=apple
6-
// REQUIRES: OS=macosx
5+
// REQUIRES: OS=macosx || OS=linux-gnu
76

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

test/embedded/modules-classes.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
// REQUIRES: swift_in_compiler
1111
// REQUIRES: executable_test
12-
// REQUIRES: VENDOR=apple
13-
// REQUIRES: OS=macosx
12+
// REQUIRES: OS=macosx || OS=linux-gnu
1413

1514
// BEGIN MyModule.swift
1615

test/embedded/modules-globals-exec.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
// REQUIRES: swift_in_compiler
1111
// REQUIRES: executable_test
12-
// REQUIRES: VENDOR=apple
13-
// REQUIRES: OS=macosx
12+
// REQUIRES: OS=macosx || OS=linux-gnu
1413

1514
// BEGIN MyModule.swift
1615

test/embedded/modules-globals-many.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
// RUN: %target-swift-frontend -emit-ir -I %t %t/Main.swift -enable-experimental-feature Embedded -parse-as-library | %FileCheck %s
88

99
// REQUIRES: swift_in_compiler
10-
// REQUIRES: VENDOR=apple
11-
// REQUIRES: OS=macosx
10+
// REQUIRES: OS=macosx || OS=linux-gnu
1211

1312
// Dependencies look like this:
1413
//
@@ -44,4 +43,4 @@ public func main() {
4443
MyModuleC.foo()
4544
}
4645

47-
// CHECK: @"$s9MyModuleA6globalSivp" = global %TSi zeroinitializer
46+
// CHECK: @"$s9MyModuleA6globalSivp" = {{.*}}global %TSi zeroinitializer

test/embedded/modules-globals.swift

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
// RUN: %target-swift-frontend -emit-ir -I %t %t/Main.swift -enable-experimental-feature Embedded -parse-as-library | %FileCheck %s
66

77
// REQUIRES: swift_in_compiler
8-
// REQUIRES: VENDOR=apple
9-
// REQUIRES: OS=macosx
8+
// REQUIRES: OS=macosx || OS=linux-gnu
109

1110
// BEGIN MyModule.swift
1211

@@ -31,7 +30,7 @@ public func main() {
3130
foo()
3231
}
3332

34-
// CHECK: @"$s4Main022global_in_client_used_c1_D0Sivp" = global %TSi zeroinitializer
35-
// CHECK: @"$s4Main024global_in_client_unused_c1_D0Sivp" = global %TSi zeroinitializer
36-
// CHECK: @"$s8MyModule022global_in_module_used_d1_E0Sivp" = global %TSi zeroinitializer
37-
// CHECK: @"$s8MyModule024global_in_module_unused_d1_E0Sivp" = global %TSi zeroinitializer
33+
// CHECK: @"$s4Main022global_in_client_used_c1_D0Sivp" = {{.*}}global %TSi zeroinitializer
34+
// CHECK: @"$s4Main024global_in_client_unused_c1_D0Sivp" = {{.*}}global %TSi zeroinitializer
35+
// CHECK: @"$s8MyModule022global_in_module_used_d1_E0Sivp" = {{.*}}global %TSi zeroinitializer
36+
// CHECK: @"$s8MyModule024global_in_module_unused_d1_E0Sivp" = {{.*}}global %TSi zeroinitializer

test/embedded/modules-print-exec.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
// REQUIRES: swift_in_compiler
1111
// REQUIRES: executable_test
12-
// REQUIRES: VENDOR=apple
13-
// REQUIRES: OS=macosx
12+
// REQUIRES: OS=macosx || OS=linux-gnu
1413

1514
// BEGIN MyModule.swift
1615

test/embedded/no-autolink.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// RUN: %target-swift-frontend -emit-ir %s -enable-experimental-feature Embedded | %FileCheck %s
22

33
// REQUIRES: swift_in_compiler
4-
// REQUIRES: VENDOR=apple
5-
// REQUIRES: OS=macosx
4+
// REQUIRES: OS=macosx || OS=linux-gnu
65

76
public func staticstring() -> StaticString {
87
return "hello"

0 commit comments

Comments
 (0)