Merge pull request #867 from dockcross/android-add-rust

Install rustup globally and add Rust support to Android images
This commit is contained in:
Matt McCormick
2025-02-27 13:45:00 -05:00
committed by GitHub
11 changed files with 58 additions and 0 deletions

View File

@ -18,6 +18,8 @@ Cross compiling toolchains in Docker images.
- [Meson](https://mesonbuild.com) is pre-installed. - [Meson](https://mesonbuild.com) is pre-installed.
- [Conan.io](https://www.conan.io) can be used as a package manager. - [Conan.io](https://www.conan.io) can be used as a package manager.
- Toolchain files configured for CMake. - Toolchain files configured for CMake.
- [Rustup](https://rustup.rs/) is pre-installed.
- Some images (e.g. android) are configured for Rust.
- Current directory is mounted as the container\'s workdir, `/work`. - Current directory is mounted as the container\'s workdir, `/work`.
- Works with the [Docker for Mac](https://docs.docker.com/docker-for-mac/) and [Docker for Windows](https://docs.docker.com/docker-for-windows/). - Works with the [Docker for Mac](https://docs.docker.com/docker-for-mac/) and [Docker for Windows](https://docs.docker.com/docker-for-windows/).
- Support using alternative container executor by setting **OCI_EXE** environment variable. By default, it searches for [docker](https://www.docker.com) and [podman](https://podman.io) executable. - Support using alternative container executor by setting **OCI_EXE** environment variable. By default, it searches for [docker](https://www.docker.com) and [podman](https://podman.io) executable.
@ -30,6 +32,7 @@ Cross compiling toolchains in Docker images.
3. `dockcross ninja -Cbuild`: Run ninja in the `./build` directory. 3. `dockcross ninja -Cbuild`: Run ninja in the `./build` directory.
4. `dockcross bash -c '$CC test/C/hello.c -o hello'`: Build the *hello.c* file with the compiler identified with the `CC` environmental variable in the build environment. 4. `dockcross bash -c '$CC test/C/hello.c -o hello'`: Build the *hello.c* file with the compiler identified with the `CC` environmental variable in the build environment.
5. `dockcross bash`: Run an interactive shell in the build environment. 5. `dockcross bash`: Run an interactive shell in the build environment.
6. `dockcross cargo build`: Build the current Rust project.
Note that commands are executed verbatim. If any shell processing for environment variable expansion or redirection is required, please use Note that commands are executed verbatim. If any shell processing for environment variable expansion or redirection is required, please use

View File

@ -35,6 +35,12 @@ RUN mkdir -p /build && \
find ${CROSS_ROOT} -exec chmod a+r '{}' \; && \ find ${CROSS_ROOT} -exec chmod a+r '{}' \; && \
find ${CROSS_ROOT} -executable -exec chmod a+x '{}' \; find ${CROSS_ROOT} -executable -exec chmod a+x '{}' \;
# Prepare Rust
ENV PATH="/root/.cargo/bin/:$PATH"
RUN rustup target add armv7-linux-androideabi
COPY config.toml /root/.cargo/
# Prepare CMake
COPY Toolchain.cmake ${CROSS_ROOT}/ COPY Toolchain.cmake ${CROSS_ROOT}/
ENV CMAKE_TOOLCHAIN_FILE ${CROSS_ROOT}/Toolchain.cmake ENV CMAKE_TOOLCHAIN_FILE ${CROSS_ROOT}/Toolchain.cmake

5
android-arm/config.toml Normal file
View File

@ -0,0 +1,5 @@
[build]
target = "armv7-linux-androideabi"
[target.armv7-linux-androideabi]
linker = "/usr/arm-linux-androideabi/bin/armv7a-linux-androideabi23-clang"

View File

@ -39,7 +39,12 @@ RUN mkdir -p /build && \
find ${CROSS_ROOT} -exec chmod a+r '{}' \; && \ find ${CROSS_ROOT} -exec chmod a+r '{}' \; && \
find ${CROSS_ROOT} -executable -exec chmod a+x '{}' \; find ${CROSS_ROOT} -executable -exec chmod a+x '{}' \;
# Prepare Rust
ENV PATH="/root/.cargo/bin/:$PATH"
RUN rustup target add aarch64-linux-android
COPY config.toml /root/.cargo/
# Prepare CMake
COPY Toolchain.cmake ${CROSS_ROOT}/ COPY Toolchain.cmake ${CROSS_ROOT}/
ENV CMAKE_TOOLCHAIN_FILE ${CROSS_ROOT}/Toolchain.cmake ENV CMAKE_TOOLCHAIN_FILE ${CROSS_ROOT}/Toolchain.cmake

View File

@ -0,0 +1,5 @@
[build]
target = "aarch64-linux-android"
[target.aarch64-linux-android]
linker = "/usr/aarch64-linux-android/bin/aarch64-linux-android-clang"

View File

@ -29,6 +29,12 @@ RUN mkdir -p /build && \
find ${CROSS_ROOT} -exec chmod a+r '{}' \; && \ find ${CROSS_ROOT} -exec chmod a+r '{}' \; && \
find ${CROSS_ROOT} -executable -exec chmod a+x '{}' \; find ${CROSS_ROOT} -executable -exec chmod a+x '{}' \;
# Prepare Rust
ENV PATH="/root/.cargo/bin/:$PATH"
RUN rustup target add i686-linux-android
COPY config.toml /root/.cargo/
# Prepare CMake
COPY Toolchain.cmake ${CROSS_ROOT}/ COPY Toolchain.cmake ${CROSS_ROOT}/
ENV CMAKE_TOOLCHAIN_FILE ${CROSS_ROOT}/Toolchain.cmake ENV CMAKE_TOOLCHAIN_FILE ${CROSS_ROOT}/Toolchain.cmake

5
android-x86/config.toml Normal file
View File

@ -0,0 +1,5 @@
[build]
target = "i686-linux-android"
[target.i686-linux-android]
linker = "/usr/i686-linux-android/bin/i686-linux-android23-clang"

View File

@ -29,6 +29,12 @@ RUN mkdir -p /build && \
find ${CROSS_ROOT} -exec chmod a+r '{}' \; && \ find ${CROSS_ROOT} -exec chmod a+r '{}' \; && \
find ${CROSS_ROOT} -executable -exec chmod a+x '{}' \; find ${CROSS_ROOT} -executable -exec chmod a+x '{}' \;
# Prepare Rust
ENV PATH="/root/.cargo/bin/:$PATH"
RUN rustup target add x86_64-linux-android
COPY config.toml /root/.cargo/
# Prepare CMake
COPY Toolchain.cmake ${CROSS_ROOT}/ COPY Toolchain.cmake ${CROSS_ROOT}/
ENV CMAKE_TOOLCHAIN_FILE ${CROSS_ROOT}/Toolchain.cmake ENV CMAKE_TOOLCHAIN_FILE ${CROSS_ROOT}/Toolchain.cmake

View File

@ -0,0 +1,5 @@
[build]
target = "x86_64-linux-android"
[target.x86_64-linux-android]
linker = "/usr/x86_64-linux-android/bin/x86_64-linux-android-clang"

View File

@ -25,6 +25,7 @@ COPY \
imagefiles/build-and-install-ninja.sh \ imagefiles/build-and-install-ninja.sh \
imagefiles/build-and-install-openssl.sh \ imagefiles/build-and-install-openssl.sh \
imagefiles/build-and-install-openssh.sh \ imagefiles/build-and-install-openssh.sh \
imagefiles/build-and-install-rustup.sh \
imagefiles/install-cmake-binary.sh \ imagefiles/install-cmake-binary.sh \
imagefiles/install-liquidprompt-binary.sh \ imagefiles/install-liquidprompt-binary.sh \
imagefiles/install-python-packages.sh \ imagefiles/install-python-packages.sh \
@ -38,6 +39,7 @@ RUN \
/buildscripts/build-and-install-curl.sh && \ /buildscripts/build-and-install-curl.sh && \
/buildscripts/build-and-install-git.sh && \ /buildscripts/build-and-install-git.sh && \
/buildscripts/build-and-install-cmake.sh $X86_FLAG && \ /buildscripts/build-and-install-cmake.sh $X86_FLAG && \
/buildscripts/build-and-install-rustup.sh && \
/buildscripts/install-liquidprompt-binary.sh && \ /buildscripts/install-liquidprompt-binary.sh && \
PYTHON=$([ -e /opt/python/cp38-cp38/bin/python ] && echo "/opt/python/cp38-cp38/bin/python" || echo "python3") && \ PYTHON=$([ -e /opt/python/cp38-cp38/bin/python ] && echo "/opt/python/cp38-cp38/bin/python" || echo "python3") && \
/buildscripts/install-python-packages.sh -python ${PYTHON} && \ /buildscripts/install-python-packages.sh -python ${PYTHON} && \

View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -ex
if ! command -v curl &> /dev/null; then
echo >&2 'error: "curl" not found!'
exit 1
fi
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y