|
| 1 | +# Compiling from source |
| 2 | + |
| 3 | +Penumbra is written in Rust. To build it, you will need a recent |
| 4 | +stable version of Rust, as well as a few OS-level dependencies. |
| 5 | +We don't support building on Windows. If you need to use Windows, |
| 6 | +consider using [WSL] instead. |
| 7 | + |
| 8 | +### Installing the Rust toolchain |
| 9 | + |
| 10 | +This requires that you install a recent (>= 1.75) stable version |
| 11 | +of the Rust compiler, installation instructions for which you can find |
| 12 | +[here](https://www.rust-lang.org/learn/get-started). Don't forget to reload your shell so that |
| 13 | +`cargo` is available in your `$PATH`! |
| 14 | + |
| 15 | +You can verify the rust compiler version by running `rustc --version` which should indicate version 1.75 or later. |
| 16 | +The project uses a `rust-toolchain.toml` file, which will ensure that your version of rust stays current enough |
| 17 | +to build the project from source. |
| 18 | + |
| 19 | +### Installing build prerequisites |
| 20 | + |
| 21 | +#### Linux |
| 22 | + |
| 23 | +You may need to install some additional packages in order to build `pcli`, |
| 24 | +depending on your distribution. For a bare-bones Ubuntu installation, you can |
| 25 | +run: |
| 26 | + |
| 27 | +```bash |
| 28 | +sudo apt-get install build-essential pkg-config libssl-dev clang git-lfs |
| 29 | +``` |
| 30 | + |
| 31 | +For a minimal Fedora/CentOS/RHEL image, you can run: |
| 32 | + |
| 33 | +```bash |
| 34 | +sudo dnf install openssl-devel clang git cargo rustfmt git-lfs |
| 35 | +``` |
| 36 | + |
| 37 | +#### macOS |
| 38 | + |
| 39 | +You may need to install the command-line developer tools if you have never done |
| 40 | +so: |
| 41 | +```bash |
| 42 | +xcode-select --install |
| 43 | +``` |
| 44 | + |
| 45 | +You'll also need to install Git LFS, which you can do [via Homebrew](https://docs.github.com/en/repositories/working-with-files/managing-large-files/installing-git-large-file-storage?platform=mac): |
| 46 | + |
| 47 | +```bash |
| 48 | +brew install git-lfs |
| 49 | +``` |
| 50 | + |
| 51 | +### Making sure that `git-lfs` is installed |
| 52 | + |
| 53 | +Running `git lfs install` will make sure that git-lfs is correctly installed on your machine. |
| 54 | + |
| 55 | +### Cloning the repository |
| 56 | + |
| 57 | +Once you have installed the above packages, you can clone the repository: |
| 58 | + |
| 59 | +```bash |
| 60 | +git clone https://github.com/penumbra-zone/penumbra |
| 61 | +``` |
| 62 | + |
| 63 | +To build the versions of `pcli`, `pd`, etc. compatible with the current testnet, |
| 64 | +navigate to the `penumbra/` folder, fetch the latest from the repository, and check out the |
| 65 | +latest tag for the current |
| 66 | +[testnet](https://github.com/penumbra-zone/penumbra/releases): |
| 67 | + |
| 68 | +```bash |
| 69 | +cd penumbra && git fetch && git checkout {{ #include ../penumbra_version.md }} |
| 70 | +``` |
| 71 | + |
| 72 | +If you want to build the most recent version compatible with the "preview" environment, |
| 73 | +then run `git checkout main` instead. |
| 74 | + |
| 75 | +### Building the binaries |
| 76 | + |
| 77 | +Then, build all the project binaries using `cargo`: |
| 78 | + |
| 79 | +```bash |
| 80 | +cargo build --release |
| 81 | +``` |
| 82 | + |
| 83 | +### Linking Against RocksDB (Optional) |
| 84 | + |
| 85 | +Development builds can avoid the cost of recompiling RocksDB for storage libraries in the Cargo |
| 86 | +workspace. This manifests as a `librocksdb-sys(build)` message when building or testing crates |
| 87 | +in the monorepo. |
| 88 | + |
| 89 | +#### Building `librocksdb.a` from source |
| 90 | + |
| 91 | +First, clone the rocksdb repository: |
| 92 | + |
| 93 | +```sh |
| 94 | +# Clone the repository, and enter that directory. |
| 95 | +git clone [email protected]:facebook/rocksdb.git && cd rocksdb |
| 96 | + |
| 97 | +# Checkout the version of rocksdb used in `librocksdb-sys`. |
| 98 | +git checkout 6a43615 |
| 99 | + |
| 100 | +# Add an environment variable pointing to this repository: |
| 101 | +ROCKSDB_LIB_DIR=`pwd` |
| 102 | + |
| 103 | +# Compile the static `librocksdb.a` library to link against: |
| 104 | +make static_lib |
| 105 | +``` |
| 106 | + |
| 107 | +#### Building `libsnappy.a` from source |
| 108 | + |
| 109 | +next, clone the snappy repository and follow the |
| 110 | +[instructions][snappy-build] to build it: |
| 111 | + |
| 112 | +``` |
| 113 | +# Clone the repository, and enter that directory. |
| 114 | +git clone [email protected]:google/snappy.git && cd snappy |
| 115 | +
|
| 116 | +# Checkout the version of snappy used in `librocksdb-sys`. |
| 117 | +git checkout 2b63814 |
| 118 | +
|
| 119 | +# Initialize the submodules. |
| 120 | +git submodule update --init |
| 121 | +
|
| 122 | +# Build snappy using cmake. |
| 123 | +mkdir build |
| 124 | +cd build && cmake .. && make |
| 125 | +
|
| 126 | +# Add an environment variable pointing to the build/ directory. |
| 127 | +SNAPPY_LIB_DIR=`pwd` |
| 128 | +``` |
| 129 | + |
| 130 | +### Building Penumbra |
| 131 | + |
| 132 | +Once you've built rocksdb and set the environment variable, the `librocksdb-sys` crate will search |
| 133 | +in that directory for the compiled `librocksdb.a` static library when it is rebuilt. |
| 134 | + |
| 135 | +[snappy-build]: https://github.com/google/snappy?tab=readme-ov-file#building |
| 136 | +[protoc-install]: https://grpc.io/docs/protoc-installation/ |
| 137 | +[WSL]: https://learn.microsoft.com/en-us/windows/wsl/install |
0 commit comments