Skip to content

Commit 580b6e3

Browse files
committed
WIP
1 parent 73ee3e7 commit 580b6e3

File tree

7 files changed

+174
-11
lines changed

7 files changed

+174
-11
lines changed

.github/workflows/m68k.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# How to chroot with qemu into a Debian created with debootstrap: https://unix.stackexchange.com/questions/41889/how-can-i-chroot-into-a-filesystem-with-a-different-architechture
2+
# Commands need to be run inside qemu-m68k-static, e.g. qemu-m68k-static /usr/bin/ls.
3+
#
4+
# TODO: check if qemu-user-static-binfmt is needed (perhaps to run some tests since it probably calls exec).
5+
6+
name: m68k CI
7+
8+
on:
9+
- push
10+
- pull_request
11+
12+
permissions:
13+
contents: read
14+
15+
env:
16+
# Enable backtraces for easier debugging
17+
RUST_BACKTRACE: 1
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-22.04
22+
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
commands: [
27+
"--mini-tests",
28+
"--std-tests",
29+
"--test-libcore",
30+
"--extended-rand-tests",
31+
"--extended-regex-example-tests",
32+
"--extended-regex-tests",
33+
"--test-successful-rustc --nb-parts 2 --current-part 0",
34+
"--test-successful-rustc --nb-parts 2 --current-part 1",
35+
"--test-failing-rustc",
36+
]
37+
38+
steps:
39+
- name: Install packages
40+
run: sudo apt-get install qemu
41+
42+
- uses: actions/checkout@v3
43+
44+
- uses: actions/checkout@v3
45+
with:
46+
repository: llvm/llvm-project
47+
path: llvm
48+
49+
- name: Download GCC artifact
50+
uses: dawidd6/action-download-artifact@v2
51+
with:
52+
workflow: m68k.yml
53+
name: gcc-m68k-13
54+
repo: cross-cg-gcc-tools/cross-gcc
55+
branch: master
56+
event: push
57+
58+
- name: Download VM artifact
59+
uses: dawidd6/action-download-artifact@v2
60+
with:
61+
workflow: m68k.yml
62+
name: debian-m68k
63+
repo: cross-cg-gcc-tools/vms
64+
branch: master
65+
event: push
66+
67+
- name: Setup path to libgccjit
68+
run: |
69+
sudo dpkg -i gcc-m68k-13.deb
70+
ls /lib
71+
echo "*********************"
72+
ls /usr/lib
73+
echo /usr/lib/ > gcc_path
74+
75+
- name: Set env
76+
run: |
77+
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
78+
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
79+
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
80+
81+
- name: Set RUST_COMPILER_RT_ROOT
82+
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV
83+
84+
- name: Cache cargo installed crates
85+
uses: actions/cache@v3
86+
with:
87+
path: ~/.cargo/bin
88+
key: cargo-installed-crates2-ubuntu-latest
89+
90+
- name: Cache cargo registry
91+
uses: actions/cache@v3
92+
with:
93+
path: ~/.cargo/registry
94+
key: ${{ runner.os }}-cargo-registry2-${{ hashFiles('**/Cargo.lock') }}
95+
96+
- name: Cache cargo index
97+
uses: actions/cache@v3
98+
with:
99+
path: ~/.cargo/git
100+
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
101+
102+
- name: Cache cargo target dir
103+
uses: actions/cache@v3
104+
with:
105+
path: target
106+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain') }}
107+
108+
#- name: Cache rust repository
109+
## We only clone the rust repository for rustc tests
110+
#if: ${{ contains(matrix.commands, 'rustc') }}
111+
#uses: actions/cache@v3
112+
#id: cache-rust-repository
113+
#with:
114+
#path: rust
115+
#key: ${{ runner.os }}-packages-${{ hashFiles('rust/.git/HEAD') }}
116+
117+
- name: Test build (TODO REMOVE)
118+
run: |
119+
cat > main.c <<EOF
120+
int main(void) {
121+
printf("Hello, world!");
122+
}
123+
EOF
124+
mkdir vm
125+
sudo mount debian-m68k.img vm
126+
m68k-unknown-linux-gnu-gcc main.c -o vm/home/main
127+
sudo chroot vm/ qemu-m68k-static /home/main
128+
129+
- name: Build
130+
run: |
131+
./y.sh prepare --only-libcore
132+
./build.sh
133+
cargo test
134+
./clean_all.sh
135+
136+
- name: Prepare dependencies
137+
run: |
138+
git config --global user.email "[email protected]"
139+
git config --global user.name "User"
140+
./y.sh prepare
141+
142+
# Compile is a separate step, as the actions-rs/cargo action supports error annotations
143+
- name: Compile
144+
uses: actions-rs/[email protected]
145+
with:
146+
command: build
147+
args: --release
148+
149+
- name: Add more failing tests because the sysroot is not compiled with LTO
150+
run: cat failing-non-lto-tests.txt >> failing-ui-tests.txt
151+
152+
- name: Run tests
153+
run: |
154+
./test.sh --release --clean --build-sysroot

Readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,3 +334,11 @@ generate it in [gimple.md](./doc/gimple.md).
334334
* Set the path to the cross-compiling libgccjit in `gcc_path`.
335335
* Comment the line: `context.add_command_line_option("-masm=intel");` in src/base.rs.
336336
* (might not be necessary) Disable the compilation of libstd.so (and possibly libcore.so?): Remove dylib from build_sysroot/sysroot_src/library/std/Cargo.toml.
337+
338+
If you get the following error:
339+
340+
```
341+
/usr/bin/ld: unrecognised emulation mode: m68kelf
342+
```
343+
344+
Make sure you set `gcc_path` to the install directory.

config.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ else
2020
fi
2121

2222
HOST_TRIPLE=$(rustc -vV | grep host | cut -d: -f2 | tr -d " ")
23-
TARGET_TRIPLE=$HOST_TRIPLE
24-
#TARGET_TRIPLE="m68k-unknown-linux-gnu"
23+
#TARGET_TRIPLE=$HOST_TRIPLE
24+
TARGET_TRIPLE="m68k-unknown-linux-gnu"
2525

2626
linker=''
2727
RUN_WRAPPER=''
2828
if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
2929
if [[ "$TARGET_TRIPLE" == "m68k-unknown-linux-gnu" ]]; then
30-
TARGET_TRIPLE="mips-unknown-linux-gnu"
30+
#TARGET_TRIPLE="mips-unknown-linux-gnu"
3131
linker='-Clinker=m68k-linux-gcc'
3232
elif [[ "$TARGET_TRIPLE" == "aarch64-unknown-linux-gnu" ]]; then
3333
# We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
@@ -60,4 +60,5 @@ export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH
6060
# NOTE: To avoid the -fno-inline errors, use /opt/gcc/bin/gcc instead of cc.
6161
# To do so, add a symlink for cc to /opt/gcc/bin/gcc in our PATH.
6262
# Another option would be to add the following Rust flag: -Clinker=/opt/gcc/bin/gcc
63-
export PATH="/opt/gcc/bin:$PATH"
63+
export PATH="/opt/m68k-gcc/bin:$PATH"
64+
export TARGET=$TARGET_TRIPLE

src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol, target_info: Lock
9999
.collect();
100100

101101
// TODO(antoyo): only set on x86 platforms.
102-
context.add_command_line_option("-masm=intel");
102+
//context.add_command_line_option("-masm=intel");
103103

104104
if !disabled_features.contains("avx") {
105105
// NOTE: we always enable AVX because the equivalent of llvm.x86.sse2.cmp.pd in GCC for

src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12241224
#[cfg(feature="master")]
12251225
{
12261226
let personality = self.rvalue_as_function(_personality);
1227-
self.current_func().set_personality_function(personality);
1227+
//self.current_func().set_personality_function(personality);
12281228
}
12291229
}
12301230

src/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
187187
let ulonglong_type = context.new_c_type(CType::ULongLong);
188188
let sizet_type = context.new_c_type(CType::SizeT);
189189

190-
let isize_type = context.new_c_type(CType::LongLong);
191-
let usize_type = context.new_c_type(CType::ULongLong);
190+
let isize_type = context.new_c_type(CType::Int);
191+
let usize_type = context.new_c_type(CType::UInt);
192192
let bool_type = context.new_type::<bool>();
193193

194194
// TODO(antoyo): only have those assertions on x86_64.
195-
assert_eq!(isize_type.get_size(), i64_type.get_size());
196-
assert_eq!(usize_type.get_size(), u64_type.get_size());
195+
/*assert_eq!(isize_type.get_size(), i64_type.get_size());
196+
assert_eq!(usize_type.get_size(), u64_type.get_size());*/
197197

198198
let mut functions = FxHashMap::default();
199199
let builtins = [

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
242242
};
243243

244244
// TODO(antoyo): only set for x86.
245-
mods.context.add_command_line_option("-masm=intel");
245+
//mods.context.add_command_line_option("-masm=intel");
246246
unsafe { allocator::codegen(tcx, &mut mods, module_name, kind, alloc_error_handler_kind); }
247247
mods
248248
}

0 commit comments

Comments
 (0)