Skip to content

Commit

Permalink
[+] OSXCross rust build
Browse files Browse the repository at this point in the history
  • Loading branch information
hykilpikonna committed Dec 22, 2024
1 parent ca74acb commit 90d12d9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tools/build_rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

set -e

# Step 1: Build the Docker image
echo "Building the Docker image..."
#echo "Building the Docker image..."
docker build -t rust-builder-general tools/rust-builder/general

# Step 2: Run the Docker container and execute the builder script
echo "Running the Docker container..."
docker run --rm -v "$(pwd)":/app rust-builder-general bash -c "cd /app && ./tools/rust-builder/general/build.sh"

echo "Building MacOS Docker image..."
docker build -t rust-builder-osx tools/rust-builder/osx

echo "Running MacOS Docker container..."
docker run --rm -v "$(pwd)":/app rust-builder-osx bash -c "cd /app && ./tools/rust-builder/osx/build.sh"
16 changes: 16 additions & 0 deletions tools/rust-builder/osx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM crazymax/osxcross:11.3-alpine AS osxcross

FROM alpine

# Install Rust building environment
RUN apk add --no-cache curl gcc musl-dev openssl-dev bash clang lld
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

# Add toolchains for building for macOS[x86_64, aarch64]
RUN /root/.cargo/bin/rustup target add x86_64-apple-darwin aarch64-apple-darwin

# Copy osxcross toolchain
# RUN apt-get update && apt-get install -y clang lld libc6-dev
ENV PATH="/osxcross/bin:$PATH"
ENV LD_LIBRARY_PATH="/osxcross/lib:$LD_LIBRARY_PATH"
COPY --from=osxcross /osxcross /osxcross
21 changes: 21 additions & 0 deletions tools/rust-builder/osx/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -e

# Add cargo to path
export PATH="$HOME/.cargo/bin:$PATH"
cd /app

# OSX linker and ar
export OSX_VER=20.4
export CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER=/osxcross/bin/x86_64-apple-darwin$OSX_VER-clang
export CARGO_TARGET_X86_64_APPLE_DARWIN_AR=/osxcross/bin/x86_64-apple-darwin$OSX_VER-ar
export CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=/osxcross/bin/aarch64-apple-darwin$OSX_VER-clang
export CARGO_TARGET_AARCH64_APPLE_DARWIN_AR=/osxcross/bin/aarch64-apple-darwin$OSX_VER-ar


# Build for platforms
#cp /osxcross/bin/x86_64-apple-darwin$OSX_VER-strip /usr/bin/strip
cargo build --release --target x86_64-apple-darwin
#cp /osxcross/bin/aarch64-apple-darwin$OSX_VER-strip /usr/bin/strip
cargo build --release --target aarch64-apple-darwin

0 comments on commit 90d12d9

Please sign in to comment.