@@ -280,6 +280,71 @@ def generate_darwin_toolchain_file(self, platform, arch):
280
280
281
281
return toolchain_file
282
282
283
+ def get_linux_abi (self , arch ):
284
+ # Map tuples of (platform, arch) to ABI
285
+ #
286
+ # E.x.: Hard ABI or Soft ABI for Linux map to gnueabihf
287
+ arch_platform_to_abi = {
288
+ # For now always map to hard float ABI.
289
+ 'armv7' : ('arm' , 'gnueabihf' )
290
+ }
291
+
292
+ # Default is just arch, gnu
293
+ sysroot_arch , abi = arch_platform_to_abi .get (arch , (arch , 'gnu' ))
294
+ return sysroot_arch , abi
295
+
296
+ def get_linux_sysroot (self , platform , arch ):
297
+ if not self .is_cross_compile_target ('{}-{}' .format (platform , arch )):
298
+ return None
299
+ sysroot_arch , abi = self .get_linux_abi (arch )
300
+ # $ARCH-$PLATFORM-$ABI
301
+ # E.x.: aarch64-linux-gnu
302
+ sysroot_dirname = '{}-{}-{}' .format (sysroot_arch , platform , abi )
303
+ return os .path .join (os .sep , 'usr' , sysroot_dirname )
304
+
305
+ def get_linux_target (self , platform , arch ):
306
+ sysroot_arch , abi = self .get_linux_abi (arch )
307
+ return '{}-unknown-linux-{}' .format (sysroot_arch , abi )
308
+
309
+ def generate_linux_toolchain_file (self , platform , arch ):
310
+ shell .makedirs (self .build_dir )
311
+ toolchain_file = os .path .join (self .build_dir , 'BuildScriptToolchain.cmake' )
312
+
313
+ toolchain_args = {}
314
+
315
+ toolchain_args ['CMAKE_SYSTEM_NAME' ] = 'Linux'
316
+ toolchain_args ['CMAKE_SYSTEM_PROCESSOR' ] = arch
317
+
318
+ # We only set the actual sysroot if we are actually cross
319
+ # compiling. This is important since otherwise cmake seems to change the
320
+ # RUNPATH to be a relative rather than an absolute path, breaking
321
+ # certain cmark tests (and maybe others).
322
+ maybe_sysroot = self .get_linux_sysroot (platform , arch )
323
+ if maybe_sysroot is not None :
324
+ toolchain_args ['CMAKE_SYSROOT' ] = maybe_sysroot
325
+
326
+ target = self .get_linux_target (platform , arch )
327
+ if self .toolchain .cc .endswith ('clang' ):
328
+ toolchain_args ['CMAKE_C_COMPILER_TARGET' ] = target
329
+ if self .toolchain .cxx .endswith ('clang++' ):
330
+ toolchain_args ['CMAKE_CXX_COMPILER_TARGET' ] = target
331
+ # Swift always supports cross compiling.
332
+ toolchain_args ['CMAKE_Swift_COMPILER_TARGET' ] = target
333
+ toolchain_args ['CMAKE_FIND_ROOT_PATH_MODE_PROGRAM' ] = 'NEVER'
334
+ toolchain_args ['CMAKE_FIND_ROOT_PATH_MODE_LIBRARY' ] = 'ONLY'
335
+ toolchain_args ['CMAKE_FIND_ROOT_PATH_MODE_INCLUDE' ] = 'ONLY'
336
+ toolchain_args ['CMAKE_FIND_ROOT_PATH_MODE_PACKAGE' ] = 'ONLY'
337
+
338
+ # Sort by the key so that we always produce the same toolchain file
339
+ data = sorted (toolchain_args .items (), key = lambda x : x [0 ])
340
+ if not self .args .dry_run :
341
+ with open (toolchain_file , 'w' ) as f :
342
+ f .writelines ("set({} {})\n " .format (k , v ) for k , v in data )
343
+ else :
344
+ print ("DRY_RUN! Writing Toolchain file to path: {}" .format (toolchain_file ))
345
+
346
+ return toolchain_file
347
+
283
348
def common_cross_c_flags (self , platform , arch ):
284
349
cross_flags = []
285
350
0 commit comments