Project

General

Profile

NDKBuild » History » Version 14

Beuc Beuc, 07/26/2015 04:49 PM
Windows build fails exactly the same way with Trisquel 4.1 - problem not related to build environment

1 1 Beuc Beuc
h1. Build a Native Developement Kit (NDK) with Replicant 4.2
2
3
h2. Principle of operation
4
5
The [[ReplicantSourceCode|Android 4.2 source code]] ships a @ndk@ directory with NDK build scripts.
6 9 Beuc Beuc
These tools download various upstream imports from https://git.androidproject.xxx/toolchain/XXX/ with optional commit date (no branches or tags), apply patches, and build them.
7 1 Beuc Beuc
8 2 Beuc Beuc
Note: as of 2015-07, the upcoming Android version moved to a different build system, and will populate $topdir/toolchain/ through @repo@ instead of invoking git in a temporary directory (i.e. ditched @download-toolchain-sources.sh@).
9
10 12 Beuc Beuc
h2. Recreate matching build environment
11 1 Beuc Beuc
12 12 Beuc Beuc
Replicant 4.2 is based on CyanogenMod 10.1 which is based on AOSP 4.2.2, released 2013-02.
13
The build environment used by NDK release managers should be Ubuntu LTS 12.04 (or maybe Ubuntu LTS 10.04).
14 2 Beuc Beuc
15 12 Beuc Beuc
To recreate it easily with LXC, follow:
16
* [[BuildEnvironments#Ubuntu-1204-Precise-with-LXC|Ubuntu 12.04 Precise with LXC]] (Trisquel support in progress)
17
* [[BuildEnvironments#Non-privileged-user-setup|Non-privileged user setup]]
18 3 Beuc Beuc
19
Note: compiling from Debian 8 will yield errors from texinfo (doc in binutils) and Perl (POD in LLVM) due to more recent, stricter versions of these.
20 2 Beuc Beuc
21
h2. Build dependencies
22
23
<pre>
24
# Base Android build dependencies (from https://source.android.com/source/initializing.html, section "Installing required packages (Ubuntu 12.04)")
25
# Dropping mingw to skip windows builds for now.
26
# Installing g++-multilib first otherwise apt-get complains.
27
apt-get install build-essential g++-multilib
28 13 Beuc Beuc
apt-get install wget git gnupg flex bison gperf \
29 2 Beuc Beuc
  zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
30
  libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
31
  libgl1-mesa-dev \
32
  python-markdown libxml2-utils xsltproc zlib1g-dev:i386
33
34
# Additional NDK build dependencies (completed from https://android.googlesource.com/platform/ndk/+/master/README.md)
35
apt-get install curl texinfo bison flex libtool pbzip2 groff
36
37
# Make 'bash' the default shell otherwise 'build-gabi++.sh' will fail
38
dpkg-reconfigure dash
39
</pre>
40
41
h2. Preparing the sources
42
43
Based on [[ReplicantSourceCode]] with additional configuration.
44 11 Beuc Beuc
Login as user @replicant@ and:
45 2 Beuc Beuc
46
<pre>
47
mkdir ~/tools/
48
cd ~/tools/
49
wget http://commondatastorage.googleapis.com/git-repo-downloads/repo
50
chmod a+x repo
51
cd ~
52
53
cat <<EOF >> ~/.bashrc
54
export USE_CCACHE=1
55
EOF
56 14 Beuc Beuc
exec bash
57 2 Beuc Beuc
58
# Avoid prompts
59
git config --global user.email "you@example.com"
60
git config --global user.name "Your Name"
61
git config --global color.ui true
62
63
mkdir replicant-4.2/
64
cd replicant-4.2/
65
../tools/repo init -u git://git.replicant.us/manifest.git -b replicant-4.2
66
../tools/repo sync -j4 
67
# > 1h, 27GB (inc. 17GB .repo)
68 14 Beuc Beuc
prebuilts/misc/linux-x86/ccache/ccache -M 10G  # unused in Trisquel 4.1?
69 2 Beuc Beuc
</pre>
70
71
h2. Determining the checkout date
72
73 7 Beuc Beuc
Since there's no NDK release tag for the @toolchain/@ Git checkouts, we need to find the right date.
74 2 Beuc Beuc
75
@cd ndk/ && git log@ says the last commit is 2012-10-05, so it's around NDK r8b (2012-07) and NDK r8c (2012-11).
76
Checking @build/tools/toolchain-patches/@ in the NDKs shows r8c has matching patches.
77
78
Also NDKs from google contain several @SOURCES@ files listing Git repos and commit IDs.
79 10 Beuc Beuc
With r8c's release date (@ls --full-time RELEASE.TXT@ => 2012-10-22 05:59), @build/tools/download-toolchain-sources.sh@ checkouts the same Git commit IDs, and the patches apply.
80 2 Beuc Beuc
Only, r8c references a LLVM Git repo, while our scripts download a tarball.
81
So our scripts match a NDK version between r8b and r8c, and can almost exactly reproduce r8c. Let's call it r8b2.
82
83
h2. Building the SDK
84
85
Based on @ndk/docs/DEVELOPMENT.html@, with much improvement :)
86
87
<pre>
88
export NDK=~/replicant-4.2/ndk
89
cd $NDK
90
91
# Allow checking build errors
92
export NDK_LOGFILE=$HOME/ndk.log
93
94
# Follow Python download redirection
95
sed -i -e 's/curl -S/curl -L -S/' build/tools/download-toolchain-sources.sh
96
97 10 Beuc Beuc
# Get the sources from toolchain/ repos, with r8c release date:
98 1 Beuc Beuc
bash $NDK/build/tools/download-toolchain-sources.sh --git-date='2012-10-22T05:59:40Z' ~/ndk-dl
99 14 Beuc Beuc
# ~5mn with good network, ndk-dl: 2.5GB
100 2 Beuc Beuc
101
# Define NDK_TMPDIR and and use --incremental so the build can be resumed on error
102
export NDK_TMPDIR=~/ndk-tmp
103
mkdir -p $NDK_TMPDIR/release-r8b2/
104
105 1 Beuc Beuc
# Build the release
106 2 Beuc Beuc
bash $NDK/build/tools/make-release.sh --toolchain-src-dir=$HOME/ndk-dl --release=r8b2 --incremental
107 14 Beuc Beuc
# 30mn with 4 cores, 28GB (inc. 17GB .repo), 2.5GB ndk-dl, ?GB ndk-tmp, 1GB /tmp
108 2 Beuc Beuc
</pre>
109
110
The GNU/Linux NDK release is in @/tmp/ndk-replicant/release/android-ndk-r8b2-linux-x86.tar.bz2@ :)
111 4 Beuc Beuc
112
113
h2. TODOs
114 1 Beuc Beuc
115 7 Beuc Beuc
h3. Mirror @toolchain/@ repos
116
117
@download-toolchain-sources.sh@'s default is @--git-base=https://android.googlesource.com/toolchain@.
118
Should we use a git.replicant.us repo? (note: there's no 'toolchain' there yet)
119
120 4 Beuc Beuc
h3. Windows build
121
122
Build deps:
123
<pre>
124
# windows build is triggered by the presence of mingw32
125
apt-get install mingw32 tofrodos
126
# and requires running maketab.exe
127
apt-get install wine
128
# I had troubles in LXC registering direct .exe execution:
129
# $ /tmp/ndk-replicant/tmp/build-3038/maketab.exe 
130 1 Beuc Beuc
# run-detectors: unable to find an interpreter for /tmp/ndk-replicant/tmp/build-3038/maketab.exe
131 4 Beuc Beuc
# Work-around:
132
update-binfmts --disable
133 14 Beuc Beuc
dpkg-reconfigure wine1.4 --pri=high  # or wine1.2 for Trisquel 4.1
134 4 Beuc Beuc
</pre>
135
136
Code fixes:
137
<pre>
138
# build-ndk-stack/elff/ produces a warning with mingw32, and uses -Werror
139
# cf. https://android.googlesource.com/platform/ndk/+/32e74f3f1b969ff65f037e1ee89e21a5cbc0ecf0
140
sed -i -e 's/-Werror//' sources/host-tools/ndk-stack/GNUMakefile
141
# TODO: maybe 'export EXTRA_CFLAGS=-Wall' would be enough?
142
</pre>
143
144
...
145 1 Beuc Beuc
146
<pre>
147
bash $NDK/build/tools/make-release.sh --toolchain-src-dir=$HOME/ndk-dl --release=r8b2 --incremental
148
# /home/replicant/ndk-dl/build/../binutils/binutils-2.21/gold/arm.cc:2171: internal compiler error: in make_rtl_for_nonlocal_decl, at cp/decl.c:4971
149
</pre>
150 14 Beuc Beuc
151
Exact same errors with Trisquel 4.1 (Ubuntu 10.04).  For reference, the build dependencies:
152
<pre>
153
# Based on https://web.archive.org/web/20121201011547/http://source.android.com/source/initializing.html
154
apt-get install gnupg flex bison gperf build-essential \
155
  zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
156
  x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
157
  libgl1-mesa-dev g++-multilib python-markdown \
158
  libxml2-utils xsltproc
159
</pre>
160
161
No idea how google made the windows build for r8c.  Maybe a later ndk.git has fixes?
162
163 4 Beuc Beuc
164 6 Beuc Beuc
h3. Use of prebuilts
165
166
Check how much of $topdir/prebuilts/ is used to compile the NDK. We shouldn't rely on untrusted binaries.
167 4 Beuc Beuc
168 1 Beuc Beuc
h3. Other build method
169 4 Beuc Beuc
170 7 Beuc Beuc
Attempt to rebuild r8e with the same build environment, but checkout-ing precise .git revisions from ndk.git and development.git:
171 4 Beuc Beuc
less patches + local LLVM repo + precise control over the ndk scripts revision
172
173
According to @ndk/docs/DEVELOPMENT.html@ one only needs:
174 9 Beuc Beuc
  git clone https://git.androidproject.xxx/platform/ndk.git ndk
175
  git clone https://git.androidproject.xxx/platform/development.git development
176 4 Beuc Beuc
177 7 Beuc Beuc
This means we wouldn't rely on exactly the build scripts shipped in Replicant 4.2.
178 6 Beuc Beuc
179
h4. Yet another build method
180
181
@ndk/docs/DEVELOPMENT.html@ references using an existing (trusted) NDK to build the next one.