Skip to content

Commit

Permalink
feat: add article about building acceleration (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
shamilsan authored Nov 20, 2023
1 parent 1fcfc64 commit 8590f99
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
book
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Gear projects navigator for Rust developers.

👉 https://gear.rs
⚙️🦀 https://gear.rs

## Build Locally

Expand Down
4 changes: 4 additions & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Summary

[Introduction](introduction.md)

# Tips and Tricks

- [Accelerate the node building](accelerate-build.md)
83 changes: 83 additions & 0 deletions src/accelerate-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Accelerate the Gear node building

## Using `sccache`

Using `sccache` configured with AWS S3 allows decreasing build time.

## Install `sccache`

macOS:

```bash
brew install sccache
```

## Add S3 config

We consider we have already configured AWS S3 storage with the following settings:

- Region: `us-west-1`
- Bucket: `gear-sccache`
- Access key ID: *<AWS_KEY_ID>*
- Secret access key: *<AWS_SECRET_KEY>*

We will use environment variables added to the profile file. For example, if using `zsh`, we need to add the following to the `~/.zshrc`:

```bash
export SCCACHE_BUCKET=gear-sccache
export SCCACHE_REGION=us-west-1
export SCCACHE_S3_KEY_PREFIX=gear
export AWS_ACCESS_KEY_ID=<AWS_KEY_ID>
export AWS_SECRET_ACCESS_KEY="<AWS_SECRET_KEY>"
```

Run to apply these settings immediately:

```bash
source ~/.zshrc
```

## Build Gear node using `sccache`

We need to set the `RUSTC_WRAPPER` environment variable to `sccache`. Also, we need to set `CARGO_INCREMENTAL` to `0` as `sccache` doesn't work well when using incremental building. We can set these environment variables by prepending the `cargo` command in the shell:

```bash
cd gear

# Debug build:
RUSTC_WRAPPER=sccache CARGO_INCREMENTAL=0 cargo b

# Release build:
RUSTC_WRAPPER=sccache CARGO_INCREMENTAL=0 cargo b -r
```

## Using `mold/sold`

`mold` is the linker that uses multiple CPU cores when linking.

## Install `mold/sold`

### macOS

As `mold` doesn't support macOS we need to build `sold` manually.

```bash
git clone https://github.com/bluewhalesystems/sold.git
mkdir sold/build
cd sold/build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=c++ ..
cmake --build . -j $(sysctl -n hw.ncpu)
sudo cmake --build . --target install
```

## Configure `cargo` to use `mold/sold`

To use `mold/sold` with Rust, create (or update) `.cargo/config.toml` at your home directory with the following:

```toml
# macOS on M-series:
[target.aarch64-apple-darwin]
rustflags = ["-C", "link-arg=--ld-path=/usr/local/bin/ld64.sold"]
```

Then just run `cargo b [-r]` as usually.
Binary file added theme/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8590f99

Please sign in to comment.