@@ -147,14 +147,24 @@ extension GenericUnixToolchain {
147
147
}
148
148
}
149
149
150
+ if targetInfo. sdkPath != nil {
151
+ for libpath in targetInfo. runtimeLibraryImportPaths {
152
+ commandLine. appendFlag ( . L)
153
+ commandLine. appendPath ( VirtualPath . lookup ( libpath. path) )
154
+ }
155
+ }
156
+
150
157
if !isEmbeddedEnabled && !parsedOptions. hasArgument ( . nostartfiles) {
151
- let swiftrtPath = VirtualPath . lookup ( targetInfo. runtimeResourcePath. path)
152
- . appending (
153
- components: targetTriple. platformName ( ) ?? " " ,
154
- String ( majorArchitectureName ( for: targetTriple) ) ,
155
- " swiftrt.o "
156
- )
157
- commandLine. appendPath ( swiftrtPath)
158
+ let rsrc : VirtualPath
159
+ // Prefer the swiftrt.o runtime file from the SDK if it's specified.
160
+ if let sdk = targetInfo. sdkPath. flatMap ( { VirtualPath . lookup ( $0. path) } ) {
161
+ rsrc = sdk. appending ( components: " usr " , " lib " , " swift " )
162
+ } else {
163
+ rsrc = VirtualPath . lookup ( targetInfo. runtimeResourcePath. path)
164
+ }
165
+ let platform : String = targetTriple. platformName ( ) ?? " "
166
+ let architecture : String = majorArchitectureName ( for: targetTriple)
167
+ commandLine. appendPath ( rsrc. appending ( components: platform, architecture, " swiftrt.o " ) )
158
168
}
159
169
160
170
// If we are linking statically, we need to add all
@@ -194,7 +204,12 @@ extension GenericUnixToolchain {
194
204
commandLine. appendPath ( try VirtualPath ( path: opt. argument. asSingle) )
195
205
}
196
206
197
- if let path = targetInfo. sdkPath? . path {
207
+ if targetTriple. environment == . android {
208
+ if let sysroot = try getAndroidNDKSysrootPath ( ) {
209
+ commandLine. appendFlag ( " --sysroot " )
210
+ commandLine. appendPath ( sysroot)
211
+ }
212
+ } else if let path = targetInfo. sdkPath? . path {
198
213
commandLine. appendFlag ( " --sysroot " )
199
214
commandLine. appendPath ( VirtualPath . lookup ( path) )
200
215
}
0 commit comments