def sdk_supports_architecture(self, arch, toolchain): """ Convenience function for checking whether the SDK supports the target architecture. """ # The names match up with the xcrun SDK names. xcrun_sdk_name = self.name # 32-bit iOS and iOS simulator are supported, but are not covered # by the SDK settings. Handle this special case here. if (xcrun_sdk_name == 'iphoneos' and (arch == 'armv7' or arch == 'armv7s')): return True if (xcrun_sdk_name == 'iphonesimulator' and arch == 'i386'): return True sdk_path = xcrun.sdk_path(sdk=xcrun_sdk_name, toolchain=toolchain) if not sdk_path: raise RuntimeError('Cannot find SDK path for %s' % xcrun_sdk_name) # Find the SDKSettings.plist for this sdK plistCommand = [ '/usr/libexec/PlistBuddy', '-c', 'Print :SupportedTargets:%s:Archs' % (self.name), '%s/SDKSettings.plist' % (sdk_path) ] sdk_archs = shell.capture(plistCommand, dry_run=False, echo=True) return arch in sdk_archs
def build(self): if os.path.exists(self.ninja_bin_path): return env = None if platform.system() == "Darwin": sysroot = xcrun.sdk_path("macosx") assert sysroot is not None env = { "CXX": shell._quote(self.toolchain.cxx), "CFLAGS": ("-isysroot {sysroot}").format(sysroot=shell._quote(sysroot)), "LDFLAGS": ("-isysroot {sysroot}").format(sysroot=shell._quote(sysroot)), } elif self.toolchain.cxx: env = { "CXX": shell._quote(self.toolchain.cxx), } # Ninja can only be built in-tree. Copy the source tree to the build # directory. shell.rmtree(self.build_dir) shell.copytree(self.source_dir, self.build_dir) with shell.pushd(self.build_dir): shell.call([sys.executable, 'configure.py', '--bootstrap'], env=env)
def build(self): if os.path.exists(self.ninja_bin_path): return env = None if platform.system() == "Darwin": sysroot = xcrun.sdk_path("macosx") osx_version_min = self.args.darwin_deployment_version_osx assert sysroot is not None env = { "CXX": self.toolchain.cxx, "CFLAGS": ( "-isysroot {sysroot} -mmacosx-version-min={osx_version}" ).format(sysroot=sysroot, osx_version=osx_version_min), "LDFLAGS": ( "-mmacosx-version-min={osx_version}" ).format(osx_version=osx_version_min), } elif self.toolchain.cxx: env = { "CXX": self.toolchain.cxx, } # Ninja can only be built in-tree. Copy the source tree to the build # directory. shell.rmtree(self.build_dir) shell.copytree(self.source_dir, self.build_dir) with shell.pushd(self.build_dir): shell.call([sys.executable, 'configure.py', '--bootstrap'], env=env)
def build(self, host_target): """build() -> void Perform the build, for a non-build-script-impl product. """ self.cmake_options.define('CMAKE_BUILD_TYPE:STRING', self.args.cmark_build_variant) (platform, arch) = host_target.split('-') if host_target.startswith("macosx") or \ host_target.startswith("iphone") or \ host_target.startswith("appletv") or \ host_target.startswith("watch"): cmake_os_sysroot = xcrun.sdk_path(platform) cmake_osx_deployment_target = '' if platform == "macosx": cmake_osx_deployment_target = self.args.darwin_deployment_version_osx common_c_flags = ' '.join(self.common_cross_c_flags( platform, arch)) self.cmake_options.define('CMAKE_C_FLAGS', common_c_flags) self.cmake_options.define('CMAKE_CXX_FLAGS', common_c_flags) self.cmake_options.define('CMAKE_OSX_SYSROOT:PATH', cmake_os_sysroot) self.cmake_options.define('CMAKE_OSX_DEPLOYMENT_TARGET', cmake_osx_deployment_target) self.cmake_options.define('CMAKE_OSX_ARCHITECTURES', arch) self.build_with_cmake(["all"], self.args.cmark_build_variant, [])
def test_build(self): ninja_build = Ninja.new_builder(args=self.args, toolchain=self.toolchain, workspace=self.workspace, host=self.host) ninja_build.build() expect_env = "" if platform.system() == "Darwin": expect_env = ("env " "'CFLAGS=-isysroot {sysroot}' " "CXX={cxx} " "'LDFLAGS=-isysroot {sysroot}' ").format( cxx=self.toolchain.cxx, sysroot=xcrun.sdk_path('macosx')) elif self.toolchain.cxx: expect_env = ("env " "CXX={cxx} ").format(cxx=self.toolchain.cxx, ) self.assertEqual( self.stdout.getvalue(), """\ + rm -rf {build_dir} + cp -r {source_dir} {build_dir} + pushd {build_dir} + {expect_env}{python} configure.py --bootstrap + popd """.format(source_dir=self._platform_quote(self.workspace.source_dir('ninja')), build_dir=self._platform_quote( self.workspace.build_dir('build', 'ninja')), expect_env=expect_env, python=self._platform_quote(sys.executable)))
def generate_darwin_toolchain_file(self, platform, arch): shell.makedirs(self.build_dir) toolchain_file = os.path.join(self.build_dir, 'BuildScriptToolchain.cmake') cmake_osx_sysroot = xcrun.sdk_path(platform) target = None if platform == 'macosx': target = '{}-apple-macosx{}'.format( arch, self.args.darwin_deployment_version_osx) elif platform == 'iphonesimulator': target = '{}-apple-ios{}'.format( arch, self.args.darwin_deployment_version_ios) elif platform == 'iphoneos': target = '{}-apple-ios{}'.format( arch, self.args.darwin_deployment_version_ios) elif platform == 'appletvsimulator': target = '{}-apple-tvos{}'.format( arch, self.args.darwin_deployment_version_tvos) elif platform == 'appletvos': target = '{}-apple-tvos{}'.format( arch, self.args.darwin_deployment_version_tvos) elif platform == 'watchsimulator': target = '{}-apple-watchos{}'.format( arch, self.args.darwin_deployment_version_watchos) elif platform == 'watchos': target = '{}-apple-watchos{}'.format( arch, self.args.darwin_deployment_version_watchos) else: raise RuntimeError("Unhandled platform?!") toolchain_args = {} toolchain_args['CMAKE_SYSTEM_NAME'] = 'Darwin' toolchain_args['CMAKE_OSX_SYSROOT'] = cmake_osx_sysroot toolchain_args['CMAKE_OSX_ARCHITECTURES'] = arch if self.toolchain.cc.endswith('clang'): toolchain_args['CMAKE_C_COMPILER_TARGET'] = target if self.toolchain.cxx.endswith('clang++'): toolchain_args['CMAKE_CXX_COMPILER_TARGET'] = target # Swift always supports cross compiling. toolchain_args['CMAKE_Swift_COMPILER_TARGET'] = target # Sort by the key so that we always produce the same toolchain file data = sorted(toolchain_args.items(), key=lambda x: x[0]) if not self.args.dry_run: with open(toolchain_file, 'w') as f: f.writelines("set({} {})\n".format(k, v) for k, v in data) else: print("DRY_RUN! Writing Toolchain file to path: {}".format( toolchain_file)) return toolchain_file