Skip to content

Commit 3359da9

Browse files
authored
Add support for riscv64gc-unknown-linux-musl target (#182)
* Add support for riscv64gc-unknown-linux-musl target * fix * Try build mips with Rust stable * CI-no-fail-fast * Don't fail fast * Update test crate * Disable mips* targets * Use 2021 edition for custom std * Disable riscv64 test cargo build openssl doesn't build
1 parent 02d4d27 commit 3359da9

File tree

9 files changed

+949
-572
lines changed

9 files changed

+949
-572
lines changed

.github/workflows/Build.yml

Lines changed: 40 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
on:
2-
push:
3-
branches:
4-
# for bors r+
5-
- staging
6-
# for bors try
7-
- trying
2+
pull_request:
83
workflow_dispatch:
94
inputs:
105
no_cache:
116
description: Disable Docker cache, yes/no
12-
default: 'no'
7+
default: "no"
138
required: false
149
toolchain:
1510
description: Rust toolchain to install
16-
default: 'stable'
11+
default: "stable"
1712
required: false
1813
arch:
1914
description: Architectures to build for
20-
default: ''
15+
default: ""
2116
required: false
2217
schedule:
23-
- cron: '0 0 1 */2 *'
18+
- cron: "0 0 1 */2 *"
2419

2520
name: Build
2621

@@ -48,11 +43,7 @@ jobs:
4843
const archMatrix = yaml.load(process.env.ARCH_MATRIX)
4944
const targetMatrix = yaml.load(process.env.TARGET_MATRIX)
5045
51-
if (context.eventName == 'schedule') {
52-
// Always run on schedule
53-
core.setOutput('arch', JSON.stringify(archMatrix))
54-
core.setOutput('target', JSON.stringify(targetMatrix))
55-
} else if (context.eventName == 'workflow_dispatch') {
46+
if (context.eventName == 'workflow_dispatch') {
5647
let outputArchMatrix = []
5748
let outputTargetMatrix = []
5849
const dockerArch = context.payload.inputs.arch.split(',')
@@ -75,84 +66,10 @@ jobs:
7566
core.setOutput('arch', JSON.stringify(outputArchMatrix))
7667
core.setOutput('target', JSON.stringify(outputTargetMatrix))
7768
core.setOutput('fail-fast', 'false')
78-
} else if (context.eventName == 'push') {
79-
const commitMessage = process.env.COMMIT_MESSAGE.trim()
80-
if (commitMessage.length > 0) {
81-
let outputArchMatrix = []
82-
let outputTargetMatrix = []
83-
84-
let borsArgs
85-
if (commitMessage.startsWith('Try #')) {
86-
borsArgs = commitMessage.replace(/Try #[0-9]+:/i, '').trim()
87-
} else {
88-
// Merge example commit message:
89-
// Merge #64
90-
//
91-
// 64: Refine bors command r=messense a=messense
92-
//
93-
// bors: amd64 --target aarch64
94-
//
95-
// Co-authored-by: messense <messense@icloud.com>
96-
//
97-
borsArgs = commitMessage
98-
.split('\n')
99-
.filter(item => item.trim().startsWith('bors:'))
100-
.join('\n')
101-
.trim()
102-
}
103-
const targetIndex = borsArgs.indexOf('--target')
104-
let dockerArch = []
105-
let targets = []
106-
107-
if (targetIndex === -1) {
108-
dockerArch = borsArgs.trim().split(' ').filter(x => x.length > 0)
109-
targets = []
110-
} else {
111-
dockerArch = borsArgs.substring(0, targetIndex).trim().split(' ').filter(x => x.length > 0)
112-
targets = borsArgs.substring(targetIndex + '--target'.length).trim().split(' ')
113-
}
114-
if (dockerArch.length === 0) {
115-
// Defaults to all arches
116-
outputArchMatrix = archMatrix
117-
} else {
118-
for (const arch of dockerArch) {
119-
outputArchMatrix.push(...archMatrix.filter(item => item.arch == arch))
120-
}
121-
}
122-
if (targets.length === 0) {
123-
// Defaults to all targets
124-
outputTargetMatrix = targetMatrix
125-
} else {
126-
for (const target of targets) {
127-
outputTargetMatrix.push(...targetMatrix.filter(item => item.TARGET.startsWith(target)))
128-
}
129-
}
130-
131-
core.setOutput('arch', JSON.stringify(outputArchMatrix))
132-
core.setOutput('target', JSON.stringify(outputTargetMatrix))
133-
} else {
134-
core.setOutput('arch', JSON.stringify(archMatrix))
135-
core.setOutput('target', JSON.stringify(targetMatrix))
136-
core.setOutput('run-build', 'false')
137-
}
138-
139-
const matches = commitMessage.match(/(Try|Merge) #([0-9]+):/)
140-
if (matches) {
141-
const prNumber = matches[2]
142-
const { data: { labels: labels } } = await github.rest.pulls.get({
143-
owner: context.repo.owner,
144-
repo: context.repo.repo,
145-
pull_number: prNumber
146-
})
147-
const labelNames = labels.map(label => label.name)
148-
if (labelNames.includes('CI-no-fail-fast')) {
149-
core.setOutput('fail-fast', 'false')
150-
}
151-
}
15269
} else {
15370
core.setOutput('arch', JSON.stringify(archMatrix))
15471
core.setOutput('target', JSON.stringify(targetMatrix))
155-
core.setOutput('run-build', 'false')
72+
core.setOutput('fail-fast', 'false')
15673
}
15774
- name: Show build matrix
15875
run: |
@@ -170,11 +87,11 @@ jobs:
17087
}}
17188
ARCH_MATRIX: |
17289
- arch: amd64
173-
runner: [ubuntu-latest]
90+
runner: ubuntu-latest
17491
- arch: arm64
175-
runner: [self-hosted, ARM64]
92+
runner: ubuntu-24.04-arm
17693
- arch: armv7
177-
runner: [self-hosted, ARM64]
94+
runner: ubuntu-24.04-arm
17895
docker_arch: arm/v7
17996
TARGET_MATRIX: |
18097
- IMAGE_TAG: aarch64-musl
@@ -213,26 +130,31 @@ jobs:
213130
TARGET: powerpc64le-unknown-linux-musl
214131
RUST_MUSL_MAKE_CONFIG: config.mak
215132
TOOLCHAIN: stable
216-
- IMAGE_TAG: mips-musl
217-
TARGET: mips-unknown-linux-musl
218-
RUST_MUSL_MAKE_CONFIG: config.mak
219-
TOOLCHAIN: nightly
220-
- IMAGE_TAG: mips64-muslabi64
221-
TARGET: mips64-unknown-linux-muslabi64
222-
RUST_MUSL_MAKE_CONFIG: config.mak
223-
TOOLCHAIN: nightly
224-
- IMAGE_TAG: mips64el-muslabi64
225-
TARGET: mips64el-unknown-linux-muslabi64
226-
RUST_MUSL_MAKE_CONFIG: config.mak
227-
TOOLCHAIN: nightly
228-
- IMAGE_TAG: mipsel-musl
229-
TARGET: mipsel-unknown-linux-musl
230-
RUST_MUSL_MAKE_CONFIG: config.mak
231-
TOOLCHAIN: nightly
133+
# - IMAGE_TAG: mips-musl
134+
# TARGET: mips-unknown-linux-musl
135+
# RUST_MUSL_MAKE_CONFIG: config.mak
136+
# TOOLCHAIN: stable
137+
# - IMAGE_TAG: mips64-muslabi64
138+
# TARGET: mips64-unknown-linux-muslabi64
139+
# RUST_MUSL_MAKE_CONFIG: config.mak
140+
# TOOLCHAIN: stable
141+
# - IMAGE_TAG: mips64el-muslabi64
142+
# TARGET: mips64el-unknown-linux-muslabi64
143+
# RUST_MUSL_MAKE_CONFIG: config.mak
144+
# TOOLCHAIN: stable
145+
# - IMAGE_TAG: mipsel-musl
146+
# TARGET: mipsel-unknown-linux-musl
147+
# RUST_MUSL_MAKE_CONFIG: config.mak
148+
# TOOLCHAIN: stable
232149
- IMAGE_TAG: s390x-musl
233150
TARGET: s390x-unknown-linux-musl
234151
RUST_MUSL_MAKE_CONFIG: config.mak
235152
TOOLCHAIN: nightly
153+
- IMAGE_TAG: riscv64gc-musl
154+
TARGET: riscv64gc-unknown-linux-musl
155+
MUSL_TARGET: riscv64-unknown-linux-musl
156+
RUST_MUSL_MAKE_CONFIG: config.mak
157+
TOOLCHAIN: stable
236158
- IMAGE_TAG: x86_64-musl
237159
TARGET: x86_64-unknown-linux-musl
238160
RUST_MUSL_MAKE_CONFIG: config.mak
@@ -251,11 +173,6 @@ jobs:
251173
env: ${{ matrix.env }}
252174
steps:
253175
- uses: actions/checkout@v4
254-
- name: Setup QEMU
255-
uses: dbhi/qus/action@main
256-
if: ${{ contains(matrix.os.runner, 'ubuntu-latest') }}
257-
- name: Setup Docker Buildx
258-
uses: docker/setup-buildx-action@v3
259176
- name: Login to DockerHub
260177
if: ${{ github.repository_owner == 'rust-cross' }}
261178
uses: docker/login-action@v3
@@ -268,12 +185,17 @@ jobs:
268185
registry: ghcr.io
269186
username: ${{ github.repository_owner }}
270187
password: ${{ secrets.GITHUB_TOKEN }}
188+
- name: Setup QEMU
189+
uses: docker/setup-qemu-action@v3
190+
- name: Setup Docker Buildx
191+
uses: docker/setup-buildx-action@v3
271192
- name: docker build
272193
uses: docker/build-push-action@v6
273194
with:
274195
platforms: linux/${{ matrix.os.docker_arch || matrix.os.arch }}
275196
build-args: |
276197
TARGET=${{ matrix.env.TARGET }}
198+
MUSL_TARGET=${{ matrix.env.MUSL_TARGET || matrix.env.TARGET }}
277199
RUST_MUSL_MAKE_CONFIG=${{ matrix.env.RUST_MUSL_MAKE_CONFIG }}
278200
TOOLCHAIN=${{ matrix.env.TOOLCHAIN }}
279201
tags: ghcr.io/${{ github.repository_owner }}/rust-musl-cross:${{ matrix.env.IMAGE_TAG }}-${{ matrix.os.arch }}
@@ -283,12 +205,13 @@ jobs:
283205
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/rust-musl-cross:buildcache-${{ matrix.env.IMAGE_TAG }}-${{ matrix.os.arch }}
284206
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/rust-musl-cross:buildcache-${{ matrix.env.IMAGE_TAG }}-${{ matrix.os.arch }},mode=max
285207
- name: Test Docker cargo build
286-
if: ${{ matrix.os.arch == 'amd64' && !startsWith(matrix.env.TARGET, 'armv5te') && !startsWith(matrix.env.TARGET, 's390x') }}
208+
if: ${{ matrix.os.arch == 'amd64' && !startsWith(matrix.env.TARGET, 'armv5te') && !startsWith(matrix.env.TARGET, 's390x') && !startsWith(matrix.env.TARGET, 'riscv64') }}
287209
run: |
288210
docker run --rm \
289211
-v "$(pwd)/tests":/home/rust/src \
290212
ghcr.io/${{ github.repository_owner }}/rust-musl-cross:$IMAGE_TAG-${{ matrix.os.arch }} bash -c "cargo build"
291213
- name: Build and push multiarch image
214+
if: ${{ github.event_name != 'pull_request' }}
292215
env:
293216
DOCKER_CLI_EXPERIMENTAL: enabled
294217
run: |
@@ -330,12 +253,12 @@ jobs:
330253
sed -n '1d;p' ghcr-manifest.yaml >> ghcr-manifest-target.yaml
331254
./manifest-tool push from-spec ghcr-manifest-target.yaml
332255
- name: Sync images to Docker Hub
333-
if: ${{ github.repository_owner == 'rust-cross' }}
256+
if: ${{ github.repository_owner == 'rust-cross' && github.event_name != 'pull_request' }}
334257
env:
335258
DOCKER_CLI_EXPERIMENTAL: enabled
336259
run: |
337260
set -e
338-
261+
339262
echo "image: ${{ secrets.DOCKER_USERNAME }}/rust-musl-cross:$IMAGE_TAG
340263
manifests:" > dockerhub-manifest.yaml
341264

Dockerfile

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,45 @@ ENV DEBIAN_FRONTEND=noninteractive
88
#
99
RUN apt-get update && \
1010
apt-get install -y \
11-
build-essential \
12-
cmake \
13-
curl \
14-
file \
15-
git \
16-
sudo \
17-
xutils-dev \
18-
unzip \
19-
ca-certificates \
20-
python3 \
21-
python3-pip \
22-
autoconf \
23-
autoconf-archive \
24-
automake \
25-
flex \
26-
bison \
27-
llvm-dev \
28-
libclang-dev \
29-
clang \
30-
&& \
11+
build-essential \
12+
cmake \
13+
curl \
14+
file \
15+
git \
16+
sudo \
17+
xutils-dev \
18+
unzip \
19+
ca-certificates \
20+
python3 \
21+
python3-pip \
22+
autoconf \
23+
autoconf-archive \
24+
automake \
25+
flex \
26+
bison \
27+
llvm-dev \
28+
libclang-dev \
29+
clang \
30+
&& \
3131
apt-get clean && rm -rf /var/lib/apt/lists/*
3232

3333
# Install Let's Encrypt R3 CA certificate from https://letsencrypt.org/certificates/
3434
COPY lets-encrypt-r3.crt /usr/local/share/ca-certificates
3535
RUN update-ca-certificates
3636

3737
ARG TARGET=x86_64-unknown-linux-musl
38-
ENV RUST_MUSL_CROSS_TARGET=$TARGET
38+
ARG MUSL_TARGET=$TARGET
39+
ENV RUST_MUSL_CROSS_TARGET=$MUSL_TARGET
3940
ARG RUST_MUSL_MAKE_CONFIG=config.mak
4041

4142
COPY $RUST_MUSL_MAKE_CONFIG /tmp/config.mak
42-
# Fix the cfi detection script in musl's configure so cfi is generated
43-
# when debug info is asked for. This patch is derived from
44-
# https://git.musl-libc.org/cgit/musl/commit/?id=c4d4028dde90562f631edf559fbc42d8ec1b29de.
45-
# When we upgrade to a version that includes this commit, we can remove the patch.
46-
COPY musl-patch-configure.diff /tmp/musl-patch-configure.diff
4743

4844
RUN cd /tmp && \
4945
git clone --depth 1 https://github.com/richfelker/musl-cross-make.git && \
5046
cp /tmp/config.mak /tmp/musl-cross-make/config.mak && \
5147
cd /tmp/musl-cross-make && \
52-
mkdir -p patches/musl-1.1.24 && \
53-
cp /tmp/musl-patch-configure.diff patches/musl-1.1.24/0001-fix-cfi-detection.diff && \
5448
export CFLAGS="-fPIC -g1 $CFLAGS" && \
55-
export TARGET=$TARGET && \
49+
export TARGET=$MUSL_TARGET && \
5650
if [ `dpkg --print-architecture` = 'armhf' ] && [ `uname -m` = 'aarch64' ]; then SETARCH=linux32; else SETARCH= ; fi && \
5751
$SETARCH make -j$(nproc) > /tmp/musl-cross-make.log && \
5852
$SETARCH make install >> /tmp/musl-cross-make.log && \
@@ -65,11 +59,11 @@ RUN mkdir -p /home/rust/libs /home/rust/src
6559
# Set up our path with all our binary directories, including those for the
6660
# musl-gcc toolchain and for our Rust toolchain.
6761
ENV PATH=/root/.cargo/bin:/usr/local/musl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
68-
ENV TARGET_CC=$TARGET-gcc
69-
ENV TARGET_CXX=$TARGET-g++
70-
ENV TARGET_AR=$TARGET-ar
71-
ENV TARGET_RANLIB=$TARGET-ranlib
72-
ENV TARGET_HOME=/usr/local/musl/$TARGET
62+
ENV TARGET_CC=$MUSL_TARGET-gcc
63+
ENV TARGET_CXX=$MUSL_TARGET-g++
64+
ENV TARGET_AR=$MUSL_TARGET-ar
65+
ENV TARGET_RANLIB=$MUSL_TARGET-ranlib
66+
ENV TARGET_HOME=/usr/local/musl/$MUSL_TARGET
7367
ENV TARGET_C_INCLUDE_PATH=$TARGET_HOME/include/
7468

7569
# pkg-config cross compilation support
@@ -117,7 +111,7 @@ RUN chmod 755 /root/ && \
117111
rustup component add --toolchain $TOOLCHAIN rustfmt clippy && \
118112
rm -rf /root/.rustup/toolchains/$TOOLCHAIN-$GNU_TARGET/share/
119113

120-
RUN echo "[target.$TARGET]\nlinker = \"$TARGET-gcc\"\n" > /root/.cargo/config.toml
114+
RUN echo "[target.$TARGET]\nlinker = \"$TARGET_CC\"\n" > /root/.cargo/config.toml
121115

122116
# Build std sysroot for targets that doesn't have official std release
123117
ADD Xargo.toml /tmp/Xargo.toml

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ Currently we have the following [prebuilt Docker images on Docker Hub](https://h
2424
| stable | armv7-unknown-linux-musleabihf | armv7-musleabihf |
2525
| stable | i586-unknown-linux-musl | i586-musl |
2626
| stable | i686-unknown-linux-musl | i686-musl |
27-
| nightly | mips-unknown-linux-musl | mips-musl |
28-
| nightly | mipsel-unknown-linux-musl | mipsel-musl |
29-
| nightly | mips64-unknown-linux-muslabi64 | mips64-muslabi64 |
30-
| nightly | mips64el-unknown-linux-muslabi64 | mips64el-muslabi64 |
27+
| stable | mips-unknown-linux-musl | mips-musl |
28+
| stable | mipsel-unknown-linux-musl | mipsel-musl |
29+
| stable | mips64-unknown-linux-muslabi64 | mips64-muslabi64 |
30+
| stable | mips64el-unknown-linux-muslabi64 | mips64el-muslabi64 |
3131
| stable | powerpc64le-unknown-linux-musl | powerpc64le-musl |
3232
| stable | x86\_64-unknown-linux-musl | x86\_64-musl |
3333

build-std.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
set -e
3-
if [[ "$TOOLCHAIN" = "nightly" && ("$TARGET" =~ ^mips || "$TARGET" =~ ^s390x) ]]
3+
if [[ "$TOOLCHAIN" = "nightly" && ("$TARGET" =~ ^s390x) ]]
44
then
55
export CARGO_NET_GIT_FETCH_WITH_CLI=true
66
export CARGO_UNSTABLE_SPARSE_REGISTRY=true
@@ -15,7 +15,7 @@ then
1515
fi
1616

1717
cargo install xargo --git https://github.com/AverseABFun/xargo.git
18-
cargo new --lib custom-std
18+
cargo new --lib --edition 2021 custom-std
1919
cd custom-std
2020
cp /tmp/Xargo.toml .
2121
rustc -Z unstable-options --print target-spec-json --target "$TARGET" | tee "$TARGET.json"

0 commit comments

Comments
 (0)