Debian Codegraph @

infra/bots/recipe_modules/build/chromebook.py

raw
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
5 from . import util
6 import os
7
8 def 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
17 args = {
18 'cc': "%s" % os.path.join(clang_linux, 'bin','clang'),
19 'cxx': "%s" % os.path.join(clang_linux, 'bin','clang++'),
20 'extra_cflags' : [],
21 'extra_ldflags' : [],
22 'extra_asmflags' : [],
23 'is_trivial_abi': True,
24 'target_cpu': target_arch,
25 'skia_use_fontconfig': False,
26 'skia_use_system_freetype2': False,
27 'skia_use_egl': True,
28 'werror': True,
29 }
30
31 if 'arm' == target_arch:
32 # This is a pretty typical arm-linux-gnueabihf sysroot
33 sysroot_dir = os.path.join(top_level, 'armhf_sysroot')
34
35 # This is the extra things needed to link against for the chromebook.
36 # For example, the Mali GL drivers.
37 gl_dir = os.path.join(top_level, 'chromebook_arm_gles')
38 env = {'LD_LIBRARY_PATH': os.path.join(sysroot_dir, 'lib')}
39 args['extra_asmflags'] = [
40 '--target=armv7a-linux-gnueabihf',
41 '--sysroot=%s' % sysroot_dir,
42 '-march=armv7-a',
43 '-mfpu=neon',
44 '-mthumb',
45 ]
46
47 args['extra_cflags'] = [
48 '--target=armv7a-linux-gnueabihf',
49 '--sysroot=%s' % sysroot_dir,
50 '-I%s' % os.path.join(gl_dir, 'include'),
51 '-I%s' % os.path.join(sysroot_dir, 'include'),
52 '-I%s' % os.path.join(sysroot_dir, 'include', 'c++', '10'),
53 '-I%s' % os.path.join(sysroot_dir, 'include', 'c++', '10', 'arm-linux-gnueabihf'),
54 '-DMESA_EGL_NO_X11_HEADERS',
55 '-U_GLIBCXX_DEBUG',
56 ]
57
58 args['extra_ldflags'] = [
59 '--target=armv7a-linux-gnueabihf',
60 '--sysroot=%s' % sysroot_dir,
61 '-static-libstdc++', '-static-libgcc',
62 # use sysroot's ld which can properly link things.
63 '-B%s' % os.path.join(sysroot_dir, 'bin'),
64 # helps locate crt*.o
65 '-B%s' % os.path.join(sysroot_dir, 'gcc-cross'),
66 # helps locate libgcc*.so
67 '-L%s' % os.path.join(sysroot_dir, 'gcc-cross'),
68 '-L%s' % os.path.join(sysroot_dir, 'lib'),
69 '-L%s' % os.path.join(gl_dir, 'lib'),
70 ]
71 elif 'arm64' == target_arch:
72 sysroot_dir = os.path.join(top_level, 'arm64_sysroot')
73 gl_dir = os.path.join(top_level, 'chromebook_arm64_gles')
74 env = {'LD_LIBRARY_PATH': os.path.join(sysroot_dir, 'lib')}
75 args['extra_asmflags'] = [
76 '--target=aarch64-linux-gnueabihf',
77 '--sysroot=%s' % sysroot_dir,
78 '-march=armv8-a',
79 '-mfpu=neon',
80 '-mthumb',
81 ]
82
83 args['extra_cflags'] = [
84 '--target=aarch64-linux-gnueabihf',
85 '--sysroot=%s' % sysroot_dir,
86 '-I%s' % os.path.join(sysroot_dir, 'include'),
87 '-I%s' % os.path.join(sysroot_dir, 'include', 'c++', '12'),
88 '-I%s' % os.path.join(sysroot_dir, 'include', 'c++', '12', 'aarch64-linux-gnu'),
89 '-I%s' % os.path.join(gl_dir, 'include'),
90 '-U_GLIBCXX_DEBUG',
91 ]
92
93 args['extra_ldflags'] = [
94 '--target=aarch64-linux-gnueabihf',
95 '--sysroot=%s' % sysroot_dir,
96 '-static-libstdc++', '-static-libgcc',
97 '-fuse-ld=%s' % os.path.join(clang_linux, 'bin', 'ld.lld'),
98 # use sysroot's ld which can properly link things.
99 '-B%s' % os.path.join(sysroot_dir, 'bin'),
100 # helps locate crt*.o
101 '-B%s' % os.path.join(sysroot_dir, 'gcc-cross'),
102 # helps locate libgcc*.so
103 '-L%s' % os.path.join(sysroot_dir, 'gcc-cross'),
104 '-L%s' % os.path.join(sysroot_dir, 'lib'),
105 '-L%s' % os.path.join(gl_dir, 'lib'),
106 # Explicitly link atomics.
107 '-Wl,-u,__aarch64_swp4_acq_rel',
108 '-Wl,-u,__aarch64_cas4_acq_rel',
109 os.path.join(sysroot_dir, 'gcc-cross', 'libgcc.a'),
110 ]
111 else:
112 gl_dir = os.path.join(top_level,'chromebook_x86_64_gles')
113 env = {}
114 args['extra_asmflags'] = []
115 args['extra_cflags'] = [
116 '-DMESA_EGL_NO_X11_HEADERS',
117 '-I%s' % os.path.join(gl_dir, 'include'),
118 ]
119 args['extra_ldflags'] = [
120 '-L%s' % os.path.join(gl_dir, 'lib'),
121 '-static-libstdc++', '-static-libgcc',
122 '-fuse-ld=lld',
123 ]
124
125 args['extra_cflags'].append('-DREBUILD_IF_CHANGED_clang_linux_version=%s' %
126 api.run.asset_version('clang_linux', skia_dir))
127
128 if configuration != 'Debug':
129 args['is_debug'] = False
130
131 gn = skia_dir.joinpath('bin', 'gn')
132 ninja = skia_dir.joinpath('third_party', 'ninja', 'ninja')
133
134 with api.context(cwd=skia_dir, env=env):
135 api.run(api.step, 'fetch-gn',
136 cmd=['python3', skia_dir.joinpath('bin', 'fetch-gn')],
137 infra_step=True)
138 api.run(api.step, 'fetch-ninja',
139 cmd=['python3', skia_dir.joinpath('bin', 'fetch-ninja')],
140 infra_step=True)
141 api.run(api.step, 'gn gen',
142 cmd=[gn, 'gen', out_dir, '--args=' + util.py_to_gn(args)])
143 api.run(api.step, 'ninja',
144 cmd=[ninja, '-C', out_dir, 'nanobench', 'dm'])
145
146
147 def copy_build_products(api, src, dst):
148 util.copy_listed_files(api, src, dst, util.DEFAULT_BUILD_PRODUCTS)