Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: custom cargo config to reduce build time #2104

Merged
merged 34 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4a2c4c4
chore: custom cargo config to reduce build time
hanabi1224 Oct 20, 2022
f9d854b
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 20, 2022
89c9597
fix
hanabi1224 Oct 20, 2022
8764554
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 20, 2022
fa520f2
fix: macos build
hanabi1224 Oct 20, 2022
dc6c571
lint-all
hanabi1224 Oct 21, 2022
2e6f40a
sccache-action ver @v1
hanabi1224 Oct 21, 2022
8be9f74
fix: unique cache key for docs
hanabi1224 Oct 21, 2022
fbe2594
pr commit save cache once
hanabi1224 Oct 21, 2022
94f4549
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 21, 2022
d6917de
do not save on PR commit
hanabi1224 Oct 21, 2022
f4e45da
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 21, 2022
46c4531
update sccache-action
hanabi1224 Oct 21, 2022
ec150d1
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 21, 2022
cf7e392
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 21, 2022
03edc72
Merge remote-tracking branch 'origin/main' into cargo-config-speed-up…
hanabi1224 Oct 24, 2022
f3422b0
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 24, 2022
3560657
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 25, 2022
700339b
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 25, 2022
5dbcbd7
reasoning why we use forked sccache-action
hanabi1224 Oct 25, 2022
5a9f755
Merge remote-tracking branch 'origin/main' into cargo-config-speed-up…
hanabi1224 Oct 25, 2022
9b4e017
Merge remote-tracking branch 'origin/main' into cargo-config-speed-up…
hanabi1224 Oct 26, 2022
07caf38
move avx2 config to .cargo/config.toml
hanabi1224 Oct 26, 2022
1572a28
fix lint errors
hanabi1224 Oct 26, 2022
5a1289d
strip cargo bins
hanabi1224 Oct 27, 2022
13ffc7a
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 27, 2022
accfc35
deps
hanabi1224 Oct 27, 2022
2742a4b
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 27, 2022
9d3a5a5
Merge remote-tracking branch 'origin/main' into cargo-config-speed-up…
hanabi1224 Oct 27, 2022
aac9852
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 28, 2022
9f5c97a
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 28, 2022
a32913c
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 31, 2022
40e7713
fix rate limited error
hanabi1224 Oct 31, 2022
f525219
Merge branch 'main' into cargo-config-speed-up-build
hanabi1224 Oct 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[alias]
b = "build"
c = "check"
d = "doc"
t = "test"
r = "run"

[build]
incremental = true
# might be helpful but we don't enforce sccache installation atm
# https://github.com/mozilla/sccache
# rustc-wrapper = "sccache"

# For details checkout https://jondot.medium.com/8-steps-for-troubleshooting-your-rust-build-times-2ffc965fd13e
[target.x86_64-unknown-linux-gnu]
# clang has been listed as prerequisite in the doc
linker = "clang"
# enable avx2 by default since it's avaiable on almost all x86_64 CPUs
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Ctarget-feature=+avx2,+fma", "-Zshare-generics=y"]

[target.x86_64-apple-darwin]
# zld might help here
# brew install michaeleisel/zld/zld
# "-Clink-arg=-fuse-ld=zld"
# For details checkout https://jondot.medium.com/8-steps-for-troubleshooting-your-rust-build-times-2ffc965fd13e
rustflags = ["-Ctarget-feature=+avx2,+fma", "-Zshare-generics=y"]

[net]
git-fetch-with-cli = true
retry = 5
19 changes: 11 additions & 8 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ jobs:
runs-on: buildjet-8vcpu-ubuntu-2004
timeout-minutes: 30
steps:
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential clang ocl-icd-opencl-dev
- name: Checkout Sources
uses: actions/checkout@v3
with:
submodules: true
- name: Rust Cache
uses: Swatinem/rust-cache@v2
timeout-minutes: 5
continue-on-error: true
- name: Apt Dependencies
run: sudo make install-deps
- name: Setup sccache
uses: hanabi1224/sccache-action@v1.2.0
with:
release-name: v0.3.0
cache-key: ${{ runner.os }}-sccache-codecov-${{ hashFiles('rust-toolchain.toml') }}
cache-update: ${{ github.event_name != 'pull_request' }}
- name: Run cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Generate code coverage
run: cargo llvm-cov --workspace --lcov --output-path lcov.info
env:
CC: "sccache clang"
CXX: "sccache clang++"
- name: Upload CodeCov
uses: codecov/codecov-action@v3
with:
Expand Down
32 changes: 24 additions & 8 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,44 @@ jobs:
name: Publish
runs-on: ubuntu-latest
steps:
- name: Apt Dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential clang ocl-icd-opencl-dev
- name: Checkout Sources
uses: actions/checkout@v3
- name: Apt Dependencies
run: sudo make install-deps
- name: Link Checker (Repo)
uses: lycheeverse/lychee-action@v1.5.1
with:
args: --verbose --no-progress 'README.md'
# Fail action on broken links
fail: true
- name: Rust Cache
uses: Swatinem/rust-cache@v2
timeout-minutes: 5
continue-on-error: true
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
key: ${{ runner.os }}-docs-cargo-bin-${{ hashFiles('rust-toolchain.toml') }}
- name: Install MDBook
run: cargo install mdbook mdbook-linkcheck --locked
env:
RUSTFLAGS: "-Cstrip=symbols"
continue-on-error: true
- name: Setup sccache
uses: hanabi1224/sccache-action@v1.2.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be great to include a comment on why are we using a fork

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Basically we need the cache-update to only save the cache on 1. main branch, 2. cache not found. The original action repo looks like unmaintained so we keep using the fork

with:
release-name: v0.3.0
cache-key: ${{ runner.os }}-sccache-docs-${{ hashFiles('rust-toolchain.toml') }}
# true: always save cache
# false: only save when cache is not found
# this option is only available in the forked action
# the original action has no activities for years so we
# just keep using the fork
cache-update: ${{ github.event_name != 'pull_request' }}
- name: Execute MDBook
run: make mdbook-build
- name: Build rustdoc
run: make rustdoc
env:
CC: "sccache clang"
CXX: "sccache clang++"
- name: Link Checker (Docs)
uses: lycheeverse/lychee-action@v1.5.1
with:
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ jobs:
- os: macos-latest
file: forest-${{ github.ref_name }}-macos-amd64.zip
steps:
- name: Checkout Sources
uses: actions/checkout@v3
- name: Apt Dependencies
if: startsWith(matrix.os, 'Ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y build-essential clang ocl-icd-opencl-dev
run: sudo make install-deps
- name: Homebrew Utils
if: startsWith(matrix.os, 'macOS')
run: |
brew install --verbose coreutils
- name: Checkout Sources
uses: actions/checkout@v3
- name: Rust Cache
uses: Swatinem/rust-cache@v2
timeout-minutes: 5
Expand Down
161 changes: 67 additions & 94 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Rust

on:
workflow_dispatch:
pull_request:
branches:
- main
Expand All @@ -14,140 +15,112 @@ env:
CI: 1
CARGO_INCREMENTAL: 1
CACHE_TIMEOUT_MINUTES: 5
RUSTFLAGS: -Ctarget-feature=+avx2,+fma

jobs:
test:
name: Test
runs-on: buildjet-8vcpu-ubuntu-2004
timeout-minutes: 30
env:
RUSTFLAGS: "-Ctarget-feature=+avx2,+fma -D warnings"
steps:
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential clang ocl-icd-opencl-dev
- name: Checkout Sources
uses: actions/checkout@v3
- name: Setup sccache
uses: hanabi1224/sccache-action@v1.2.0
with:
release-name: v0.3.0
cache-key: ${{ runner.os }}-sccache-test-${{ hashFiles('rust-toolchain.toml') }}
cache-update: ${{ github.event_name != 'pull_request' }}
- name: Apt Dependencies
run: sudo make install-deps
- name: install nextest
uses: taiki-e/install-action@nextest
- name: Rust Cache
uses: Swatinem/rust-cache@v2
timeout-minutes: ${{ fromJSON(env.CACHE_TIMEOUT_MINUTES) }}
continue-on-error: true
- name: Cargo Check
run: cargo check
- name: Make Test-All
run: make test-all

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Apt Dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential clang ocl-icd-opencl-dev
- name: Checkout Sources
uses: actions/checkout@v3
- name: Rust Cache
uses: Swatinem/rust-cache@v2
timeout-minutes: ${{ fromJSON(env.CACHE_TIMEOUT_MINUTES) }}
continue-on-error: true
- name: Install taplo (TOML linter)
run: cargo install taplo-cli --locked
- name: Run Linters
run: make lint

audit:
name: Audit
runs-on: ubuntu-latest
steps:
- name: Checkout Sources
uses: actions/checkout@v3
- name: Rust Cache
uses: Swatinem/rust-cache@v2
timeout-minutes: ${{ fromJSON(env.CACHE_TIMEOUT_MINUTES) }}
continue-on-error: true
- name: Install Audit
run: cargo install cargo-audit --locked
- name: Run Audit
run: make audit

unused_dependencies:
name: Unused dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout Sources
uses: actions/checkout@v3
- name: Rust Cache
uses: Swatinem/rust-cache@v2
timeout-minutes: ${{ fromJSON(env.CACHE_TIMEOUT_MINUTES) }}
continue-on-error: true
- name: Install udeps
run: cargo install cargo-udeps --locked
- name: Run udeps
run: make udeps
- run: make test-all
env:
CC: "sccache clang"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if it wouldn't clash with some other steps, but would adding those envs as global for the entire workflow be fine?

Copy link
Contributor Author

@hanabi1224 hanabi1224 Oct 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sccache is not always the first step to avoid generating cache for cargo install [tools], so that sccache is not available during cargo install and apt-get install which very likely invoke c/c++ compilers

CXX: "sccache clang++"

spellcheck:
name: Spellcheck
lint-all:
name: All lint checks (lint audit spellcheck udeps)
runs-on: ubuntu-latest
steps:
- name: Checkout Sources
uses: actions/checkout@v3
- name: Rust Cache
uses: Swatinem/rust-cache@v2
timeout-minutes: ${{ fromJSON(env.CACHE_TIMEOUT_MINUTES) }}
- name: Apt Dependencies
run: sudo make install-deps
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
key: ${{ runner.os }}-lints-cargo-bin-${{ hashFiles('rust-toolchain.toml') }}
- run: make install-lint-tools
continue-on-error: true
- name: Install spellcheck
run: cargo install cargo-spellcheck --locked
- name: Run Spellcheck
run: make spellcheck
- name: Setup sccache
uses: hanabi1224/sccache-action@v1.2.0
with:
release-name: v0.3.0
cache-key: ${{ runner.os }}-sccache-lints-${{ hashFiles('rust-toolchain.toml') }}
cache-update: ${{ github.event_name != 'pull_request' }}
- run: make lint-all
env:
CC: "sccache clang"
CXX: "sccache clang++"

build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
#rv: [1.58.1, stable, beta, nightly]
rv: [nightly]
steps:
- name: Install Dependencies
if: startsWith(matrix.os, 'Ubuntu')
run: |
sudo apt-get update
sudo apt-get install -y build-essential clang ocl-icd-opencl-dev
- name: Checkout Sources
uses: actions/checkout@v3
- name: Rust Cache
uses: Swatinem/rust-cache@v2
timeout-minutes: ${{ fromJSON(env.CACHE_TIMEOUT_MINUTES) }}
continue-on-error: true
- name: Cargo Build
run: cargo build --profile dev
- name: Setup sccache
uses: hanabi1224/sccache-action@v1.2.0
with:
# hard code release-name for macos, it always get rate limited when calling github api
release-name: v0.3.0
cache-key: ${{ runner.os }}-sccache-${{ hashFiles('rust-toolchain.toml') }}
cache-update: ${{ github.event_name != 'pull_request' }}
- name: Install Apt Dependencies
if: startsWith(matrix.os, 'Ubuntu')
run: |
lscpu # the job may run on different CPUs, list cpu here for analysing build time
sudo make install-deps
- name: Cargo Check
run: cargo check --timings
env:
CC: "sccache clang"
CXX: "sccache clang++"
- uses: actions/upload-artifact@v3
with:
name: build-timings
path: |
target/cargo-timings/*
if-no-files-found: error

calibnet-check:
name: Calibnet sync check
if: ${{ false }}
runs-on: buildjet-8vcpu-ubuntu-2004
timeout-minutes: 30
steps:
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential clang ocl-icd-opencl-dev
- name: Checkout Sources
uses: actions/checkout@v3
with:
submodules: true
- name: Rust Cache
uses: Swatinem/rust-cache@v2
timeout-minutes: ${{ fromJSON(env.CACHE_TIMEOUT_MINUTES) }}
continue-on-error: true
- name: Apt Dependencies
run: sudo make install-deps
- name: Setup sccache
uses: hanabi1224/sccache-action@v1.2.0
with:
release-name: v0.3.0
cache-key: ${{ runner.os }}-sccache-calibnet-check-${{ hashFiles('rust-toolchain.toml') }}
cache-update: ${{ github.event_name != 'pull_request' }}
- name: build and install binaries
run: make install
env:
CC: "sccache clang"
CXX: "sccache clang++"
- name: download snapshot
run: forest-cli --chain calibnet chain fetch -s /tmp/snapshots/
- name: import snapshot and run Forest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ config*.toml
*.orig
criterion
genesis.json
/.cargo
/.cargo/*
!/.cargo/*.toml
node/rpc-api/static/ast.ron
documentation/book/**/*
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
FROM buildpack-deps:buster AS build-env

# Install dependencies
RUN apt-get update && apt-get install --no-install-recommends -y build-essential clang ocl-icd-opencl-dev cmake ca-certificates curl
RUN apt-get update && apt-get install --no-install-recommends -y build-essential clang lld ocl-icd-opencl-dev cmake ca-certificates curl
RUN update-ca-certificates

# Install rustup
# https://rustup.rs/
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
ENV RUSTFLAGS="-Ctarget-feature=+avx2,+fma"

WORKDIR /usr/src/forest
COPY . .
Expand Down
Loading