Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 1 | --- |
| 2 | layout: documentation |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 3 | title: Compiling Bazel from source |
daroberts | 223aebd | 2021-02-18 17:53:30 -0800 | [diff] [blame] | 4 | category: getting-started |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 5 | --- |
| 6 | |
Googler | de98177 | 2021-01-08 18:41:01 -0800 | [diff] [blame] | 7 | <h1 id="compiling-from-source">Compiling Bazel from Source</h1> |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 8 | |
Googler | 10eddc3 | 2020-12-21 18:46:12 -0800 | [diff] [blame] | 9 | This page describes how to install Bazel from source and provides |
| 10 | troubleshooting tips for common issues. |
| 11 | |
laszlocsomor | 810d236 | 2018-09-17 09:35:09 -0700 | [diff] [blame] | 12 | To build Bazel from source, you can do one of the following: |
| 13 | |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 14 | * Build it [using an existing Bazel binary](#build-bazel-using-bazel) |
laszlocsomor | 810d236 | 2018-09-17 09:35:09 -0700 | [diff] [blame] | 15 | |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 16 | * Build it [without an existing Bazel binary](#bootstrap-bazel) which is known |
Zackary Lowery | 8118389 | 2019-10-30 08:14:39 -0700 | [diff] [blame] | 17 | as _bootstrapping_. |
laszlocsomor | 810d236 | 2018-09-17 09:35:09 -0700 | [diff] [blame] | 18 | |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 19 | <h2 id="build-bazel-using-bazel">Build Bazel using Bazel</h2> |
steren | 30c35a2 | 2017-06-30 15:49:47 +0200 | [diff] [blame] | 20 | |
Googler | 7732c4c | 2021-01-15 17:13:49 -0800 | [diff] [blame] | 21 | <h3 id="summary">Summary</h3> |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 22 | |
Jingwen Chen | 7c15c03 | 2020-01-16 11:54:44 -0800 | [diff] [blame] | 23 | 1. Get the latest Bazel release from the |
| 24 | [GitHub release page](https://github.com/bazelbuild/bazel/releases) or with |
| 25 | [Bazelisk](https://github.com/bazelbuild/bazelisk). |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 26 | |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 27 | 2. [Download Bazel's sources from GitHub](https://github.com/bazelbuild/bazel/archive/master.zip) |
| 28 | and extract somewhere. |
| 29 | Alternatively you can git clone the source tree from https://github.com/bazelbuild/bazel |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 30 | |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 31 | 3. Install the same prerequisites as for bootstrapping (see |
| 32 | [for Unix-like systems](#bootstrap-unix-prereq) or |
| 33 | [for Windows](#bootstrap-windows-prereq)) |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 34 | |
Jingwen Chen | 7c15c03 | 2020-01-16 11:54:44 -0800 | [diff] [blame] | 35 | 4. Build a development build of Bazel using Bazel: |
| 36 | `bazel build //src:bazel-dev` (or `bazel build //src:bazel-dev.exe` on |
| 37 | Windows) |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 38 | |
Jingwen Chen | 7c15c03 | 2020-01-16 11:54:44 -0800 | [diff] [blame] | 39 | 5. The resulting binary is at `bazel-bin/src/bazel-dev` |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 40 | (or `bazel-bin\src\bazel-dev.exe` on Windows). You can copy it wherever you |
| 41 | like and use immediately without further installation. |
| 42 | |
| 43 | Detailed instructions follow below. |
| 44 | |
Greg Estren | d2b063e | 2020-02-20 12:33:22 -0800 | [diff] [blame] | 45 | <h3 id="build-bazel-install-bazel">Step 1: Get the latest Bazel release</h3> |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 46 | |
| 47 | **Goal**: Install or download a release version of Bazel. Make sure you can run |
| 48 | it by typing `bazel` in a terminal. |
| 49 | |
| 50 | **Reason**: To build Bazel from a GitHub source tree, you need a pre-existing |
| 51 | Bazel binary. You can install one from a package manager or download one from |
| 52 | GitHub. See <a href="install.html">Installing Bazel</a>. (Or you can [build from |
| 53 | scratch (bootstrap)](#bootstrap-bazel).) |
| 54 | |
| 55 | **Troubleshooting**: |
| 56 | |
| 57 | * If you cannot run Bazel by typing `bazel` in a terminal: |
| 58 | |
| 59 | * Maybe your Bazel binary's directory is not on the PATH. |
| 60 | |
| 61 | This is not a big problem. Instead of typing `bazel`, you will need to |
| 62 | type the full path. |
| 63 | |
| 64 | * Maybe the Bazel binary itself is not called `bazel` (on Unixes) or |
| 65 | `bazel.exe` (on Windows). |
| 66 | |
| 67 | This is not a big problem. You can either rename the binary, or type the |
| 68 | binary's name instead of `bazel`. |
| 69 | |
| 70 | * Maybe the binary is not executable (on Unixes). |
| 71 | |
| 72 | You must make the binary executable by running `chmod +x /path/to/bazel`. |
| 73 | |
Greg Estren | d2b063e | 2020-02-20 12:33:22 -0800 | [diff] [blame] | 74 | <h3 id="build-bazel-git">Step 2: Download Bazel's sources from GitHub</h3> |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 75 | |
| 76 | If you are familiar with Git, then just git clone https://github.com/bazelbuild/bazel |
| 77 | |
| 78 | Otherwise: |
| 79 | |
| 80 | 1. Download the |
| 81 | [latest sources as a zip file](https://github.com/bazelbuild/bazel/archive/master.zip). |
| 82 | |
| 83 | 2. Extract the contents somewhere. |
| 84 | |
| 85 | For example create a `bazel-src` directory under your home directory and |
| 86 | extract there. |
| 87 | |
Greg Estren | d2b063e | 2020-02-20 12:33:22 -0800 | [diff] [blame] | 88 | <h3 id="build-bazel-prerequisites">Step 3: Install prerequisites</h3> |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 89 | |
| 90 | Install the same prerequisites as for bootstrapping (see below) -- JDK, C++ |
| 91 | compiler, MSYS2 (if you are building on Windows), etc. |
| 92 | |
Greg Estren | d2b063e | 2020-02-20 12:33:22 -0800 | [diff] [blame] | 93 | <h3 id="build-bazel-on-unixes">Step 4: Build Bazel</h3> |
| 94 | |
| 95 | <h4 id="build-bazel-on-unixes">Ubuntu Linux, macOS, and other Unix-like systems</h4> |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 96 | |
| 97 | ([Scroll down](#build-bazel-on-windows) for instructions for Windows.) |
| 98 | |
Jingwen Chen | 7c15c03 | 2020-01-16 11:54:44 -0800 | [diff] [blame] | 99 | **Goal**: Run Bazel to build a custom Bazel binary (`bazel-bin/src/bazel-dev`). |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 100 | |
| 101 | **Instructions**: |
| 102 | |
| 103 | 1. Start a Bash terminal |
| 104 | |
| 105 | 2. `cd` into the directory where you extracted (or cloned) Bazel's sources. |
| 106 | |
| 107 | For example if you extracted the sources under your home directory, run: |
| 108 | |
| 109 | cd ~/bazel-src |
| 110 | |
| 111 | 3. Build Bazel from source: |
| 112 | |
Jingwen Chen | 7c15c03 | 2020-01-16 11:54:44 -0800 | [diff] [blame] | 113 | bazel build //src:bazel-dev |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 114 | |
Jingwen Chen | 7c15c03 | 2020-01-16 11:54:44 -0800 | [diff] [blame] | 115 | Alternatively you can run `bazel build //src:bazel --compilation_mode=opt` |
| 116 | to yield a smaller binary but it's slower to build. |
| 117 | |
| 118 | 4. The output will be at `bazel-bin/src/bazel-dev` (or `bazel-bin/src/bazel`). |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 119 | |
Greg Estren | d2b063e | 2020-02-20 12:33:22 -0800 | [diff] [blame] | 120 | <h4 id="build-bazel-on-windows">Windows</h4> |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 121 | |
| 122 | ([Scroll up](#build-bazel-on-unixes) for instructions for Linux, macOS, and other |
| 123 | Unix-like systems.) |
| 124 | |
| 125 | **Goal**: Run Bazel to build a custom Bazel binary |
| 126 | (`bazel-bin\src\bazel-dev.exe`). |
| 127 | |
| 128 | **Instructions**: |
| 129 | |
| 130 | 1. Start Command Prompt (Start Menu > Run > "cmd.exe") |
| 131 | |
| 132 | 2. `cd` into the directory where you extracted (or cloned) Bazel's sources. |
| 133 | |
| 134 | For example if you extracted the sources under your home directory, run: |
| 135 | |
| 136 | cd %USERPROFILE%\bazel-src |
| 137 | |
| 138 | 3. Build Bazel from source: |
| 139 | |
| 140 | bazel build //src:bazel-dev.exe |
| 141 | |
Jingwen Chen | 7c15c03 | 2020-01-16 11:54:44 -0800 | [diff] [blame] | 142 | Alternatively you can run `bazel build //src:bazel.exe |
| 143 | --compilation_mode=opt` to yield a smaller binary but it's slower to build. |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 144 | |
Jingwen Chen | 7c15c03 | 2020-01-16 11:54:44 -0800 | [diff] [blame] | 145 | 4. The output will be at `bazel-bin\src\bazel-dev.exe` (or |
| 146 | `bazel-bin\src\bazel.exe`). |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 147 | |
Greg Estren | d2b063e | 2020-02-20 12:33:22 -0800 | [diff] [blame] | 148 | <h3 id="build-bazel-install">Step 5: Install the built binary</h3> |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 149 | |
| 150 | Actually, there's nothing to install. |
| 151 | |
| 152 | The output of the previous step is a self-contained Bazel binary. You can copy |
| 153 | it to any directory and use immediately. (It's useful if that directory is on |
| 154 | your PATH so that you can run "bazel" everywhere.) |
| 155 | |
| 156 | --- |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 157 | |
| 158 | <h2 id="bootstrap-bazel">Build Bazel from scratch (bootstrapping)</h2> |
| 159 | |
| 160 | You can also build Bazel from scratch, without using an existing Bazel binary. |
| 161 | |
Greg Estren | d2b063e | 2020-02-20 12:33:22 -0800 | [diff] [blame] | 162 | <h3 id="download-distfile">Step 1: Download Bazel's sources (distribution archive)</h3> |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 163 | |
| 164 | (This step is the same for all platforms.) |
| 165 | |
| 166 | 1. Download `bazel-<version>-dist.zip` from |
| 167 | [GitHub](https://github.com/bazelbuild/bazel/releases), for example |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 168 | `bazel-0.28.1-dist.zip`. |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 169 | |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 170 | **Attention**: |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 171 | |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 172 | - There is a **single, architecture-independent** distribution archive. |
| 173 | There are no architecture-specific or OS-specific distribution archives. |
| 174 | - These sources are **not the same as the GitHub source tree**. You |
| 175 | have to use the distribution archive to bootstrap Bazel. You cannot |
| 176 | use a source tree cloned from GitHub. (The distribution archive contains |
| 177 | generated source files that are required for bootstrapping and are not part |
| 178 | of the normal Git source tree.) |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 179 | |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 180 | 2. Unpack the distribution archive somewhere on disk. |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 181 | |
Googler | 480d83e | 2021-02-26 17:24:10 -0800 | [diff] [blame] | 182 | You should verify the signature made by Bazel's |
Klaus Aehlig | 552cf56 | 2019-10-11 04:20:41 -0700 | [diff] [blame] | 183 | [release key](https://bazel.build/bazel-release.pub.gpg) 3D5919B448457EE0. |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 184 | |
Greg Estren | d2b063e | 2020-02-20 12:33:22 -0800 | [diff] [blame] | 185 | <h3 id="bootstrap-unix">Step 2a: Bootstrap Bazel on Ubuntu Linux, macOS, and other Unix-like systems</h3> |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 186 | |
| 187 | ([Scroll down](#bootstrap-windows) for instructions for Windows.) |
| 188 | |
| 189 | <h4 id="bootstrap-unix-prereq">2.1. Install the prerequisites</h4> |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 190 | |
Laszlo Csomor | 4691ad9 | 2018-05-14 01:58:00 -0700 | [diff] [blame] | 191 | * **Bash** |
| 192 | |
| 193 | * **zip, unzip** |
| 194 | |
| 195 | * **C++ build toolchain** |
| 196 | |
wyv | a9de41c | 2020-05-11 07:23:47 -0700 | [diff] [blame] | 197 | * **JDK.** Versions 8 and 11 are supported. |
Laszlo Csomor | 4691ad9 | 2018-05-14 01:58:00 -0700 | [diff] [blame] | 198 | |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 199 | * **Python**. Versions 2 and 3 are supported, installing one of them is |
| 200 | enough. |
Laszlo Csomor | 4691ad9 | 2018-05-14 01:58:00 -0700 | [diff] [blame] | 201 | |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 202 | For example on Ubuntu Linux you can install these requirements using the |
| 203 | following command: |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 204 | |
Serge | 70e84f8 | 2018-04-18 10:04:22 -0700 | [diff] [blame] | 205 | ```sh |
wyv | a9de41c | 2020-05-11 07:23:47 -0700 | [diff] [blame] | 206 | sudo apt-get install build-essential openjdk-11-jdk python zip unzip |
Serge | 70e84f8 | 2018-04-18 10:04:22 -0700 | [diff] [blame] | 207 | ``` |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 208 | |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 209 | <h4 id="bootstrap-unix-bootstrap">2.2. Bootstrap Bazel</h4> |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 210 | |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 211 | 1. Open a shell or Terminal window. |
| 212 | |
| 213 | 3. `cd` to the directory where you unpacked the distribution archive. |
| 214 | |
Klaus Aehlig | 004bcb4 | 2019-01-24 03:53:32 -0800 | [diff] [blame] | 215 | 3. Run the compilation script: `env EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk" bash ./compile.sh`. |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 216 | |
| 217 | The compiled output is placed into `output/bazel`. This is a self-contained |
| 218 | Bazel binary, without an embedded JDK. You can copy it anywhere or use it |
Googler | 480d83e | 2021-02-26 17:24:10 -0800 | [diff] [blame] | 219 | in-place. For convenience, copy this binary to a directory that's on your |
| 220 | `PATH` (such as `/usr/local/bin` on Linux). |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 221 | |
Klaus Aehlig | fc996af | 2019-02-19 07:21:28 -0800 | [diff] [blame] | 222 | To build the `bazel` binary in a reproducible way, also set |
| 223 | [`SOURCE_DATE_EPOCH`](https://reproducible-builds.org/specs/source-date-epoch/) |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 224 | in the "Run the compilation script" step. |
Klaus Aehlig | fc996af | 2019-02-19 07:21:28 -0800 | [diff] [blame] | 225 | |
Greg Estren | d2b063e | 2020-02-20 12:33:22 -0800 | [diff] [blame] | 226 | <h3 id="bootstrap-windows">Step 2b: Bootstrap Bazel on Windows</h3> |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 227 | |
| 228 | ([Scroll up](#bootstrap-unix) for instructions for Linux, macOS, and other |
| 229 | Unix-like systems.) |
| 230 | |
| 231 | <h4 id="bootstrap-windows-prereq">2.1. Install the prerequisites</h4> |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 232 | |
| 233 | * [MSYS2 shell](https://msys2.github.io/) |
| 234 | |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 235 | * **The MSYS2 packages for zip and unzip.** Run the following command in the MSYS2 shell: |
Laszlo Csomor | ab2431e | 2018-05-29 05:15:42 -0700 | [diff] [blame] | 236 | |
| 237 | ``` |
laszlocsomor | f6696b8 | 2019-04-29 01:02:51 -0700 | [diff] [blame] | 238 | pacman -S zip unzip patch |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 239 | ``` |
| 240 | |
| 241 | * **The Visual C++ compiler.** Install the Visual C++ compiler either as part |
| 242 | of Visual Studio 2015 or newer, or by installing the latest [Build Tools |
| 243 | for Visual Studio 2017](https://aka.ms/BuildTools). |
| 244 | |
| 245 | * **JDK 8.** You must install version 8 of the JDK. Versions other than 8 are |
| 246 | *not* supported. |
| 247 | |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 248 | * **Python**. Versions 2 and 3 are supported, installing one of them is |
| 249 | enough. You need the Windows-native version (downloadable from |
| 250 | [https://www.python.org](https://www.python.org)). Versions installed via |
| 251 | pacman in MSYS2 will not work. |
Googler | 1fbef39 | 2017-03-22 09:05:09 +0000 | [diff] [blame] | 252 | |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 253 | <h4 id="bootstrap-windows-bootstrap">2.2. Bootstrap Bazel</h4> |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 254 | |
| 255 | 1. Open the MSYS2 shell. |
| 256 | |
| 257 | 2. Set the following environment variables: |
Laszlo Csomor | a7e0c75 | 2018-06-10 23:24:26 -0700 | [diff] [blame] | 258 | * Either `BAZEL_VS` or `BAZEL_VC` (they are *not* the same): Set to the |
| 259 | path to the Visual Studio directory (BAZEL\_V<b>S</b>) or to the Visual |
| 260 | C++ directory (BAZEL\_V<b>C</b>). Setting one of them is enough. |
Laszlo Csomor | 7574865 | 2018-07-26 07:38:14 -0700 | [diff] [blame] | 261 | * `BAZEL_SH`: Path of the MSYS2 `bash.exe`. See the command in the |
| 262 | examples below. |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 263 | |
| 264 | Do not set this to `C:\Windows\System32\bash.exe`. (You have that file |
| 265 | if you installed Windows Subsystem for Linux.) Bazel does not support |
| 266 | this version of `bash.exe`. |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 267 | * `PATH`: Add the Python directory. |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 268 | * `JAVA_HOME`: Set to the JDK directory. |
| 269 | |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 270 | **Example** (using BAZEL\_V<b>S</b>): |
Laszlo Csomor | 4691ad9 | 2018-05-14 01:58:00 -0700 | [diff] [blame] | 271 | |
| 272 | export BAZEL_VS="C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools" |
Laszlo Csomor | 7574865 | 2018-07-26 07:38:14 -0700 | [diff] [blame] | 273 | export BAZEL_SH="$(cygpath -m $(realpath $(which bash)))" |
Laszlo Csomor | 4691ad9 | 2018-05-14 01:58:00 -0700 | [diff] [blame] | 274 | export PATH="/c/python27:$PATH" |
| 275 | export JAVA_HOME="C:/Program Files/Java/jdk1.8.0_112" |
| 276 | |
Laszlo Csomor | a7e0c75 | 2018-06-10 23:24:26 -0700 | [diff] [blame] | 277 | or (using BAZEL\_V<b>C</b>): |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 278 | |
Laszlo Csomor | 4691ad9 | 2018-05-14 01:58:00 -0700 | [diff] [blame] | 279 | export BAZEL_VC="C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC" |
Laszlo Csomor | 7574865 | 2018-07-26 07:38:14 -0700 | [diff] [blame] | 280 | export BAZEL_SH="$(cygpath -m $(realpath $(which bash)))" |
Laszlo Csomor | 4691ad9 | 2018-05-14 01:58:00 -0700 | [diff] [blame] | 281 | export PATH="/c/python27:$PATH" |
| 282 | export JAVA_HOME="C:/Program Files/Java/jdk1.8.0_112" |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 283 | |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 284 | 3. `cd` to the directory where you unpacked the distribution archive. |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 285 | |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 286 | 4. Run the compilation script: `env EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk" ./compile.sh` |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 287 | |
| 288 | The compiled output is placed into `output/bazel.exe`. This is a self-contained |
Laszlo Csomor | ebb902e | 2018-10-22 00:56:43 -0700 | [diff] [blame] | 289 | Bazel binary, without an embedded JDK. You can copy it anywhere or use it |
Googler | 480d83e | 2021-02-26 17:24:10 -0800 | [diff] [blame] | 290 | in-place. For convenience, copy this binary to a directory that's on |
| 291 | your `PATH`. |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 292 | |
Laszlo Csomor | 7d47987 | 2019-08-16 07:00:04 -0700 | [diff] [blame] | 293 | To build the `bazel.exe` binary in a reproducible way, also set |
| 294 | [`SOURCE_DATE_EPOCH`](https://reproducible-builds.org/specs/source-date-epoch/) |
| 295 | in the "Run the compilation script" step. |
| 296 | |
Laszlo Csomor | 6532ecc | 2018-05-04 01:21:54 -0700 | [diff] [blame] | 297 | You don't need to run Bazel from the MSYS2 shell. You can run Bazel from the |
| 298 | Command Prompt (`cmd.exe`) or PowerShell. |