1# Fluoride Bluetooth stack 2 3## Building and running on AOSP 4Just build AOSP - Fluoride is there by default. 5 6## Building and running on Linux 7 8Instructions for a Debian based distribution: 9* Debian Bullseye or newer 10* Ubuntu 20.10 or newer 11* Clang-11 or Clang-12 12* Flex 2.6.x 13* Bison 3.x.x (tested with 3.0.x, 3.2.x and 3.7.x) 14 15You'll want to download some pre-requisite packages as well. If you're currently 16configured for AOSP development, you should have most required packages. 17Otherwise, you can use the following apt-get list or use the `--run-bootstrap` 18option on `build.py` (see below) to get a list of packages missing on your 19system: 20 21```sh 22sudo apt-get install repo git-core gnupg flex bison gperf build-essential \ 23 zip curl zlib1g-dev gcc-multilib g++-multilib \ 24 x11proto-core-dev libx11-dev libncurses5 \ 25 libgl1-mesa-dev libxml2-utils xsltproc unzip liblz4-tool libssl-dev \ 26 libc++-dev libevent-dev \ 27 flatbuffers-compiler libflatbuffers1 openssl \ 28 libflatbuffers-dev libfmt-dev libtinyxml2-dev \ 29 libglib2.0-dev libevent-dev libnss3-dev libdbus-1-dev \ 30 libprotobuf-dev ninja-build generate-ninja protobuf-compiler \ 31 libre2-9 debmake \ 32 llvm libc++abi-dev \ 33 libre2-dev libdouble-conversion-dev \ 34 libgtest-dev libgmock-dev libabsl-dev 35``` 36 37You will also need a recent-ish version of Rust and Cargo. Please follow the 38instructions on [Rustup](https://rustup.rs/) to install a recent version. 39 40### Download source 41 42```sh 43mkdir ~/fluoride 44cd ~/fluoride 45git clone https://android.googlesource.com/platform/packages/modules/Bluetooth 46``` 47 48### Using --run-bootstrap on build.py 49 50`build.py` is the helper script used to build Fluoride for Linux (i.e. Floss). 51It accepts a `--run-bootstrap` option that will set up your build staging 52directory and also make sure you have all required system packages to build 53(should work on Debian and Ubuntu). You will still need to build some unpackaged 54dependencies (like libchrome, modp_b64, googletest, etc). 55 56To use it: 57```sh 58./build.py --run-bootstrap 59``` 60 61This will install your bootstrapped build environment to `~/.floss`. If you want 62to change this, just pass in `--bootstrap-dir` to the script. 63 64### Build dependencies 65 66The following third-party dependencies are necessary but currently unavailable 67via a package manager. You may have to build these from source and install them 68to your local environment. 69 70* libchrome 71* modp_b64 72 73We provide a script to produce debian packages for those components. Please 74see the instructions in build/dpkg/README.txt for more details. 75 76```sh 77cd system/build/dpkg 78mkdir -p outdir/{modp_b64,libchrome} 79 80# Build and install modp_b64 81pushd modp_b64 82./gen-src-pkg.sh $(readlink -f ../outdir/modp_b64) 83popd 84sudo dpkg -i outdir/modp_b64/*.deb 85 86# Build and install libchrome 87pushd libchrome 88./gen-src-pkg.sh $(readlink -f ../outdir/libchrome) 89popd 90sudo dpkg -i outdir/libchrome/*.deb 91``` 92 93### Rust dependencies 94 95**Note**: Handled by `--run-bootstrap` option. 96 97Run the following to install Rust dependencies: 98``` 99cargo install cxxbridge-cmd 100``` 101 102### Stage your build environment 103 104**Note**: Handled by `--run-bootstrap` option. 105 106For host build, we depend on a few other repositories: 107* [Platform2](https://chromium.googlesource.com/chromiumos/platform2/) 108* [Rust crates](https://chromium.googlesource.com/chromiumos/third_party/rust_crates/) 109* [Proto logging](https://android.googlesource.com/platform/frameworks/proto_logging/) 110 111Clone these all somewhere and create your staging environment. 112```sh 113export STAGING_DIR=path/to/your/staging/dir 114mkdir ${STAGING_DIR} 115mkdir -p ${STAGING_DIR}/external 116ln -s $(readlink -f ${PLATFORM2_DIR}/common-mk) ${STAGING_DIR}/common-mk 117ln -s $(readlink -f ${PLATFORM2_DIR}/.gn) ${STAGING_DIR}/.gn 118ln -s $(readlink -f ${RUST_CRATE_DIR}) ${STAGING_DIR}/external/rust 119ln -s $(readlink -f ${PROTO_LOG_DIR}) ${STAGING_DIR}/external/proto_logging 120``` 121 122### Build 123 124We provide a build script to automate building assuming you've staged your build 125environment already as above. At this point, make sure you have all the 126pre-requisites installed (i.e. bootstrap option and other dependencies above) or 127you will see failures. In addition, you may need to set a `--libdir=` if your 128libraries are not stored in `/usr/lib` by default. 129 130 131```sh 132./build.py 133``` 134 135This will build all targets to the output directory at `--bootstrap-dir` (which 136defaults to `~/.floss`). You can also build each stage separately (if you want 137to iterate on something specific): 138 139* prepare - Generate the GN rules 140* tools - Generate host tools 141* rust - Build the rust portion of the build 142* main - Build all the C/C++ code 143* test - Build all targets and run the tests 144* clean - Clean the output directory 145 146You can choose to run only a specific stage by passing an arg via `--target`. 147 148Currently, Rust builds are a separate stage that uses Cargo to build. See 149[gd/rust/README.md](gd/rust/README.md) for more information. If you are 150iterating on Rust code and want to add new crates, you may also want to use the 151`--no-vendored-rust` option (which will let you use crates.io instead of using 152a pre-populated vendored crates repo). 153 154### Run 155 156By default on Linux, we statically link libbluetooth so you can just run the 157binary directly. By default, it will try to run on hci0 but you can pass it 158--hci=N, where N corresponds to /sys/class/bluetooth/hciN. 159 160```sh 161$OUTPUT_DIR/debug/btadapterd --hci=$HCI INIT_gd_hci=true 162``` 163