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

build!: optimize build process for Haswell CPUs #2374

Draft
wants to merge 11 commits into
base: v1.7-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion .cargo/config-release.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
rustflags = ["-C", "target-feature=-crt-static"]

[target.x86_64-unknown-linux-musl]
rustflags = ["-C", "target-feature=-crt-static"]
rustflags = ["-C", "target-feature=-crt-static", "-C", "target-cpu=x86-64-v3"]

[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "target-feature=-crt-static", "-C", "target-cpu=x86-64-v3"]

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
19 changes: 18 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@
rustflags = ["-C", "target-feature=-crt-static", "--cfg", "tokio_unstable"]

[target.x86_64-unknown-linux-musl]
rustflags = ["-C", "target-feature=-crt-static", "--cfg", "tokio_unstable"]
rustflags = [
"-C",
"target-feature=-crt-static",
"--cfg",
"tokio_unstable",
"-C",
"target-cpu=x86-64",
]

[target.x86_64-unknown-linux-gnu]
rustflags = [
"-C",
"target-feature=-crt-static",
"--cfg",
"tokio_unstable",
"-C",
"target-cpu=x86-64",
]

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
Expand Down
42 changes: 32 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,28 @@ RUN TOOLCHAIN_VERSION="$(grep channel rust-toolchain.toml | awk '{print $3}' | t
ONBUILD ENV HOME=/root
ONBUILD ENV CARGO_HOME=$HOME/.cargo

# Configure Rust toolchain
ONBUILD ARG CARGO_BUILD_PROFILE=dev

# Configure Rust toolchain and C / C++ compiler
RUN <<EOS
# It doesn't sharing PATH between stages, so we need "source $HOME/.cargo/env" everywhere
RUN echo 'source $HOME/.cargo/env' >> /root/env
echo 'source $HOME/.cargo/env' >> /root/env

# Enable gcc / g++ optimizations
if [[ "$TARGETARCH" == "amd64" ]] ; then
if [[ "${CARGO_BUILD_PROFILE}" == "release" ]] ; then
echo "export CFLAGS=-march=x86-64-v3" >> /root/env
echo "export CXXFLAGS=-march=x86-64-v3" >> /root/env
echo "PORTABLE=x86-64-v3" >> /root/env
else
echo "export CFLAGS=-march=x86-64" >> /root/env
echo "export CXXFLAGS=-march=x86-64" >> /root/env
echo "PORTABLE=1" >> /root/env
fi
else
echo "PORTABLE=1" >> /root/env
fi
EOS

# Install protoc - protobuf compiler
# The one shipped with Alpine does not work
Expand Down Expand Up @@ -258,14 +277,15 @@ WORKDIR /tmp/rocksdb
# sccache -s
# EOS

# Select whether we want dev or release
# This variable will be also visibe in next stages
ONBUILD ARG CARGO_BUILD_PROFILE=dev

RUN --mount=type=secret,id=AWS <<EOS
set -ex -o pipefail
git clone https://github.com/facebook/rocksdb.git -b v8.10.2 --depth 1 .
source /root/env

# Support any CPU architecture
export PORTABLE=1

make -j$(nproc) static_lib
mkdir -p /opt/rocksdb/usr/local/lib
cp librocksdb.a /opt/rocksdb/usr/local/lib/
Expand Down Expand Up @@ -313,17 +333,13 @@ RUN --mount=type=secret,id=AWS \

RUN --mount=type=secret,id=AWS \
source /root/env; \
cargo binstall [email protected] [email protected] \
cargo binstall [email protected] [email protected] [email protected] \
--locked \
--no-discover-github-token \
--disable-telemetry \
--no-track \
--no-confirm


# Select whether we want dev or release
ONBUILD ARG CARGO_BUILD_PROFILE=dev

#
# Rust build planner to speed up builds
#
Expand Down Expand Up @@ -465,6 +481,12 @@ RUN --mount=type=cache,sharing=shared,id=cargo_registry_index,target=${CARGO_HOM
# Remove /platform to reduce layer size
rm -rf /platform

# See what CPU capabilities are required
RUN --mount=type=secret,id=AWS \
set -ex; \
source /root/env && \
elfx86exts /artifacts/drive-abci

#
# STAGE: BUILD JAVASCRIPT INTERMEDIATE IMAGE
#
Expand Down
4 changes: 4 additions & 0 deletions packages/rs-drive-abci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ grovedbg = ["drive/grovedbg"]
[[bin]]
name = "drive-abci"
path = "src/main.rs"


[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tokio_unstable)'] }
Loading