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: drive binary build script #2031

Open
wants to merge 4 commits into
base: feat/reproducibleBuilds
Choose a base branch
from
Open
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
11 changes: 7 additions & 4 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ linker = "x86_64-linux-gnu-gcc"
opt-level = 3
debug = false
debug-assertions = false
# TODO: I don't think it's a good idea
overflow-checks = false
lto = true
# TODO: I don't think it's a good idea
Comment on lines +21 to +24
Copy link
Member

Choose a reason for hiding this comment

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

justify?

Copy link
Member Author

@shumkov shumkov Sep 30, 2024

Choose a reason for hiding this comment

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

panic = 'abort'
codegen-units = 1
incremental = false
rustflags = [
"-C", "relocation-model=pic",
"-C", "strip=debuginfo"
]
strip = "debuginfo"
# TODO: Not supported in Rust 1.76
#rustflags = [
# "-C", "relocation-model=pic",
#]


[build]
Expand Down
29 changes: 29 additions & 0 deletions Dockerfile.rust-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use the official Rust image based on Debian Bullseye 1.76-bullseye
FROM rust@sha256:607b5e64b8d51f78ac5a37984e64f6493e9a7f90b605fa068be86ff035f48141

# Install necessary packages
RUN apt-get update && apt-get install -y \
clang \
cmake \
git \
wget \
bash \
unzip \
&& if [[ "$TARGETARCH" == "arm64" ]] ; then apt-get install -y gcc-aarch64-linux-gnu; fi \
&& rm -rf /var/lib/apt/lists/*

# Add Rust target
RUN if [[ "$TARGETARCH" == "arm64" ]] ; then RUST_TARGET=aarch64-unknown-linux-gnu; else RUST_TARGET=x86_64-unknown-linux-gnu; fi; \
rustup target add ${RUST_TARGET}

# Install protoc - protobuf compiler
ARG PROTOC_VERSION="25.2"
RUN if [[ "$TARGETARCH" == "arm64" ]] ; then export PROTOC_ARCH=aarch_64; else export PROTOC_ARCH=x86_64; fi; \
curl -Ls https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip \
-o /tmp/protoc.zip && \
unzip -qd /opt/protoc /tmp/protoc.zip && \
rm /tmp/protoc.zip && \
ln -s /opt/protoc/bin/protoc /usr/bin/

# Set the working directory inside the container
WORKDIR /app
Comment on lines +1 to +29
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

@shumkov shumkov Sep 30, 2024

Choose a reason for hiding this comment

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

yeah, this is replacement

59 changes: 59 additions & 0 deletions scripts/release_binaries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

set -e

FULL_PATH=$(realpath "$0")
DIR_PATH=$(dirname "$FULL_PATH")
ROOT_PATH=$(dirname "$DIR_PATH")

IMAGE_NAME="rust-build-env"

# Function to build the Docker image if it doesn't exist
build_docker_image() {
echo "Building Docker image $IMAGE_NAME..."
docker buildx build -t $IMAGE_NAME \
-f "$ROOT_PATH/Dockerfile.rust-build" \
--platform linux/amd64,linux/arm64 \
--load \
"$ROOT_PATH"
}

# Function to build and strip the binary for a specific target
build() {
local target=$1
local output_name=$2
local arch=$3

echo "Building Drive for target ${target}..."
docker run --rm \
-v "$ROOT_PATH:/app" \
-w /app \
-u "$(id -u):$(id -g)" \
--platform "$arch" \
"$IMAGE_NAME" \
cargo build --release \
--locked \
--target "$target" \
-p drive-abci

echo "Renaming output binary to ${output_name}..."
mv "$ROOT_PATH/target/$target/release/drive-abci" "$ROOT_PATH/$output_name"

echo "Creating tar.gz archive for $output_name..."
tar -czf "$ROOT_PATH/$output_name.tar.gz" "$ROOT_PATH/$output_name"
}

# Main script
main() {
build_docker_image

# Build for x86_64
build x86_64-unknown-linux-gnu drive-abci-linux-gnu-x86_64 linux/amd64

# Build for aarch64
build aarch64-unknown-linux-gnu drive-abci-linux-gnu-aarch64 linux/arm64

echo "Release process completed successfully."
}

main