1# Copyright 2018 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from . import util 6import os 7 8def compile_fn(api, checkout_root, out_dir): 9 skia_dir = checkout_root.joinpath('skia') 10 configuration = api.vars.builder_cfg.get('configuration') 11 target_arch = api.vars.builder_cfg.get('target_arch') 12 13 top_level = str(api.vars.workdir) 14 15 clang_linux = os.path.join(top_level, 'clang_linux') 16 # This is a pretty typical arm-linux-gnueabihf sysroot 17 sysroot_dir = os.path.join(top_level, 'armhf_sysroot') 18 19 args = { 20 'cc': "%s" % os.path.join(clang_linux, 'bin','clang'), 21 'cxx': "%s" % os.path.join(clang_linux, 'bin','clang++'), 22 'extra_cflags' : [], 23 'extra_ldflags' : [], 24 'extra_asmflags' : [], 25 'target_cpu': target_arch, 26 'skia_use_fontconfig': False, 27 'skia_use_system_freetype2': False, 28 'skia_use_egl': True, 29 'werror': True, 30 } 31 32 if 'arm' == target_arch: 33 # This is the extra things needed to link against for the chromebook. 34 # For example, the Mali GL drivers. 35 gl_dir = os.path.join(top_level, 'chromebook_arm_gles') 36 env = {'LD_LIBRARY_PATH': os.path.join(sysroot_dir, 'lib')} 37 args['extra_asmflags'] = [ 38 '--target=armv7a-linux-gnueabihf', 39 '--sysroot=%s' % sysroot_dir, 40 '-march=armv7-a', 41 '-mfpu=neon', 42 '-mthumb', 43 ] 44 45 args['extra_cflags'] = [ 46 '--target=armv7a-linux-gnueabihf', 47 '--sysroot=%s' % sysroot_dir, 48 '-I%s' % os.path.join(gl_dir, 'include'), 49 '-I%s' % os.path.join(sysroot_dir, 'include'), 50 '-I%s' % os.path.join(sysroot_dir, 'include', 'c++', '10'), 51 '-I%s' % os.path.join(sysroot_dir, 'include', 'c++', '10', 'arm-linux-gnueabihf'), 52 '-DMESA_EGL_NO_X11_HEADERS', 53 '-U_GLIBCXX_DEBUG', 54 ] 55 56 args['extra_ldflags'] = [ 57 '--target=armv7a-linux-gnueabihf', 58 '--sysroot=%s' % sysroot_dir, 59 '-static-libstdc++', '-static-libgcc', 60 # use sysroot's ld which can properly link things. 61 '-B%s' % os.path.join(sysroot_dir, 'bin'), 62 # helps locate crt*.o 63 '-B%s' % os.path.join(sysroot_dir, 'gcc-cross'), 64 # helps locate libgcc*.so 65 '-L%s' % os.path.join(sysroot_dir, 'gcc-cross'), 66 '-L%s' % os.path.join(sysroot_dir, 'lib'), 67 '-L%s' % os.path.join(gl_dir, 'lib'), 68 ] 69 else: 70 gl_dir = os.path.join(top_level,'chromebook_x86_64_gles') 71 env = {} 72 args['extra_asmflags'] = [] 73 args['extra_cflags'] = [ 74 '-DMESA_EGL_NO_X11_HEADERS', 75 '-I%s' % os.path.join(gl_dir, 'include'), 76 ] 77 args['extra_ldflags'] = [ 78 '-L%s' % os.path.join(gl_dir, 'lib'), 79 '-static-libstdc++', '-static-libgcc', 80 '-fuse-ld=lld', 81 ] 82 83 args['extra_cflags'].append('-DREBUILD_IF_CHANGED_clang_linux_version=%s' % 84 api.run.asset_version('clang_linux', skia_dir)) 85 86 if configuration != 'Debug': 87 args['is_debug'] = False 88 89 gn = skia_dir.joinpath('bin', 'gn') 90 91 with api.context(cwd=skia_dir, env=env): 92 api.run(api.step, 'fetch-gn', 93 cmd=['python3', skia_dir.joinpath('bin', 'fetch-gn')], 94 infra_step=True) 95 api.run(api.step, 'fetch-ninja', 96 cmd=['python3', skia_dir.joinpath('bin', 'fetch-ninja')], 97 infra_step=True) 98 api.run(api.step, 'gn gen', 99 cmd=[gn, 'gen', out_dir, '--args=' + util.py_to_gn(args)]) 100 api.run(api.step, 'ninja', 101 cmd=['ninja', '-C', out_dir, 'nanobench', 'dm']) 102 103 104def copy_build_products(api, src, dst): 105 util.copy_listed_files(api, src, dst, util.DEFAULT_BUILD_PRODUCTS) 106