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 6 7def compile_fn(api, checkout_root, out_dir): 8 skia_dir = checkout_root.join('skia') 9 configuration = api.vars.builder_cfg.get('configuration') 10 target_arch = api.vars.builder_cfg.get('target_arch') 11 12 clang_linux = api.vars.slave_dir.join('clang_linux') 13 # This is a pretty typical arm-linux-gnueabihf sysroot 14 sysroot_dir = api.vars.slave_dir.join('armhf_sysroot') 15 16 if 'arm' == target_arch: 17 # This is the extra things needed to link against for the chromebook. 18 # For example, the Mali GL drivers. 19 gl_dir = api.vars.slave_dir.join('chromebook_arm_gles') 20 env = {'LD_LIBRARY_PATH': sysroot_dir.join('lib')} 21 extra_asmflags = [ 22 '--target=armv7a-linux-gnueabihf', 23 '--sysroot=%s' % sysroot_dir, 24 '-march=armv7-a', 25 '-mfpu=neon', 26 '-mthumb', 27 ] 28 29 extra_cflags = [ 30 '--target=armv7a-linux-gnueabihf', 31 '--sysroot=%s' % sysroot_dir, 32 '-I%s' % gl_dir.join('include'), 33 '-I%s' % sysroot_dir.join('include'), 34 '-I%s' % sysroot_dir.join('include', 'c++', '6'), 35 '-I%s' % sysroot_dir.join('include', 'c++', '6', 'arm-linux-gnueabihf'), 36 '-DMESA_EGL_NO_X11_HEADERS', 37 '-U_GLIBCXX_DEBUG', 38 ] 39 40 extra_ldflags = [ 41 '--target=armv7a-linux-gnueabihf', 42 '--sysroot=%s' % sysroot_dir, 43 '-static-libstdc++', '-static-libgcc', 44 # use sysroot's ld which can properly link things. 45 '-B%s' % sysroot_dir.join('bin'), 46 # helps locate crt*.o 47 '-B%s' % sysroot_dir.join('gcc-cross'), 48 # helps locate libgcc*.so 49 '-L%s' % sysroot_dir.join('gcc-cross'), 50 '-L%s' % sysroot_dir.join('lib'), 51 '-L%s' % gl_dir.join('lib'), 52 ] 53 else: 54 gl_dir = api.vars.slave_dir.join('chromebook_x86_64_gles') 55 env = {} 56 extra_asmflags = [] 57 extra_cflags = [ 58 '-DMESA_EGL_NO_X11_HEADERS', 59 '-I%s' % gl_dir.join('include'), 60 ] 61 extra_ldflags = [ 62 '-L%s' % gl_dir.join('lib'), 63 '-static-libstdc++', '-static-libgcc', 64 '-fuse-ld=lld', 65 ] 66 67 quote = lambda x: '"%s"' % x 68 args = { 69 'cc': quote(clang_linux.join('bin','clang')), 70 'cxx': quote(clang_linux.join('bin','clang++')), 71 'target_cpu': quote(target_arch), 72 'skia_use_fontconfig': 'false', 73 'skia_use_system_freetype2': 'false', 74 'skia_use_egl': 'true', 75 'werror': 'true', 76 } 77 extra_cflags.append('-DDUMMY_clang_linux_version=%s' % 78 api.run.asset_version('clang_linux', skia_dir)) 79 80 if configuration != 'Debug': 81 args['is_debug'] = 'false' 82 args['extra_asmflags'] = repr(extra_asmflags).replace("'", '"') 83 args['extra_cflags'] = repr(extra_cflags).replace("'", '"') 84 args['extra_ldflags'] = repr(extra_ldflags).replace("'", '"') 85 86 gn_args = ' '.join('%s=%s' % (k,v) for (k,v) in sorted(args.iteritems())) 87 gn = skia_dir.join('bin', 'gn') 88 89 with api.context(cwd=skia_dir, env=env): 90 api.run(api.python, 'fetch-gn', 91 script=skia_dir.join('bin', 'fetch-gn'), 92 infra_step=True) 93 api.run(api.step, 'gn gen', cmd=[gn, 'gen', out_dir, '--args=' + gn_args]) 94 api.run(api.step, 'ninja', 95 cmd=['ninja', '-C', out_dir, 'nanobench', 'dm']) 96 97 98def copy_build_products(api, src, dst): 99 util.copy_listed_files(api, src, dst, util.DEFAULT_BUILD_PRODUCTS) 100