-
Notifications
You must be signed in to change notification settings - Fork 24
200 lines (179 loc) · 7.56 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: CI
on:
push:
branches:
- main
pull_request:
jobs:
rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
with:
toolchain: stable
- run: cargo fmt --all -- --check
test:
name: Test
runs-on: ${{ matrix.os }}
env:
QEMU_BUILD_VERSION: 8.1.0
strategy:
matrix:
build: [ubuntu, i686-linux, aarch64-linux, riscv64-linux]
include:
- build: ubuntu
os: ubuntu-latest
rust: nightly-2024-10-06
host_target: x86_64-unknown-linux-gnu
mustang_target: x86_64-mustang-linux-gnu
- build: i686-linux
os: ubuntu-latest
rust: nightly-2024-10-06
target: i686-unknown-linux-gnu
gcc_package: gcc-i686-linux-gnu
gcc: i686-linux-gnu-gcc
libc_package: libc-dev-i386-cross
host_target: i686-unknown-linux-gnu
mustang_target: i686-mustang-linux-gnu
- build: aarch64-linux
os: ubuntu-latest
rust: nightly-2024-10-06
target: aarch64-unknown-linux-gnu
gcc_package: gcc-aarch64-linux-gnu
gcc: aarch64-linux-gnu-gcc
qemu: qemu-aarch64 -L /usr/aarch64-linux-gnu
qemu_target: aarch64-linux-user
host_target: aarch64-unknown-linux-gnu
mustang_target: aarch64-mustang-linux-gnu
- build: riscv64-linux
os: ubuntu-latest
rust: nightly-2024-10-06
target: riscv64gc-unknown-linux-gnu
gcc_package: gcc-riscv64-linux-gnu
gcc: riscv64-linux-gnu-gcc
qemu: qemu-riscv64 -L /usr/riscv64-linux-gnu
qemu_target: riscv64-linux-user
host_target: riscv64gc-unknown-linux-gnu
mustang_target: riscv64gc-mustang-linux-gnu
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: ./.github/actions/install-rust
with:
toolchain: ${{ matrix.rust }}
- name: Configure Cargo target
run: |
echo CARGO_BUILD_TARGET=${{ matrix.target }} >> $GITHUB_ENV
rustup target add ${{ matrix.target }}
if: matrix.target != ''
- uses: actions/cache@v4
with:
path: ${{ runner.tool_cache }}/qemu
key: qemu-${{ matrix.target }}-${{ env.QEMU_BUILD_VERSION }}-patched
if: matrix.target != '' && matrix.os == 'ubuntu-latest'
- name: Install cross-compilation tools
run: |
set -ex
sudo apt-get update
sudo apt-get install -y ${{ matrix.gcc_package }} ninja-build
upcase=$(echo ${{ matrix.host_target }} | awk '{ print toupper($0) }' | sed 's/-/_/g')
echo CARGO_TARGET_${upcase}_LINKER=${{ matrix.gcc }} >> $GITHUB_ENV
upcase=$(echo ${{ matrix.mustang_target }} | awk '{ print toupper($0) }' | sed 's/-/_/g')
echo CARGO_TARGET_${upcase}_LINKER=${{ matrix.gcc }} >> $GITHUB_ENV
# Configure the `*-mustang` C compiler for the `cc` crate per
# <https://github.com/sunfishcode/mustang/blob/main/README.md#the-c-runtime>
echo CC_${{ matrix.mustang_target }}=${{ matrix.gcc }} >> $GITHUB_ENV
echo CC_${{ matrix.target }}=${{ matrix.gcc }} >> $GITHUB_ENV
if: matrix.gcc_package != '' && matrix.os == 'ubuntu-latest'
- name: Install cross-compilation libraries
run: |
set -ex
sudo apt-get update
sudo apt-get install -y ${{ matrix.libc_package }}
if: matrix.libc_package != '' && matrix.os == 'ubuntu-latest'
- name: Install qemu
run: |
set -ex
# Configure Cargo for cross compilation and tell it how it can run
# cross executables
upcase=$(echo ${{ matrix.host_target }} | awk '{ print toupper($0) }' | sed 's/-/_/g')
echo CARGO_TARGET_${upcase}_RUNNER=${{ runner.tool_cache }}/qemu/bin/${{ matrix.qemu }} >> $GITHUB_ENV
upcase=$(echo ${{ matrix.mustang_target }} | awk '{ print toupper($0) }' | sed 's/-/_/g')
echo CARGO_TARGET_${upcase}_RUNNER=${{ runner.tool_cache }}/qemu/bin/${{ matrix.qemu }} >> $GITHUB_ENV
# See if qemu is already in the cache
if [ -f ${{ runner.tool_cache }}/qemu/bin/${{ matrix.qemu }} ]; then
exit 0
fi
# Download and build qemu from source since the most recent release is
# way faster at arm emulation than the current version github actions'
# ubuntu image uses. Disable as much as we can to get it to build
# quickly.
cd
curl https://download.qemu.org/qemu-$QEMU_BUILD_VERSION.tar.xz | tar xJf -
cd qemu-$QEMU_BUILD_VERSION
patch -p1 < $GITHUB_WORKSPACE/ci/translate-errno.patch
patch -p1 < $GITHUB_WORKSPACE/ci/getsockopt-timeouts.patch
patch -p1 < $GITHUB_WORKSPACE/ci/s390x-stat-have-nsec.patch
patch -p1 < $GITHUB_WORKSPACE/ci/aarch64-o-largefile.patch
patch -p1 < $GITHUB_WORKSPACE/ci/tcgets2-tcsets2.patch
./configure --target-list=${{ matrix.qemu_target }} --prefix=${{ runner.tool_cache }}/qemu --disable-tools --disable-slirp --disable-fdt --disable-capstone --disable-docs
ninja -C build install
if: matrix.qemu != '' && matrix.os == 'ubuntu-latest'
- name: Install rust-src
run: |
rustup component add rust-src --toolchain nightly-2024-10-06-x86_64-unknown-linux-gnu
- name: cargo check non-mustang
run: |
# Check that the code compiles on non-mustang targets.
cargo +nightly-2024-10-06 check --all --target=${{ matrix.host_target }}
- name: cargo test
run: |
cargo +nightly-2024-10-06 test --verbose -Z build-std --target=target-specs/${{ matrix.mustang_target }}.json -- ${{ matrix.test_args }} -- --nocapture
env:
RUST_BACKTRACE: 1
- name: cargo test --release
run: |
cargo +nightly-2024-10-06 test --verbose --release -Z build-std --target=target-specs/${{ matrix.mustang_target }}.json -- ${{ matrix.test_args }}
env:
RUST_BACKTRACE: 1
- name: test mustang-example in mustang mode
working-directory: example-crates/mustang-example
run: |
cargo run -Z build-std --target=../../target-specs/${{ matrix.mustang_target }}.json
env:
RUST_BACKTRACE: 1
- name: test mustang-example in non-mustang mode
working-directory: example-crates/mustang-example
run: |
cargo run --target=${{ matrix.host_target }}
env:
RUST_BACKTRACE: 1
- name: test mustang-example-lto
working-directory: example-crates/mustang-example-lto
run: |
cargo run -Z build-std --target=../../target-specs/${{ matrix.mustang_target }}.json --release
env:
RUST_BACKTRACE: 1
- name: test mustang-nostd as program
working-directory: example-crates/mustang-nostd
run: |
cargo +nightly-2024-10-06 run -Zbuild-std=core,alloc --target=../../target-specs/${{ matrix.mustang_target }}.json
env:
RUST_BACKTRACE: 1
- name: test mustang-nostd as tests
working-directory: example-crates/mustang-nostd
run: |
cargo +nightly-2024-10-06 test -Zbuild-std=core,alloc,test,std --target=../../target-specs/${{ matrix.mustang_target }}.json
env:
RUST_BACKTRACE: 1
- name: test mustang-custom-allocator as tests
working-directory: example-crates/mustang-custom-allocator
run: |
cargo +nightly-2024-10-06 run -Zbuild-std --target=../../target-specs/${{ matrix.mustang_target }}.json
env:
RUST_BACKTRACE: 1