Project

General

Profile

NDKBuild » History » Version 12

Beuc Beuc, 07/25/2015 12:37 PM
Move LXC environment to a separate page.

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
apt-get install git gnupg flex bison gperf \
29
  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
57
# Avoid prompts
58
git config --global user.email "you@example.com"
59
git config --global user.name "Your Name"
60
git config --global color.ui true
61
62
mkdir replicant-4.2/
63
cd replicant-4.2/
64
../tools/repo init -u git://git.replicant.us/manifest.git -b replicant-4.2
65
../tools/repo sync -j4 
66
# > 1h, 27GB (inc. 17GB .repo)
67
</pre>
68
69
h2. Determining the checkout date
70
71 7 Beuc Beuc
Since there's no NDK release tag for the @toolchain/@ Git checkouts, we need to find the right date.
72 2 Beuc Beuc
73
@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).
74
Checking @build/tools/toolchain-patches/@ in the NDKs shows r8c has matching patches.
75
76
Also NDKs from google contain several @SOURCES@ files listing Git repos and commit IDs.
77 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.
78 2 Beuc Beuc
Only, r8c references a LLVM Git repo, while our scripts download a tarball.
79
So our scripts match a NDK version between r8b and r8c, and can almost exactly reproduce r8c. Let's call it r8b2.
80
81
h2. Building the SDK
82
83
Based on @ndk/docs/DEVELOPMENT.html@, with much improvement :)
84
85
<pre>
86
export NDK=~/replicant-4.2/ndk
87
cd $NDK
88
89
# Allow checking build errors
90
export NDK_LOGFILE=$HOME/ndk.log
91
92
# Follow Python download redirection
93
sed -i -e 's/curl -S/curl -L -S/' build/tools/download-toolchain-sources.sh
94
95
# Get the sources from toolchain/ repos, with r8c release date:
96 10 Beuc Beuc
bash $NDK/build/tools/download-toolchain-sources.sh --git-date='2012-10-22T05:59:40Z' ~/ndk-dl
97 2 Beuc Beuc
# ndk-dl: 2.5GB
98
99
# Define NDK_TMPDIR and and use --incremental so the build can be resumed on error
100
export NDK_TMPDIR=~/ndk-tmp
101
mkdir -p $NDK_TMPDIR/release-r8b2/
102
103
# Build the release
104
bash $NDK/build/tools/make-release.sh --toolchain-src-dir=$HOME/ndk-dl --release=r8b2 --incremental
105
# 30mn with 4 cores, 28GB (inc. 17GB .repo), 2.5GB ndk-dl, 1GB /tmp
106
</pre>
107
108
The GNU/Linux NDK release is in @/tmp/ndk-replicant/release/android-ndk-r8b2-linux-x86.tar.bz2@ :)
109 4 Beuc Beuc
110
111
h2. TODOs
112 1 Beuc Beuc
113 7 Beuc Beuc
h3. Mirror @toolchain/@ repos
114
115
@download-toolchain-sources.sh@'s default is @--git-base=https://android.googlesource.com/toolchain@.
116
Should we use a git.replicant.us repo? (note: there's no 'toolchain' there yet)
117
118 4 Beuc Beuc
h3. Windows build
119
120
Build deps:
121
<pre>
122
# windows build is triggered by the presence of mingw32
123
apt-get install mingw32 tofrodos
124
# and requires running maketab.exe
125
apt-get install wine
126
# I had troubles in LXC registering direct .exe execution:
127
# $ /tmp/ndk-replicant/tmp/build-3038/maketab.exe 
128
# run-detectors: unable to find an interpreter for /tmp/ndk-replicant/tmp/build-3038/maketab.exe
129
# Work-around:
130
update-binfmts --disable
131
dpkg-reconfigure wine1.4 --pri=high
132
</pre>
133
134
Code fixes:
135
<pre>
136
# build-ndk-stack/elff/ produces a warning with mingw32, and uses -Werror
137
# cf. https://android.googlesource.com/platform/ndk/+/32e74f3f1b969ff65f037e1ee89e21a5cbc0ecf0
138
sed -i -e 's/-Werror//' sources/host-tools/ndk-stack/GNUMakefile
139
# TODO: maybe 'export EXTRA_CFLAGS=-Wall' would be enough?
140
# TODO: does this mean google was rebuilding from Ubuntu 10.04 instead of 12.04?
141
</pre>
142
143
...
144
145
<pre>
146
bash $NDK/build/tools/make-release.sh --toolchain-src-dir=$HOME/ndk-dl --release=r8b2 --incremental
147
# /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
148
# => let's disable the windows build for now.. maybe better with 10.04? or a later ndk.git revision?
149
</pre>
150
151 6 Beuc Beuc
h3. Use of prebuilts
152
153
Check how much of $topdir/prebuilts/ is used to compile the NDK. We shouldn't rely on untrusted binaries.
154 4 Beuc Beuc
155 1 Beuc Beuc
h3. Other build method
156 4 Beuc Beuc
157 7 Beuc Beuc
Attempt to rebuild r8e with the same build environment, but checkout-ing precise .git revisions from ndk.git and development.git:
158 4 Beuc Beuc
less patches + local LLVM repo + precise control over the ndk scripts revision
159
160
According to @ndk/docs/DEVELOPMENT.html@ one only needs:
161 9 Beuc Beuc
  git clone https://git.androidproject.xxx/platform/ndk.git ndk
162
  git clone https://git.androidproject.xxx/platform/development.git development
163 4 Beuc Beuc
164 7 Beuc Beuc
This means we wouldn't rely on exactly the build scripts shipped in Replicant 4.2.
165 6 Beuc Beuc
166
h4. Yet another build method
167
168
@ndk/docs/DEVELOPMENT.html@ references using an existing (trusted) NDK to build the next one.