Skip to content

Commit

Permalink
add support for i686-musl
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Dec 31, 2016
1 parent 2033c73 commit 17abfe3
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 29 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ matrix:
- env: TARGET=aarch64-unknown-linux-gnu
- env: TARGET=armv7-unknown-linux-gnueabihf
- env: TARGET=i686-unknown-linux-gnu
- env: TARGET=i686-unknown-linux-musl
- env: TARGET=mips-unknown-linux-gnu
- env: TARGET=mips64-unknown-linux-gnuabi64
- env: TARGET=mips64el-unknown-linux-gnuabi64
Expand Down
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,26 @@ because QEMU gets upset when you spawn several threads. This also means that, if
one of your unit tests spawns several threads then it's more likely to fail or,
worst, "hang" (never terminate).

| Target | glibc | GCC | QEMU | OpenSSL | `test` |
|--------------------------------------|-------|-------|-------|---------|:------:|
| `aarch64-unknown-linux-gnu` | 2.19 | 4.8.2 | 2.8.0 | 1.0.2j ||
| `armv7-unknown-linux-gnueabihf` | 2.15 | 4.6.2 | 2.8.0 | 1.0.2j ||
| `i686-unknown-linux-gnu` | 2.15 | 4.6.2 | N/A | 1.0.2j ||
| `mips-unknown-linux-gnu` | 2.23 | 5.3.1 | 2.8.0 | 1.0.2j ||
| `mips64-unknown-linux-gnuabi64` | 2.23 | 5.3.1 | 2.8.0 | 1.0.2j ||
| `mips64el-unknown-linux-gnuabi64` | 2.23 | 5.3.1 | 2.8.0 | 1.0.2j ||
| `mipsel-unknown-linux-gnu` | 2.23 | 5.3.1 | 2.8.0 | 1.0.2j ||
| `powerpc-unknown-linux-gnu` | 2.19 | 4.8.2 | 2.7.1 | 1.0.2j ||
| `powerpc64-unknown-linux-gnu` | 2.19 | 4.8.2 | 2.7.1 | 1.0.2j ||
| `powerpc64le-unknown-linux-gnu` | 2.19 | 4.8.2 | 2.7.1 | 1.0.2j ||
| `s390x-unknown-linux-gnu` | 2.23 | 5.3.1 | 2.8.0 | 1.0.2j | |
| `thumbv6m-none-eabi` | N/A | 5.3.1 | N/A | N/A | |
| `thumbv7em-none-eabi` | N/A | 5.3.1 | N/A | N/A | |
| `thumbv7em-none-eabihf` | N/A | 5.3.1 | N/A | N/A | |
| `thumbv7m-none-eabi` | N/A | 5.3.1 | N/A | N/A | |
| `x86_64-unknown-linux-gnu` | 2.15 | 4.6.2 | N/A | 1.0.2j ||
| `x86_64-unknown-linux-musl` | N/A | 5.3.1 | N/A | 1.0.2j ||
| Target | libc | GCC | QEMU | OpenSSL | `test` |
|--------------------------------------|--------|-------|-------|---------|:------:|
| `aarch64-unknown-linux-gnu` | 2.19 | 4.8.2 | 2.8.0 | 1.0.2j ||
| `armv7-unknown-linux-gnueabihf` | 2.15 | 4.6.2 | 2.8.0 | 1.0.2j ||
| `i686-unknown-linux-gnu` | 2.15 | 4.6.2 | N/A | 1.0.2j ||
| `i686-unknown-linux-musl` | 1.1.15 | 5.3.1 | N/A | N/A ||
| `mips-unknown-linux-gnu` | 2.23 | 5.3.1 | 2.8.0 | 1.0.2j ||
| `mips64-unknown-linux-gnuabi64` | 2.23 | 5.3.1 | 2.8.0 | 1.0.2j ||
| `mips64el-unknown-linux-gnuabi64` | 2.23 | 5.3.1 | 2.8.0 | 1.0.2j ||
| `mipsel-unknown-linux-gnu` | 2.23 | 5.3.1 | 2.8.0 | 1.0.2j ||
| `powerpc-unknown-linux-gnu` | 2.19 | 4.8.2 | 2.7.1 | 1.0.2j ||
| `powerpc64-unknown-linux-gnu` | 2.19 | 4.8.2 | 2.7.1 | 1.0.2j ||
| `powerpc64le-unknown-linux-gnu` | 2.19 | 4.8.2 | 2.7.1 | 1.0.2j ||
| `s390x-unknown-linux-gnu` | 2.23 | 5.3.1 | 2.8.0 | 1.0.2j | |
| `thumbv6m-none-eabi` | N/A | 5.3.1 | N/A | N/A | |
| `thumbv7em-none-eabi` | N/A | 5.3.1 | N/A | N/A | |
| `thumbv7em-none-eabihf` | N/A | 5.3.1 | N/A | N/A | |
| `thumbv7m-none-eabi` | N/A | 5.3.1 | N/A | N/A | |
| `x86_64-unknown-linux-gnu` | 2.15 | 4.6.2 | N/A | 1.0.2j ||
| `x86_64-unknown-linux-musl` | 1.1.15 | 5.3.1 | N/A | 1.0.2j ||

## Caveats / gotchas

Expand Down
5 changes: 3 additions & 2 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ main() {
;;
esac

if [ $TARGET != i686-apple-darwin ]; then
if [ $TARGET != i686-apple-darwin && $TARGET != i686-unknown-linux-musl ]; then
td=$(mktemp -d)

git clone --depth 1 https://github.com/rust-lang/cargo $td
Expand All @@ -48,7 +48,8 @@ main() {
# NOTE(x86_64-musl) can't test compiler-builtins because that crate needs
# cdylibs and this musl target doesn't support cdylibs
case $TARGET in
s390x-unknown-linux-gnu | \
i686-unknown-linux-musl | \
s390x-unknown-linux-gnu | \
x86_64-unknown-linux-musl)
;;
*)
Expand Down
16 changes: 16 additions & 0 deletions docker/i686-unknown-linux-musl/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM ubuntu:16.04

RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc-multilib

COPY musl.sh /
RUN bash /musl.sh 1.1.15 i386 -m32

RUN apt-get install -y --no-install-recommends \
ca-certificates \
cmake \
make \
pkg-config

ENV CC_i686_unknown_linux_musl=musl-gcc
32 changes: 32 additions & 0 deletions docker/musl-gcc.specs.x86_64-unknown-linux-musl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
%rename cpp_options old_cpp_options

*cpp_options:
-nostdinc -isystem /usr/local/include -isystem include%s %(old_cpp_options)

*cc1:
%(cc1_cpu) -nostdinc -isystem /usr/local/include -isystem include%s

*link_libgcc:
-L/usr/local/lib -L .%s

*libgcc:
libgcc.a%s %:if-exists(libgcc_eh.a%s)

*startfile:
%{!shared: /usr/local/lib/%{pie:S}crt1.o} /usr/local/lib/crti.o %{shared|pie:crtbeginS.o%s;:crtbegin.o%s}

*endfile:
%{shared|pie:crtendS.o%s;:crtend.o%s} /usr/local/lib/crtn.o

*link:
-dynamic-linker /lib/ld-musl-x86_64.so.1 -nostdlib %{shared:-shared} %{static:-static} %{rdynamic:-export-dynamic}

*esp_link:


*esp_options:


*esp_cpp_options:


2 changes: 2 additions & 0 deletions docker/musl-gcc.x86_64-unknown-linux-musl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec "${REALGCC:-cc}" "$@" -specs "/usr/local/lib/musl-gcc.specs"
47 changes: 47 additions & 0 deletions docker/musl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
set -ex

main() {
local version=$1 \
target=$2

local dependencies=(
ca-certificates
curl
make
)

apt-get install -y --no-install-recommends ${dependencies[@]}

local td=$(mktemp -d)

pushd $td
curl https://www.musl-libc.org/releases/musl-$version.tar.gz | \
tar --strip-components=1 -xz

if [ ! -z $target ]; then
ln -s /usr/bin/{,$target-}ar
ln -s /usr/bin/{,$target-}cc
ln -s /usr/bin/{,$target-}ranlib
fi

CFLAGS="-fPIC ${@:3}" ./configure \
--disabled-shared \
--prefix=/usr/local \
$(test -z $target || echo --target=$target)
nice make -j$(nproc)
nice make install
ln -s /usr/bin/ar /usr/local/bin/musl-ar

if [ ! -z $target ]; then
rm /usr/bin/$target-{ar,ranlib}
fi

apt-get purge --auto-remove -y ${dependencies[@]}

popd

rm -rf $td
rm $0
}

main "${@}"
12 changes: 8 additions & 4 deletions docker/openssl.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
set -ex

main() {
local cflags=$4 \
os=$2 \
local os=$2 \
triple=$3 \
version=$1

Expand All @@ -22,8 +21,13 @@ main() {
pushd $td
curl https://www.openssl.org/source/openssl-$version.tar.gz | \
tar --strip-components=1 -xz
AR=${triple}ar CC=${triple}gcc ./Configure --prefix=/openssl no-dso $os -fPIC $cflags
nice make -j$(nproc)
AR=${triple}ar CC=${triple}gcc ./Configure \
--prefix=/openssl \
no-dso \
$os \
-fPIC \
${@:4}
nice make -j1
make install

apt-get purge --auto-remove -y ${dependencies[@]}
Expand Down
13 changes: 9 additions & 4 deletions docker/x86_64-unknown-linux-musl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ FROM ubuntu:16.04

RUN apt-get update && \
apt-get install -y --no-install-recommends \
musl-tools && \
ln -s /usr/bin/ar /usr/bin/musl-ar
gcc

COPY musl.sh /
RUN bash /musl.sh 1.1.15
COPY musl-gcc.x86_64-unknown-linux-musl /usr/local/bin/musl-gcc
COPY musl-gcc.specs.x86_64-unknown-linux-musl /usr/local/lib/musl-gcc.specs

COPY openssl.sh /
RUN bash /openssl.sh 1.0.2j linux-x86_64 musl-
RUN bash /openssl.sh 1.0.2j linux-x86_64 musl- -static

RUN apt-get install -y --no-install-recommends \
ca-certificates \
Expand All @@ -15,4 +19,5 @@ RUN apt-get install -y --no-install-recommends \
make \
pkg-config

ENV OPENSSL_DIR=/openssl
ENV CC_i686_unknown_linux_musl=musl-gcc \
OPENSSL_DIR=/openssl
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub enum Target {
Aarch64UnknownLinuxGnu,
Armv7UnknownLinuxGnueabihf,
I686UnknownLinuxGnu,
I686UnknownLinuxMusl,
Mips64UnknownLinuxGnuabi64,
Mips64elUnknownLinuxGnuabi64,
MipsUnknownLinuxGnu,
Expand Down Expand Up @@ -130,6 +131,7 @@ impl Target {
self.is_linux() &&
match *self {
Target::I686UnknownLinuxGnu |
Target::I686UnknownLinuxMusl |
Target::X86_64UnknownLinuxGnu |
Target::X86_64UnknownLinuxMusl => false,
_ => true,
Expand All @@ -144,6 +146,7 @@ impl Target {
Armv7UnknownLinuxGnueabihf => "armv7-unknown-linux-gnueabihf",
I686AppleDarwin => "i686-apple-darwin",
I686UnknownLinuxGnu => "i686-unknown-linux-gnu",
I686UnknownLinuxMusl => "i686-unknown-linux-musl",
Mips64UnknownLinuxGnuabi64 => "mips64-unknown-linux-gnuabi64",
Mips64elUnknownLinuxGnuabi64 => "mips64el-unknown-linux-gnuabi64",
MipsUnknownLinuxGnu => "mips-unknown-linux-gnu",
Expand Down Expand Up @@ -177,6 +180,7 @@ impl<'a> From<&'a str> for Target {
"armv7-unknown-linux-gnueabihf" => Armv7UnknownLinuxGnueabihf,
"i686-apple-darwin" => I686AppleDarwin,
"i686-unknown-linux-gnu" => I686UnknownLinuxGnu,
"i686-unknown-linux-musl" => I686UnknownLinuxMusl,
"mips-unknown-linux-gnu" => MipsUnknownLinuxGnu,
"mips64-unknown-linux-gnuabi64" => Mips64UnknownLinuxGnuabi64,
"mips64el-unknown-linux-gnuabi64" => Mips64elUnknownLinuxGnuabi64,
Expand Down

0 comments on commit 17abfe3

Please sign in to comment.