blob: 98e39f068d56c9b59435a47ffb42ef8159f41bb5 [file] [log] [blame]
Patrick Williams975a06f2022-10-21 14:42:47 -05001LICENSE = "Apache-2.0 & BSD-3-Clause & MIT & Zlib"
2
3LIC_FILES_CHKSUM = "file://LICENSE;md5=f87516e0b698007e9e75a1fe1012b390 \
4 file://buildtools/libcxx/LICENSE.TXT;md5=55d89dd7eec8d3b4204b680e27da3953 \
5 file://buildtools/libcxx/utils/google-benchmark/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57 \
6 file://buildtools/libcxxabi/LICENSE.TXT;md5=7b9334635b542c56868400a46b272b1e \
7 file://buildtools/libunwind/LICENSE.TXT;md5=f66970035d12f196030658b11725e1a1 \
8 file://buildtools/protobuf/LICENSE;md5=37b5762e07f0af8c74ce80a8bda4266b \
9 file://buildtools/zlib/LICENSE;md5=f09575dbfb09420642318b413159496f \
10 file://debian/copyright;md5=4e08364c82141f181de69d0a2b89d612 \
11 file://python/LICENSE;md5=c602a632c34ade9c78a976734077bce7"
12
Patrick Williams2390b1b2022-11-03 13:47:49 -050013SRC_URI:append = " \
Patrick Williams975a06f2022-10-21 14:42:47 -050014 git://github.com/protocolbuffers/protobuf.git;branch=3.9.x;protocol=https;destsuffix=git/buildtools/protobuf;name=protobuf \
15 git://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxx.git;protocol=https;destsuffix=git/buildtools/libcxx;branch=main;name=libcxx \
16 git://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxxabi.git;protocol=https;destsuffix=git/buildtools/libcxxabi;branch=main;name=libcxxabi \
17 git://chromium.googlesource.com/external/github.com/llvm/llvm-project/libunwind.git;protocol=https;destsuffix=git/buildtools/libunwind;branch=main;name=libunwind \
18 git://android.googlesource.com/platform/external/zlib.git;branch=master;protocol=https;destsuffix=git/buildtools/zlib;name=zlib \
19 https://storage.googleapis.com/perfetto/gn-linux64-1968-0725d782;subdir=git/buildtools/;name=gn \
20 file://0001-Remove-check_build_deps-build-steps.patch "
21
Patrick Williams975a06f2022-10-21 14:42:47 -050022SRCREV_protobuf = "6a59a2ad1f61d9696092f79b6d74368b4d7970a3"
23SRCREV_libcxx = "d9040c75cfea5928c804ab7c235fed06a63f743a"
24SRCREV_libcxxabi = "196ba1aaa8ac285d94f4ea8d9836390a45360533"
25SRCREV_libunwind = "d999d54f4bca789543a2eb6c995af2d9b5a1f3ed"
26SRCREV_zlib = "5c85a2da4c13eda07f69d81a1579a5afddd35f59"
27SRC_URI[gn.sha256sum] = "f706aaa0676e3e22f5fc9ca482295d7caee8535d1869f99efa2358177b64f5cd"
28
Patrick Williams2390b1b2022-11-03 13:47:49 -050029require perfetto.inc
30
Patrick Williams975a06f2022-10-21 14:42:47 -050031DEPENDS += " ninja-native"
32
33COMPATIBLE_HOST = "(i.86|x86_64|aarch64|arm).*-linux*"
34
35FILES:${PN}:append = " \
36 ${bindir}/tracebox \
37 "
38
Patrick Williams975a06f2022-10-21 14:42:47 -050039B = "${WORKDIR}/build"
40
41# Run the GN (Generate Ninja) script, and replace the compiler flags where applicable
42do_configure () {
43 # Configuration needs to be done from the source directory
44 cd ${S}
45 # Rename a few build tools if they have not been renamed
46 cd buildtools
47 x="gn-linux64-1968-0725d782"
48 [ -f $x ] && mkdir linux64 && mv $x linux64/gn
49 chmod +x linux64/gn
50 cd ..
51
52 CC_BIN=`echo $CC | awk '{print $1}'`
53 CXX_BIN=`echo $CXX | awk '{print $1}'`
54 STRIP_BIN=`echo $STRIP | awk '{print $1}'`
55
56 ARGS="is_debug=false " # Tell gn to use release mode
57
58 if [ -z `echo ${TOOLCHAIN} | grep clang` ]; then
59 ARGS=$ARGS" is_clang=false"
60 else
61 ARGS=$ARGS" is_clang=true"
62 fi
63
64 # Architecture parameter accepted by Perfetto
65 arch=${TARGET_ARCH}
66 if [ $arch = "i686" ]; then
67 arch="x86"
68 elif [ $arch = "x86_64" ]; then
69 arch="x64"
70 elif [ $arch = "aarch64" ]; then
71 arch="arm64"
72 fi
73
74 # For ARM32 with hardware floating point using clang and musl, we need to
75 # specify -mfloat-abi=hard to make the ABI settings of the linker and the
76 # compiler match. The linker would use hardware float ABI. The compiler does
77 # not. As a result we need to force the compiler to do so by adding
78 # -mfloat-abi=hard to compilation flags.
79 FLOAT_ABI=""
80 if [[ "${@bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'true', 'false', d)}" == "true" ]]; then
81 FLOAT_ABI="-mfloat-abi=hard"
82 fi
83
84 ARGS=$ARGS" target_os=\"linux\""
85 ARGS=$ARGS" target_cpu=\"$arch\""
86 ARGS=$ARGS" target_cc=\"$CC_BIN ${FLOAT_ABI}\""
87 ARGS=$ARGS" target_cxx=\"$CXX_BIN -std=c++11 ${FLOAT_ABI}\""
88 ARGS=$ARGS" target_strip=\"$STRIP_BIN\"" #
89 ARGS=$ARGS" target_sysroot=\"${RECIPE_SYSROOT}\""
90 ARGS=$ARGS" target_linker=\"$CC_BIN ${FLOAT_ABI} ${LDFLAGS}\""
91 ARGS=$ARGS" target_ar=\"$AR\""
92 ARGS="'$ARGS'"
93 cmd="tools/gn gen --args=$ARGS ${B}"
94
95 echo $cmd
96 # Use eval, not just call $cmd, due to escaping of single quotation marks
97 eval $cmd
98
99 cd ${B}
100 # Eliminate a few incompatible build flags
101 REPLACES="s/-Wl,--icf=all//g"
102 REPLACES=$REPLACES";s/-Werror//g"
103 REPLACES=$REPLACES";s/-mfpu=neon//g"
104 REPLACES=$REPLACES";s/-fcolor-diagnostics//g"
105 REPLACES=$REPLACES";s/=format-security//g"
106 REPLACES=$REPLACES";s/-fdiagnostics-show-template-tree//g"
107 REPLACES=$REPLACES";s/-D_FORTIFY_SOURCE=2//g"
108 REPLACES=$REPLACES";s/-fuse-ld=\S*//g"
109
110 find . -name "*.ninja" | xargs sed $REPLACES -i
111
112 # If using the clang toolchain: use the clang host-side binaries built by Bitbake
113 if [ "${TOOLCHAIN}" = "clang" ]; then
114 BB_CLANGXX="${BUILD_CXX} ${BUILD_LDFLAGS} ${FLOAT_ABI}"
115 BB_CLANG="${BUILD_CC} ${FLOAT_ABI}"
116 BB_LLVM_OBJCOPY="${RECIPE_SYSROOT_NATIVE}/usr/bin/llvm-objcopy"
117
118 HOST_CLANGXX="${STAGING_DIR_NATIVE}/usr/bin/clang++ -stdlib=libc++ -rtlib=libgcc -unwindlib=libgcc ${FLOAT_ABI}"
119 HOST_CLANG="${STAGING_DIR_NATIVE}/usr/bin/clang ${FLOAT_ABI}"
120 HOST_LLVM_OBJCOPY="${STAGING_DIR_NATIVE}/usr/bin/llvm-objcopy"
121
122 cd gcc_like_host
123 REPLACES="s:\S*clang++ :$HOST_CLANGXX :g"
124 REPLACES=$REPLACES";s:\S*clang :$HOST_CLANG :g"
125 REPLACES=$REPLACES";s:\S*llvm-objcopy :$HOST_LLVM_OBJCOPY :g"
126 find . -name "*.ninja" | xargs sed "$REPLACES" -i
127 cd ..
128 fi
129 # Done processing the Ninja files
130
131 # Workaround for the functions not supported by musl
132 if [ "${TCLIBC}" = "musl" ]; then
133 sed -e 's/strtoll_l(__a, \&__p2, __base, _LIBCPP_GET_C_LOCALE)/strtoll(__a, \&__p2, __base)/g' \
134 -e 's/strtoull_l(__a, \&__p2, __base, _LIBCPP_GET_C_LOCALE)/strtoull(__a, \&__p2, __base)/g' \
135 ${S}/buildtools/libcxx/include/locale -i
136 fi
137}
138
139# Perfetto generates a few different binaries, such as traced and traced_probes and perfetto.
140# The "tracebox" is a busybox that combines the 3 above and provides a single stop for trace capture, so we only build "tracebox" here.
141do_compile () {
142 cd ${B}
143 ninja -C . tracebox
144}
145
146do_install () {
147 BIN_DIR=${D}${bindir}
148
149 install -d -m0755 $BIN_DIR
150 install ${B}/tracebox $BIN_DIR/tracebox
151}