Skip to content

Commit c754663

Browse files
committed
Add script to automate BoringSSL rebuilds.
"Knows" the correct arguments for each supported architecture and can automate `git pull` etc. Updated BUILDING.md to document it. Also updated the Windows build instructions as they were for a deprecated version of MSVC.
1 parent b7e6501 commit c754663

File tree

2 files changed

+169
-17
lines changed

2 files changed

+169
-17
lines changed

BUILDING.md

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ Conscrypt requires that you have __Java__, __BoringSSL__ and the __Android SDK__
2222
described below.
2323

2424
#### Java
25-
The build uses a version of Gradle which requires a __Java 11__ JRE to run, however to ensure
26-
backward compatibility Conscrypt itself is compiled with a __Java 8__ JDK using Gradle's
27-
recent Java toolchain support. At the least, you will need to install __Java 11__ to run
28-
Gradle, but if you do not also have __Java 8__ then depending on the OS, Gradle will
29-
try and install it automatically.
25+
The build uses a version of Gradle which requires a __Java 11__ JDK.
3026

3127
#### Android SDK
3228
[Download and install](https://developer.android.com/studio/install.html) the latest Android SDK
@@ -62,9 +58,11 @@ cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \
6258
ninja
6359
```
6460

61+
You can also use the `rebuild_boringssl.sh` script (see below) to automate this process.
62+
6563
##### Building on macOS.
6664
When building Conscrypt on macOS it will build libraries for both x86 and ARM, and so BoringSSL
67-
must also be build for each of these.
65+
must also be built for each of these.
6866

6967
To build the x86_64 version:
7068
```bash
@@ -90,22 +88,34 @@ cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE \
9088
ninja
9189
```
9290

91+
You can also use the `rebuild_boringssl.sh` script (see below) to automate this process.
9392

9493
##### Building on Windows
95-
This assumes that you have Microsoft Visual Studio 2017 installed along
96-
with both the Windows 8.1 and 10 SDKs and that your machine is capable of
97-
compiling 64-bit.
94+
This assumes that you have
95+
[Git for Windows](https://gitforwindows.org/) and
96+
[Microsoft Visual Studio 2022](https://visualstudio.microsoft.com/downloads/)
97+
installed.
98+
99+
You'll also need `nasm`, `cmake` and `ninja` which can be usefully
100+
managed via a package tool such as
101+
[Chocolatey](https://chocolatey.org/).
102+
103+
Like Visual Studio 2017, Visual Studio 2022 provides a batch file
104+
to set up the correct environment for the compiler which can be invoked
105+
as follows (assuming a default installation):
106+
```bat
107+
call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
108+
```
98109

99-
Unlike earlier versions, Visual Studio 2017 doesn't appear to set an
100-
environment variable to simplify building from the command line. The
101-
instructions below assume the default installation of the community
102-
edition. To use another edition or a non-standard install path, you'll
103-
need to modify the paths below as appropriate.
110+
However, Visual Studio 2022 also sets up a _Developer Command Prompt_
111+
in Windows Terminal which provides a simpler way of getting the
112+
correct compiler environment, defaulting to 64-bit mode.
104113

105-
To build in 64-bit mode, set up with this command line:
114+
After either method, you can run Git for Windows' `bash` to get a
115+
more UNIX like environment with a working compiler.
106116

117+
To build BoringSSL in 64-bit mode from a Command Prompt:
107118
```bat
108-
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
109119
mkdir build64
110120
cd build64
111121
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ^
@@ -115,7 +125,27 @@ cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ^
115125
ninja
116126
```
117127

118-
32-bit mode is no longer supported.
128+
32-bit mode is no longer supported on Windows.
129+
130+
If running `bash`, you can use the `rebuild_boringssl` script (see below)
131+
to automate this process.
132+
133+
##### rebuild_boringssl.sh script
134+
135+
The script `scripts/rebuild_boringssl.sh` will build or rebuild BoringSSL
136+
with the correct configuration for the current architecture.
137+
138+
When run with no arguments, the script assumes that `BORINGSSL_HOME` is set
139+
correctly and will re-run `cmake` and `ninja` with the correct arguments.
140+
141+
The following arguments can be used to modify its behaviour:
142+
143+
* `--clone` May only be used if `BORINGSSL_HOME` is set but does not
144+
yet exist. Will clone BoringSSL from Github and build it.
145+
146+
* `--clean` Delete the current build directly and rebuild from scratch.
147+
* `--pull` or `--update` Updates the source tree to the latest revision and
148+
then builds. Note will not clean old builds unless `--clean` is also specified.
119149

120150
Coverage
121151
--------

scripts/rebuild_boringssl.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#! /bin/bash
2+
#
3+
# Copyright (C) 2025 The Android Open Source Project
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Rebuilds BoringSSL from scratch for supported architectures,
18+
# optionally performing a `git pull` first to update it.
19+
20+
21+
UPSTREAM="https://github.com/google/boringssl.git"
22+
MAIN="main"
23+
24+
fail() {
25+
echo "*** FAILED: " $@
26+
exit 1
27+
}
28+
29+
usage() {
30+
cat <<EOF
31+
Usage: $0 [OPTIONS]
32+
33+
--clone Clone BoringSSL git repository if not already present
34+
--update Resync from upstream before building
35+
--clean Clean before building
36+
37+
EOF
38+
exit 0
39+
}
40+
41+
test "$BORINGSSL_HOME" || fail "Please set BORINGSSL_HOME."
42+
43+
44+
CLONE=
45+
UPDATE=
46+
CLEAN=
47+
while [ "$1" ]; do
48+
case "$1" in
49+
--clone)
50+
CLONE=true
51+
;;
52+
53+
--update | --pull)
54+
UPDATE=true
55+
;;
56+
57+
--clean | --fresh)
58+
CLEAN=true
59+
;;
60+
61+
*)
62+
usage
63+
95
64+
;;
65+
esac
66+
shift
67+
done
68+
69+
if [ "$CLONE" ]; then
70+
echo "Cloning BoringSSL from ${UPSTREAM}."
71+
72+
test -d "$BORINGSSL_HOME" && fail "$BORINGSSL_HOME already exists"
73+
PARENT="$(dirname $BORINGSSL_HOME)"
74+
cd "$PARENT" || fail "Cannot access parent directory $PARENT"
75+
git clone "$UPSTREAM" "$BORINGSSL_HOME" || fail "Unable to clone BoringSSL"
76+
UPDATE=
77+
CLEAN=true
78+
fi
79+
80+
cd "$BORINGSSL_HOME" || fail "Cannot access $BORINGSSL_HOME"
81+
82+
if [ "$UPDATE" ]; then
83+
echo "Updating BoringSSL."
84+
git checkout "$MAIN"
85+
git pull
86+
fi
87+
88+
run_cmake() {
89+
local BUILD_DIR="${BORINGSSL_HOME}/$1"
90+
local EXTRA_CMAKE_FLAGS="$2"
91+
92+
if [ "$CLEAN" ]; then
93+
echo "Removing $BUILD_DIR"
94+
rm -rf "$BUILD_DIR"
95+
fi
96+
mkdir -p "$BUILD_DIR" || fail "Unable to create $BUILD_DIR"
97+
cd "$BUILD_DIR" || fail "Unable to access $BUILD_DIR"
98+
echo "Running cmake."
99+
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DCMAKE_BUILD_TYPE=Release $EXTRA_CMAKE_FLAGS \
100+
-GNinja .. || fail "cmake failed."
101+
echo "Building BoringSSL in ${BUILD_DIR}."
102+
ninja
103+
}
104+
105+
case "$(uname -s)" in
106+
Darwin)
107+
run_cmake build.x86 "-DCMAKE_ASM_FLAGS=-Wa,--noexecstack -DCMAKE_OSX_ARCHITECTURES=x86_64"
108+
run_cmake build.arm "-DCMAKE_ASM_FLAGS=-Wa,--noexecstack -DCMAKE_OSX_ARCHITECTURES=arm64"
109+
;;
110+
111+
Linux)
112+
run_cmake build64 "-DCMAKE_ASM_FLAGS=-Wa,--noexecstack"
113+
;;
114+
115+
MINGW64*)
116+
run_cmake build64 "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded"
117+
;;
118+
119+
*)
120+
fail "Please follow the manual build instructions."
121+
;;
122+
esac

0 commit comments

Comments
 (0)