Need to test some Rust program in a 32-bit environment? You're on MacOS? Looks like you're going to have to use Docker. Not only that, but you'll have to use Docker with a 64-bit linux environment, that can support building and running 32-bit binaries.
Create this Dockerfile:
FROM rust:latest
# Ensure we don't use our local build folder
ENV CARGO_TARGET_DIR=/tmp/target32
# Install 32-bit compilation support
RUN dpkg --add-architecture i386 && \
apt-get update && \
apt-get install -y gcc-multilib libc6-dev:i386
# Install 32-bit Rust target
RUN rustup target add i686-unknown-linux-gnu
# Create app directory
WORKDIR /usr/src/app
# Set up local config for 32-bit default
RUN mkdir -p .cargo && \
echo '[build]\ntarget = "i686-unknown-linux-gnu"' > .cargo/config.toml
then build it / run it:
docker build --platform=linux/amd64 -t rust-32 .
docker run --platform=linux/amd64 -it --rm \
-v "$PWD":/usr/src/app \
-w /usr/src/app \
rust-32 \
bash
this will mount your local directory (which should contain your rust project) and any cargo command should automatically pick up on the 32-bit target that's set as default in .cargo/config.toml