-
Notifications
You must be signed in to change notification settings - Fork 179
chore: add standalone toolchain build scripts #2400
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # Default to x86_64-unknown-linux-gnu if no target specified | ||
| TARGET=${1:-x86_64-unknown-linux-musl} | ||
|
|
||
| case $TARGET in | ||
| x86_64-unknown-linux-musl) | ||
| echo "Building for Linux x86_64 platform" | ||
| DOCKERFILE="linux.Dockerfile" | ||
| BINARY="rivet-$TARGET" | ||
| ;; | ||
| aarch64-apple-darwin) | ||
| echo "Building for macOS ARM64 platform" | ||
| DOCKERFILE="macos.Dockerfile" | ||
| BINARY="rivet-$TARGET" | ||
| ;; | ||
| x86_64-apple-darwin) | ||
| echo "Building for macOS x86_64 platform" | ||
| DOCKERFILE="macos.Dockerfile" | ||
| BINARY="rivet-$TARGET" | ||
| ;; | ||
| x86_64-pc-windows-gnu) | ||
| echo "Building for Windows platform" | ||
| DOCKERFILE="windows.Dockerfile" | ||
| BINARY="rivet-$TARGET.exe" | ||
| ;; | ||
| *) | ||
| echo "Unsupported target: $TARGET" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| # Build docker image | ||
| DOCKER_BUILDKIT=1 docker build -f docker/toolchain/$DOCKERFILE -t rivet-cli-builder-$TARGET . | ||
|
|
||
| # Extract binary | ||
| CONTAINER_ID=$(docker create rivet-cli-builder-$TARGET) | ||
| mkdir -p dist | ||
| docker cp "$CONTAINER_ID:/artifacts/$BINARY" dist/ | ||
| docker rm "$CONTAINER_ID" | ||
|
|
||
| # Make binary executable (skip for Windows .exe files) | ||
| if [[ ! "$BINARY" == *.exe ]]; then | ||
| chmod +x dist/$BINARY | ||
| fi | ||
|
|
||
| echo "Binary saved to: dist/$BINARY" |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||
| # syntax=docker/dockerfile:1.4 | ||||||
| FROM rust:1.82.0 | ||||||
|
|
||||||
| # Install dependencies | ||||||
| RUN apt-get update && apt-get install -y \ | ||||||
| musl-tools \ | ||||||
| libssl-dev \ | ||||||
| pkg-config \ | ||||||
| protobuf-compiler \ | ||||||
| ca-certificates \ | ||||||
| git-lfs \ | ||||||
| musl-dev \ | ||||||
| && rm -rf /var/lib/apt/lists/* | ||||||
|
|
||||||
| # Install musl target | ||||||
| RUN rustup target add x86_64-unknown-linux-musl | ||||||
|
|
||||||
| # Set up OpenSSL for musl target | ||||||
| ENV SSL_VER=1.1.1w | ||||||
| RUN wget https://www.openssl.org/source/openssl-$SSL_VER.tar.gz \ | ||||||
| && tar -xzf openssl-$SSL_VER.tar.gz \ | ||||||
| && cd openssl-$SSL_VER \ | ||||||
| && ./Configure no-shared no-async --prefix=/musl --openssldir=/musl/ssl linux-x86_64 \ | ||||||
| && make -j$(nproc) \ | ||||||
| && make install_sw \ | ||||||
| && cd .. \ | ||||||
| && rm -rf openssl-$SSL_VER* | ||||||
|
|
||||||
| # Configure OpenSSL env vars for the build | ||||||
| ENV OPENSSL_DIR=/musl \ | ||||||
| OPENSSL_INCLUDE_DIR=/musl/include \ | ||||||
| OPENSSL_LIB_DIR=/musl/lib \ | ||||||
| PKG_CONFIG_ALLOW_CROSS=1 | ||||||
|
|
||||||
| # Set environment variables | ||||||
| ENV CARGO_INCREMENTAL=0 \ | ||||||
| RUSTFLAGS="--cfg tokio_unstable" \ | ||||||
| CARGO_NET_GIT_FETCH_WITH_CLI=true | ||||||
|
|
||||||
| # Set working directory | ||||||
| WORKDIR /build | ||||||
|
|
||||||
| # Build CLI instructions | ||||||
| COPY . . | ||||||
|
|
||||||
| # Build for Linux with musl (static binary) | ||||||
| RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||||||
| --mount=type=cache,target=/usr/local/cargo/git \ | ||||||
| --mount=type=cache,target=/build/target \ | ||||||
| cargo build --bin rivet --release --target x86_64-unknown-linux-musl -v && \ | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Add --locked flag to cargo build to ensure reproducible builds
Suggested change
|
||||||
| mkdir -p /artifacts && \ | ||||||
| cp target/x86_64-unknown-linux-musl/release/rivet /artifacts/rivet-x86_64-unknown-linux-musl | ||||||
|
|
||||||
| # Default command to show help | ||||||
| CMD ["ls", "-la", "/artifacts"] | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # syntax=docker/dockerfile:1.4 | ||
| FROM rust:1.82.0 | ||
|
|
||
| # Install dependencies | ||
| RUN apt-get update && apt-get install -y \ | ||
| git-lfs \ | ||
| protobuf-compiler \ | ||
| clang \ | ||
| cmake \ | ||
| patch \ | ||
| libxml2-dev \ | ||
| wget \ | ||
| xz-utils \ | ||
| curl \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Install osxcross | ||
| RUN git config --global --add safe.directory '*' && \ | ||
| git clone https://github.com/tpoechtrager/osxcross /root/osxcross && \ | ||
| cd /root/osxcross && \ | ||
| wget -nc https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz && \ | ||
| mv MacOSX11.3.sdk.tar.xz tarballs/ && \ | ||
| UNATTENDED=yes OSX_VERSION_MIN=10.7 ./build.sh | ||
|
|
||
| # Add osxcross to PATH | ||
| ENV PATH="/root/osxcross/target/bin:$PATH" | ||
|
|
||
| # Install macOS target | ||
| RUN rustup target add x86_64-apple-darwin aarch64-apple-darwin | ||
|
|
||
| # Configure Cargo for cross-compilation | ||
| RUN mkdir -p /root/.cargo && \ | ||
| echo '\ | ||
| [target.x86_64-apple-darwin]\n\ | ||
| linker = "x86_64-apple-darwin20.4-clang"\n\ | ||
| ar = "x86_64-apple-darwin20.4-ar"\n\ | ||
| \n\ | ||
| [target.aarch64-apple-darwin]\n\ | ||
| linker = "aarch64-apple-darwin20.4-clang"\n\ | ||
| ar = "aarch64-apple-darwin20.4-ar"\n\ | ||
| ' > /root/.cargo/config.toml | ||
|
|
||
| # Set environment variables for cross-compilation | ||
| ENV CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER=x86_64-apple-darwin20.4-clang \ | ||
| CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=aarch64-apple-darwin20.4-clang \ | ||
| CC_x86_64_apple_darwin=x86_64-apple-darwin20.4-clang \ | ||
| CXX_x86_64_apple_darwin=x86_64-apple-darwin20.4-clang++ \ | ||
| CC_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang \ | ||
| CXX_aarch64_apple_darwin=aarch64-apple-darwin20.4-clang++ \ | ||
| MACOSX_DEPLOYMENT_TARGET=10.7 \ | ||
| # Skip aws-lc-rs with rustls certs config when building for macOS | ||
| RUSTFLAGS="--cfg tokio_unstable --cfg rustls_native_certs --cfg aws_lc_rs" \ | ||
| CARGO_FEATURE_RUSTLS_NATIVE_CERTS=0 \ | ||
| CARGO_RUSTLS_NATIVE_CERTS=0 \ | ||
| CARGO_INCREMENTAL=0 \ | ||
| CARGO_NET_GIT_FETCH_WITH_CLI=true | ||
|
|
||
| # Set working directory | ||
| WORKDIR /build | ||
|
|
||
| # Copy the source code | ||
| COPY . . | ||
|
|
||
| # Build for x86_64 macOS | ||
| RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||
| --mount=type=cache,target=/usr/local/cargo/git \ | ||
| --mount=type=cache,target=/build/target \ | ||
|
Comment on lines
+65
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Cache mounts should be unique per architecture to prevent potential conflicts between x86_64 and ARM64 builds |
||
| cargo build --bin rivet --release --target x86_64-apple-darwin && \ | ||
| mkdir -p /artifacts && \ | ||
| cp target/x86_64-apple-darwin/release/rivet /artifacts/rivet-x86_64-apple-darwin | ||
|
|
||
| # Build for ARM64 macOS | ||
| RUN --mount=type=cache,target=/usr/local/cargo/registry \ | ||
| --mount=type=cache,target=/usr/local/cargo/git \ | ||
| --mount=type=cache,target=/build/target \ | ||
| cargo build --bin rivet --release --target aarch64-apple-darwin && \ | ||
| cp target/aarch64-apple-darwin/release/rivet /artifacts/rivet-aarch64-apple-darwin | ||
|
|
||
| # Default command to show help | ||
| CMD ["ls", "-la", "/artifacts"] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Inconsistent indentation between lines (tab vs spaces)