def inspect_arch_windows(lib, dumpbin_exe_path=None): """Find the CPU architecture for the specified library. Args: lib (str): Path to a library file on disk. dumpbin_exe_path (str, optional): Path to MS Developer tool dumpbin.exe. If its not specified, we make our best effort in automatically finding one. Defaults to None. Returns: (str): Output from dumpbin tool. """ if not utils.is_windows_os(): print( "ERROR: inspect_arch_windows function can only be called on windows. Exiting " ) sys.exit(1) if dumpbin_exe_path is None: dumpbin_exe_path = get_or_create_dumpbin_exe_path() dumpbin = subprocess.Popen([dumpbin_exe_path, '/headers', lib], stdout=subprocess.PIPE) grep = subprocess.Popen(['findstr', 'machine'], stdin=dumpbin.stdout, stdout=subprocess.PIPE) output = grep.communicate()[0] if not output: return return output.decode('utf-8')
def _build_desktop(sdk_dir, cmake_flags): cmake_configure_cmd = ["cmake", ".", "-DCMAKE_BUILD_TYPE=Debug", "-DFIREBASE_CPP_SDK_DIR=" + sdk_dir] if utils.is_windows_os(): cmake_configure_cmd += ["-A", "x64"] elif utils.is_mac_os(): # Ensure that correct Mac architecture is built. cmake_configure_cmd += ["-DCMAKE_OSX_ARCHITECTURES=%s" % ("arm64" if FLAGS.arch == "arm64" else "x86_64")] _run(cmake_configure_cmd + cmake_flags) _run(["cmake", "--build", ".", "--config", "Debug"])
def should_upgrade(): return is_windows_os() and is_64bit_windows_os() \ and not is_64bit_python()
def cmake_configure(build_dir, arch, msvc_runtime_library='static', linux_abi='legacy', build_tests=True, config=None, target_format=None, use_openssl=False, disable_vcpkg=False, gha_build=False, verbose=False): """ CMake configure. If you are seeing problems when running this multiple times, make sure to clean/delete previous build directory. Args: build_dir (str): Output build directory. arch (str): Platform Architecture (example: 'x64', 'x86', 'arm64'). msvc_runtime_library (str): Runtime library for MSVC (eg: 'static', 'dynamic'). linux_abi (str): Linux ABI (eg: 'legacy', 'c++11'). build_tests (bool): Build cpp unit tests. config (str): Release/Debug config. If its not specified, cmake's default is used (most likely Debug). target_format (str): If specified, build for this targetformat ('frameworks' or 'libraries'). use_openssl (bool) : Use prebuilt OpenSSL library instead of using boringssl downloaded and built during the cmake configure step. disable_vcpkg (bool): If True, skip vcpkg and just use CMake for deps. gha_build (bool): If True, this build will be marked as having been built from GitHub, which is useful for metrics tracking. verbose (bool): If True, enable verbose mode in the CMake file. """ cmd = ['cmake', '-S', '.', '-B', build_dir] # If generator is not specifed, default for platform is used by cmake, else # use the specified value if config: cmd.append('-DCMAKE_BUILD_TYPE={0}'.format(config)) if build_tests: cmd.append('-DFIREBASE_CPP_BUILD_TESTS=ON') cmd.append('-DFIREBASE_FORCE_FAKE_SECURE_STORAGE=ON') else: # workaround, absl doesn't build without tests enabled cmd.append('-DBUILD_TESTING=off') if not disable_vcpkg: if utils.is_linux_os() and arch == 'x86': # Use a separate cmake toolchain for cross compiling linux x86 builds vcpkg_toolchain_file_path = os.path.join(os.getcwd(), 'external', 'vcpkg', 'scripts', 'buildsystems', 'linux_32.cmake') elif utils.is_mac_os() and arch == 'arm64': vcpkg_toolchain_file_path = os.path.join(os.getcwd(), 'external', 'vcpkg', 'scripts', 'buildsystems', 'macos_arm64.cmake') else: vcpkg_toolchain_file_path = os.path.join(os.getcwd(), 'external', 'vcpkg', 'scripts', 'buildsystems', 'vcpkg.cmake') cmd.append('-DCMAKE_TOOLCHAIN_FILE={0}'.format(vcpkg_toolchain_file_path)) vcpkg_triplet = utils.get_vcpkg_triplet(arch, msvc_runtime_library) cmd.append('-DVCPKG_TARGET_TRIPLET={0}'.format(vcpkg_triplet)) if utils.is_windows_os(): # If building for x86, we should supply -A Win32 to cmake configure # Its a good habit to specify for x64 too as the default might be different # on different windows machines. cmd.append('-A') cmd.append('Win32') if arch == 'x86' else cmd.append('x64') # Use our special cmake flag to specify /MD vs /MT if msvc_runtime_library == "static": cmd.append('-DMSVC_RUNTIME_LIBRARY_STATIC=ON') if utils.is_mac_os(): if (arch == 'arm64'): cmd.append('-DCMAKE_OSX_ARCHITECTURES=arm64') else: cmd.append('-DCMAKE_OSX_ARCHITECTURES=x86_64') if utils.is_linux_os() and linux_abi == 'c++11': cmd.append('-DFIREBASE_LINUX_USE_CXX11_ABI=TRUE') if (target_format): cmd.append('-DFIREBASE_XCODE_TARGET_FORMAT={0}'.format(target_format)) if not use_openssl: cmd.append('-DFIREBASE_USE_BORINGSSL=ON') # When building from GitHub Actions, this should always be set. if gha_build: cmd.append('-DFIREBASE_GITHUB_ACTION_BUILD=ON') # Print out every command while building. if verbose: cmd.append('-DCMAKE_VERBOSE_MAKEFILE=1') utils.run_command(cmd)
def main(): args = parse_cmdline_args() summary_headers = ['Library', 'Architecture'] # Setup platform specific functions if utils.is_linux_os(): arch_pattern = get_arch_re_pattern_linux() inspect_arch_function = inspect_arch_linux summarize_arch_function = functools.partial(summarize_arch_linux, re_pattern=arch_pattern) elif utils.is_mac_os(): arch_pattern = get_arch_re_pattern_mac() inspect_arch_function = inspect_arch_mac summarize_arch_function = functools.partial(summarize_arch_mac, re_pattern=arch_pattern) elif utils.is_windows_os(): arch_pattern = get_arch_re_pattern_windows() dumpbin = get_or_create_dumpbin_exe_path() inspect_arch_function = functools.partial(inspect_arch_windows, dumpbin_exe_path=dumpbin) summarize_arch_function = functools.partial(summarize_arch_windows, re_pattern=arch_pattern) summary_headers.append('MSVC_Runtime') msvc_runtime_library_pattern = get_msvc_runtime_library_re_pattern() else: raise ValueError( "Unsupported desktop OS. Can be either Mac, Linux or Windows.") # We technically dont support full blown regex or glob filters but still cover # the simplest and most frequently used symbol *, just incase. Avoiding # regex for speed and convenience (users can easily forget quotes around # and that expands to # all files in current directory). libs = get_libraries_to_inspect(args.libraries, args.library_filter.replace('*', '')) all_libs_info = [] for lib in libs: libname = os.path.basename(lib) if not args.print_full_paths else lib libinfo = [libname] try: verbose_data = inspect_arch_function(lib) if args.verbose: print("Inspecting architecture: {0}".format(lib)) print(verbose_data) print() arch = summarize_arch_function(verbose_data) libinfo.append(arch) except: libinfo.append('N.A') if utils.is_windows_os(): try: verbose_data = inspect_msvc_runtime_library( lib, dumpbin_exe_path=dumpbin) if args.verbose: print("Inspecting msvc runtime library: {0}".format(lib)) print(verbose_data) print() runtime_library = summarize_msvc_runtime_library( verbose_data, re_pattern=msvc_runtime_library_pattern) libinfo.append(runtime_library) except: libinfo.append('N.A') all_libs_info.append(libinfo) # Sort libraries info based on library names. all_libs_info.sort(key=lambda x: x[0]) print_summary_table(summary_headers, all_libs_info)