Skip to content

Commit da1fa9c

Browse files
authored
Merge pull request tectonic-typesetting#13 from pkgw/add-mips
Add a MIPS Docker image
2 parents b36aabd + a4c8b34 commit da1fa9c

File tree

6 files changed

+148
-0
lines changed

6 files changed

+148
-0
lines changed

.azure-pipelines/variables.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ variables:
99
windows_image: 'windows-2019'
1010
cross_tag: 'v0.1.16'
1111
target_arm_unknown_linux_musleabihf: 'arm-unknown-linux-musleabihf'
12+
target_mips_unknown_linux_gnu: 'mips-unknown-linux-gnu'
1213
target_x86_64_unknown_linux_musl: 'x86_64-unknown-linux-musl'

cross-images/01_debian_populate.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#! /bin/bash
2+
# Copyright 2019 The Tectonic Project
3+
# Licensed under the MIT License.
4+
5+
set -xeuo pipefail
6+
7+
apt-get install -y \
8+
binfmt-support \
9+
crossbuild-essential-${debian_arch} \
10+
pkg-config \
11+
qemu \
12+
qemu-user-static \
13+
sudo
14+
15+
# Must do this in two stages because mips openssl messes up amd64 openssl.
16+
17+
apt-get install -y \
18+
libgraphite2-dev:${debian_arch} \
19+
libharfbuzz-dev:${debian_arch} \
20+
libfontconfig1-dev:${debian_arch} \
21+
libfreetype6-dev:${debian_arch} \
22+
libicu-dev:${debian_arch} \
23+
libssl-dev:${debian_arch} \
24+
openssl:${debian_arch} \
25+
zlib1g-dev:${debian_arch}
26+
27+
apt-get clean
28+
rm -rf /var/lib/apt/lists/*
29+
30+
rm -f "$0" # self-destruct

cross-images/02_debian_setup_env.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#! /bin/bash
2+
# Copyright 2019 The Tectonic Project
3+
# Licensed under the MIT License.
4+
5+
set -xeuo pipefail
6+
7+
urp="$(echo $rust_platform |tr - _)"
8+
crp="$(echo $urp |tr '[a-z]' '[A-Z]')"
9+
10+
RUSTFLAGS="-L /usr/lib/${debian_platform}"
11+
12+
cat <<EOF >/environ
13+
export AR_${urp}="${debian_platform}-ar"
14+
export CC_${urp}="${debian_platform}-gcc"
15+
export CXX_${urp}="${debian_platform}-g++"
16+
export CARGO_TARGET_${crp}_LINKER="${debian_platform}-g++"
17+
18+
export OPENSSL_LIB_DIR=/usr/lib/${debian_platform}
19+
export OPENSSL_INCLUDE_DIR=/usr/include
20+
export PKG_CONFIG_LIBDIR=/usr/lib/${debian_platform}/pkgconfig
21+
22+
export RUSTFLAGS="$RUSTFLAGS"
23+
export PKG_CONFIG_ALLOW_CROSS=1
24+
export RUST_TEST_THREADS=1
25+
export RUST_BACKTRACE=1
26+
EOF
27+
28+
# The OpenSSL includes are split between /usr/include (platform-independent)
29+
# and /usr/include/${debian_platform} (platform-dependent). I don't believe
30+
# that openssl-sys is smart enough to deal with that well. Since we're in a
31+
# container, just hack it:
32+
cp /usr/include/${debian_platform}/openssl/*.h /usr/include/openssl/
33+
34+
if [ $qemu_arch != native ] ; then
35+
cat <<EOF >>/environ
36+
export CARGO_TARGET_${crp}_RUNNER=qemu-${qemu_arch}-static
37+
EOF
38+
fi
39+
40+
rm -f "$0" # self-destruct

cross-images/Dockerfile.debian-cross

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2019 The Tectonic Project
2+
# Licensed under the MIT License.
3+
4+
FROM debian:buster
5+
6+
ARG UID=1000
7+
ARG rust_platform
8+
ARG debian_platform
9+
ARG debian_arch
10+
ARG qemu_arch
11+
12+
ENV TERM=dumb
13+
RUN dpkg --add-architecture ${debian_arch} && apt-get update
14+
ADD 01_debian_populate.sh /
15+
RUN /bin/bash /01_debian_populate.sh
16+
17+
ADD 02_debian_setup_env.sh /
18+
RUN /bin/bash /02_debian_setup_env.sh
19+
20+
WORKDIR /project
21+
ADD debian-entrypoint.sh /entrypoint.sh
22+
ENTRYPOINT ["/entrypoint.sh"]
23+
CMD ["cargo", "test", "--release", "--all"]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#! /usr/bin/env bash
2+
# Copyright 2019 The Tectonic Project
3+
# Licensed under the MIT License.
4+
5+
[ -n "$IMGUID" ] || IMGUID="$(id -u)"
6+
rust_platform=mips-unknown-linux-gnu
7+
debian_platform=mips-linux-gnu
8+
debian_arch=mips
9+
qemu_arch=mips
10+
11+
cd "$(dirname $0)" && \
12+
exec docker build \
13+
-t tectonictypesetting/crossbuild:$rust_platform \
14+
-f Dockerfile.debian-cross \
15+
--build-arg UID=$IMGUID \
16+
--build-arg rust_platform=$rust_platform \
17+
--build-arg debian_platform=$debian_platform \
18+
--build-arg debian_arch=$debian_arch \
19+
--build-arg qemu_arch=$qemu_arch \
20+
.

cross-images/debian-entrypoint.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#! /usr/bin/env bash
2+
# Copyright 2019 the Tectonic Project
3+
# Licensed under the MIT license.
4+
5+
set -euo pipefail
6+
7+
# This script shouldn't be necessary since we don't need to chroot in the
8+
# debian-cross builder, but we want to use the same `cross` driver for that
9+
# and for the alpine-cross one that does, so we have to jump through the same
10+
# hoops.
11+
12+
# Ensure that there exist a user and group with the desired UID/GID.
13+
14+
groupname="$(getent group $HOST_GID |cut -d: -f1 || true)"
15+
if [ -z "$groupname" ] ; then
16+
groupname="gid${HOST_GID}"
17+
addgroup -q --gid $HOST_GID "$groupname"
18+
fi
19+
20+
username="$(getent passwd $HOST_UID |cut -d: -f1 || true)"
21+
if [ -z "$username" ] ; then
22+
username="user${HOST_UID}"
23+
adduser -q --gid $HOST_GID --uid $HOST_UID --disabled-password --gecos "UID $HOST_UID" "$username"
24+
fi
25+
26+
cur_prim_gid="$(getent passwd $HOST_UID |cut -d: -f4)"
27+
if [ "$cur_prim_gid" -ne "$HOST_GID" ] ; then
28+
usermod -g $HOST_GID "$username"
29+
fi
30+
31+
# We can now run the command with the desired UID/GID.
32+
33+
export HOME="$(getent passwd $HOST_UID |cut -d: -f6)"
34+
exec sudo -E -u "$username" sh -c '. /environ ; "$@"' -- "${@:-sh}"

0 commit comments

Comments
 (0)