1
1
2
- DEPENDS_prepend += "swift-native swift glibc gcc libgcc "
3
- RDEPENDS_${PN} += " swift "
2
+ DEPENDS += "swift-native glibc gcc libgcc swift-stdlib libdispatch libfoundation"
3
+
4
+ # Default build directory for SPM is "./.build"
5
+ # (see 'swift [build|package|run|test] --help')
6
+ #
7
+ # We can allow for this to be changed by changing ${B} but one must be careful to also set
8
+ # "--build-path ${B}" for _ALL_ invocations of SPM within a recipe.
9
+ B ?= "${S} /.build"
10
+ EXTERNALSRC_BUILD ?= "${EXTERNALSRC} /.build"
11
+
12
+ BUILD_MODE = "${@ ['release' , 'debug' ][d . getVar ('DEBUG_BUILD' ) == '1' ]}"
4
13
5
14
# Additional parameters to pass to SPM
6
15
EXTRA_OESWIFT ?= ""
7
16
17
+ SWIFT_TARGET_NAME = "${@ oe . utils . conditional ('TARGET_ARCH' , 'arm' , 'armv7-unknown-linux-gnueabihf' , 'aarch64-unknown-linux-gnueabi' , d )}"
18
+
19
+ # Workaround complex macros that cannot be automatically imported by Swift.
20
+ # https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/using_imported_c_macros_in_swift
21
+ #
22
+ # Seems that SO_RCVTIMEO and SO_SNDTIMEO definitions aren't working because they are expressions
23
+ # and not simple constants.
24
+ #
25
+ # This could be improved to replace just the specific lines that need fixing rather than rewriting
26
+ # the entire file.
8
27
def fix_socket_header (filename ):
9
- with open (filename , 'r' ) as f :
10
- lines = f . readlines ()
28
+ with open (filename , 'r' ) as f :
29
+ lines = f . readlines ()
11
30
12
- os . remove (filename )
31
+ os . remove (filename )
32
+
33
+ with open (filename , 'w' ) as f :
34
+ for line in lines :
35
+ if line . startswith ('#define SO_RCVTIMEO ' ) and ("SO_RCVTIMEO_OLD" in line ) and ("?" in line ):
36
+ f . write ('#define SO_RCVTIMEO SO_RCVTIMEO_OLD\n' )
37
+ elif line . startswith ('#define SO_SNDTIMEO ' ) and ("SO_SNDTIMEO_OLD" in line ) and ("?" in line ):
38
+ f . write ('#define SO_SNDTIMEO SO_SNDTIMEO_OLD\n' )
39
+ else :
40
+ f . write (line )
13
41
14
- with open (filename , 'w' ) as f :
15
- for line in lines :
16
- if line . startswith ('#define SO_RCVTIMEO ' ) and ("SO_RCVTIMEO_OLD" in line ) and ("?" in line ):
17
- f . write ('#define SO_RCVTIMEO SO_RCVTIMEO_OLD\n' )
18
- elif line . startswith ('#define SO_SNDTIMEO ' ) and ("SO_SNDTIMEO_OLD" in line ) and ("?" in line ):
19
- f . write ('#define SO_SNDTIMEO SO_SNDTIMEO_OLD\n' )
20
- else :
21
- f . write (line )
22
42
23
43
python swift_do_configure () {
24
44
import os
25
45
import os . path
26
46
import shutil
47
+
27
48
workdir = d . getVar ("WORKDIR" , True )
28
49
recipe_sysroot = d . getVar ("STAGING_DIR_TARGET" , True )
29
-
30
- # socket.h workaround. Seems that SO_RCVTIMEO and SO_SNDTIMEO definitions using ? aren't working
50
+
51
+ # Workaround complex macros that cannot be automatically imported by Swift.
52
+ # https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/using_imported_c_macros_in_swift
53
+ #
54
+ # Seems that SO_RCVTIMEO and SO_SNDTIMEO definitions aren't working because they are expressions
55
+ # and not simple constants.
31
56
socket_header = recipe_sysroot + "/usr/include/asm-generic/socket.h"
32
57
fix_socket_header (socket_header )
33
58
59
+ # Detect the version of the C++ runtime
60
+ # This is used to determine necessary include paths
34
61
cxx_include_base = recipe_sysroot + "/usr/include/c++"
35
62
cxx_include_list = os . listdir (cxx_include_base )
36
63
if len (cxx_include_list ) != 1 :
37
64
bb . fatal ("swift bbclass detected more than one c++ runtime, unable to determine which one to use" )
38
65
cxx_version = cxx_include_list [0 ]
39
-
66
+
40
67
d . setVar ('SWIFT_CXX_VERSION' , cxx_version )
41
68
42
69
swift_destination_template = """{
43
70
"version":1,
44
71
"sdk":"${STAGING_DIR_TARGET} /",
45
- "toolchain-bin-dir":"${STAGING_DIR_NATIVE} /opt/swift-arm/ usr/bin",
46
- "target":"armv7-unknown-linux-gnueabihf ",
72
+ "toolchain-bin-dir":"${STAGING_DIR_NATIVE} /opt/usr/bin",
73
+ "target":"${SWIFT_TARGET_NAME} ",
47
74
"dynamic-library-extension":"so",
48
- "extra-cc-flags":[
75
+ "extra-cc-flags":[
49
76
"-fPIC",
50
77
"-I${STAGING_DIR_TARGET} /usr/include/c++/${SWIFT_CXX_VERSION} ",
51
78
"-I${STAGING_DIR_TARGET} /usr/include/c++/${SWIFT_CXX_VERSION} /${TARGET_SYS} ",
79
+ "-I${STAGING_DIR_NATIVE} /opt/usr/lib/clang/13.0.0/include",
80
+ "-I${STAGING_DIR_NATIVE} /opt/usr/lib/clang/13.0.0/include-fixed"
52
81
],
53
- "extra-swiftc-flags":[
82
+ "extra-swiftc-flags":[
54
83
"-target",
55
- "armv7-unknown-linux-gnueabihf ",
84
+ "${SWIFT_TARGET_NAME} ",
56
85
"-use-ld=lld",
57
86
"-tools-directory",
58
- "/usr/bin",
87
+ "${STAGING_DIR_NATIVE} /opt/usr/bin",
88
+
89
+ "-Xlinker", "-rpath", "-Xlinker", "/usr/lib/swift/linux",
90
+
91
+ "-Xlinker",
92
+ "-L${STAGING_DIR_TARGET} ",
59
93
60
94
"-Xlinker",
61
95
"-L${STAGING_DIR_TARGET} /lib",
@@ -68,29 +102,41 @@ python swift_do_configure() {
68
102
69
103
"-Xlinker",
70
104
"-L${STAGING_DIR_TARGET} /usr/lib/${TARGET_SYS} /${SWIFT_CXX_VERSION} ",
71
-
105
+
106
+ "-Xlinker",
107
+ "--build-id=sha1",
108
+
109
+ "-I${STAGING_INCDIR} ",
72
110
"-I${STAGING_DIR_TARGET} /usr/include/c++/${SWIFT_CXX_VERSION} ",
73
- "-I${STAGING_DIR_TARGET} /usr/include/c++/${SWIFT_CXX_VERSION} /${TARGET_SYS} "
111
+ "-I${STAGING_DIR_TARGET} /usr/include/c++/${SWIFT_CXX_VERSION} /${TARGET_SYS} ",
112
+ "-I${STAGING_DIR_NATIVE} /opt/usr/lib/clang/13.0.0/include",
113
+ "-I${STAGING_DIR_NATIVE} /opt/usr/lib/clang/13.0.0/include-fixed",
114
+
115
+ "-resource-dir", "${STAGING_DIR_TARGET} /usr/lib/swift",
116
+ "-module-cache-path", "${B} /${BUILD_MODE} /ModuleCache",
117
+ "-Xclang-linker", "-B${STAGING_DIR_TARGET} /usr/lib/${TARGET_SYS} /${SWIFT_CXX_VERSION} ",
118
+ "-Xclang-linker", "-B${STAGING_DIR_TARGET} /usr/lib",
119
+
120
+ "-sdk", "${STAGING_DIR_TARGET} "
74
121
],
75
- "extra-cpp-flags":[
122
+ "extra-cpp-flags":[
76
123
"-lstdc++"
77
124
]
78
125
}"""
79
126
80
127
swift_destination = d . expand (swift_destination_template )
81
128
82
129
d . delVar ("SWIFT_CXX_VERSION" )
83
-
130
+
84
131
configJSON = open (workdir + "/destination.json" , "w" )
85
132
configJSON . write (swift_destination )
86
133
configJSON . close ()
87
134
}
88
135
89
136
swift_do_compile () {
90
- # Linker isn't finding crtbeginS.o and crtendS.o under ${TARGET_SYS} path
91
- cp -r ${WORKDIR} /recipe -sysroot /usr /lib /${TARGET_SYS} /*/* ${WORKDIR} /recipe -sysroot /usr /lib
92
- cd ${S}
93
- ${WORKDIR} /recipe -sysroot -native /usr /bin /swift build -v -c release --destination ${WORKDIR} /destination . json ${EXTRA_OESWIFT}
137
+ swift build --package -path ${S} --build -path ${B} --skip -update -c ${BUILD_MODE} --destination ${WORKDIR} /destination . json ${EXTRA_OESWIFT}
94
138
}
95
139
96
140
EXPORT_FUNCTIONS do_configure do_compile
141
+
142
+ EXTRANATIVEPATH += "swift-tools"
0 commit comments