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 8IMAGES = { 9 # Used to build ChromeOS for Pixelbook in Debian9, to align GLIBC versions. 10 'Debian9': ( 11 'gcr.io/skia-public/debian9@sha256:' 12 '7bdcb25e8c37597acd254b0c5b4ff8d004745eddede3363213bcc06fb0feace3'), 13} 14 15def compile_fn(api, checkout_root, out_dir): 16 skia_dir = checkout_root.join('skia') 17 configuration = api.vars.builder_cfg.get('configuration') 18 target_arch = api.vars.builder_cfg.get('target_arch') 19 os_name = api.vars.builder_cfg.get('os', '') 20 builder_name = api.vars.builder_name 21 22 # Currently we mount this directory to /SRC in Docker. 23 # TODO(westont): Add docker module API to match binding to actual structure. 24 top_level = '/SRC' if 'Docker' in builder_name else str(api.vars.workdir) 25 26 clang_linux = os.path.join(top_level, 'clang_linux') 27 # This is a pretty typical arm-linux-gnueabihf sysroot 28 sysroot_dir = os.path.join(top_level, 'armhf_sysroot') 29 30 args = { 31 'cc': "%s" % os.path.join(clang_linux, 'bin','clang'), 32 'cxx': "%s" % os.path.join(clang_linux, 'bin','clang++'), 33 'extra_cflags' : [], 34 'extra_ldflags' : [], 35 'extra_asmflags' : [], 36 'target_cpu': target_arch, 37 'skia_use_fontconfig': False, 38 'skia_use_system_freetype2': False, 39 'skia_use_egl': True, 40 'werror': True, 41 } 42 43 if 'arm' == target_arch: 44 # This is the extra things needed to link against for the chromebook. 45 # For example, the Mali GL drivers. 46 gl_dir = os.path.join(top_level, 'chromebook_arm_gles') 47 env = {'LD_LIBRARY_PATH': os.path.join(sysroot_dir, 'lib')} 48 args['extra_asmflags'] = [ 49 '--target=armv7a-linux-gnueabihf', 50 '--sysroot=%s' % sysroot_dir, 51 '-march=armv7-a', 52 '-mfpu=neon', 53 '-mthumb', 54 ] 55 56 args['extra_cflags'] = [ 57 '--target=armv7a-linux-gnueabihf', 58 '--sysroot=%s' % sysroot_dir, 59 '-I%s' % os.path.join(gl_dir, 'include'), 60 '-I%s' % os.path.join(sysroot_dir, 'include'), 61 '-I%s' % os.path.join(sysroot_dir, 'include', 'c++', '6'), 62 '-I%s' % os.path.join(sysroot_dir, 'include', 'c++', '6', 'arm-linux-gnueabihf'), 63 '-DMESA_EGL_NO_X11_HEADERS', 64 '-U_GLIBCXX_DEBUG', 65 ] 66 67 args['extra_ldflags'] = [ 68 '--target=armv7a-linux-gnueabihf', 69 '--sysroot=%s' % sysroot_dir, 70 '-static-libstdc++', '-static-libgcc', 71 # use sysroot's ld which can properly link things. 72 '-B%s' % os.path.join(sysroot_dir, 'bin'), 73 # helps locate crt*.o 74 '-B%s' % os.path.join(sysroot_dir, 'gcc-cross'), 75 # helps locate libgcc*.so 76 '-L%s' % os.path.join(sysroot_dir, 'gcc-cross'), 77 '-L%s' % os.path.join(sysroot_dir, 'lib'), 78 '-L%s' % os.path.join(gl_dir, 'lib'), 79 ] 80 else: 81 gl_dir = os.path.join(top_level,'chromebook_x86_64_gles') 82 env = {} 83 args['extra_asmflags'] = [] 84 args['extra_cflags'] = [ 85 '-DMESA_EGL_NO_X11_HEADERS', 86 '-I%s' % os.path.join(gl_dir, 'include'), 87 ] 88 args['extra_ldflags'] = [ 89 '-L%s' % os.path.join(gl_dir, 'lib'), 90 '-static-libstdc++', '-static-libgcc', 91 '-fuse-ld=lld', 92 ] 93 94 args['extra_cflags'].append('-DREBUILD_IF_CHANGED_clang_linux_version=%s' % 95 api.run.asset_version('clang_linux', skia_dir)) 96 97 if configuration != 'Debug': 98 args['is_debug'] = False 99 100 gn = skia_dir.join('bin', 'gn') 101 102 if os_name == 'Debian9' and 'Docker' in builder_name: 103 script = api.build.resource('docker-chromeos-compile.sh') 104 image_hash = IMAGES[os_name] 105 # Invalidate incremental build cache if image changes. 106 args['extra_cflags'].append('-DREBUILD_IF_CHANGED_docker_image=%s' % image_hash) 107 api.docker.run('Run build script in Docker', image_hash, 108 checkout_root, out_dir, script, args=[util.py_to_gn(args)]) 109 return 110 111 with api.context(cwd=skia_dir, env=env): 112 api.run(api.python, 'fetch-gn', 113 script=skia_dir.join('bin', 'fetch-gn'), 114 infra_step=True) 115 api.run(api.step, 'gn gen', 116 cmd=[gn, 'gen', out_dir, '--args=' + util.py_to_gn(args)]) 117 api.run(api.step, 'ninja', 118 cmd=['ninja', '-C', out_dir, 'nanobench', 'dm']) 119 120 121def copy_build_products(api, src, dst): 122 util.copy_listed_files(api, src, dst, util.DEFAULT_BUILD_PRODUCTS) 123