Skip to content

Instantly share code, notes, and snippets.

@mimoo
Last active April 10, 2025 14:49
Show Gist options
  • Save mimoo/b92a7263e5316182e7aa8d8d056e3ddd to your computer and use it in GitHub Desktop.
Save mimoo/b92a7263e5316182e7aa8d8d056e3ddd to your computer and use it in GitHub Desktop.

Revisions

  1. mimoo revised this gist Apr 10, 2025. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    create this Dockerfile:
    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
  2. mimoo renamed this gist Apr 10, 2025. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. mimoo created this gist Apr 10, 2025.
    37 changes: 37 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    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`