Skip to content

Commit 0f4b616

Browse files
authored
Add notes for cross-compilation to gcc-only targets (rust-lang#68)
1 parent 48d60ab commit 0f4b616

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Readme.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,21 @@ p loc->m_line
115115
116116
* Build the stage2 compiler (`rustup toolchain link debug-current build/x86_64-unknown-linux-gnu/stage2`).
117117
* Clean and rebuild the codegen with `debug-current` in the file `rust-toolchain`.
118+
119+
### How to build a cross-compiling libgccjit
120+
121+
#### Building libgccjit
122+
123+
* Follow these instructions: https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/ with the following changes:
124+
* Configure gcc with `../gcc/configure --enable-host-shared --disable-multilib --enable-languages=c,jit,c++ --disable-bootstrap --enable-checking=release --prefix=/opt/m68k-gcc/ --target=m68k-linux --without-headers`.
125+
* Some shells, like fish, don't define the environment variable `$MACHTYPE`.
126+
* Add `CFLAGS="-Wno-error=attributes -g -O2"` at the end of the configure command for building glibc (`CFLAGS="-Wno-error=attributes -Wno-error=array-parameter -Wno-error=stringop-overflow -Wno-error=array-bounds -g -O2"` for glibc 2.31, which is useful for Debian).
127+
128+
#### Configuring rustc_codegen_gcc
129+
130+
* Set `TARGET_TRIPLE="m68k-unknown-linux-gnu"` in config.sh.
131+
* Since rustc doesn't support this architecture yet, set it back to `TARGET_TRIPLE="mips-unknown-linux-gnu"` (or another target having the same attributes). Alternatively, create a [target specification file](https://book.avr-rust.com/005.1-the-target-specification-json-file.html) (note that the `arch` specified in this file must be supported by the rust compiler).
132+
* Set `linker='-Clinker=m68k-linux-gcc'`.
133+
* Set the path to the cross-compiling libgccjit in `gcc_path`.
134+
* Disable the 128-bit integer types if the target doesn't support them by using `let i128_type = context.new_type::<i64>();` in `context.rs` (same for u128_type).
135+
* (might not be necessary) Disable the compilation of libstd.so (and possibly libcore.so?).

config.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ fi
2121

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

2626
linker=''
2727
RUN_WRAPPER=''
2828
if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
29-
if [[ "$TARGET_TRIPLE" == "aarch64-unknown-linux-gnu" ]]; then
29+
if [[ "$TARGET_TRIPLE" == "m68k-unknown-linux-gnu" ]]; then
30+
TARGET_TRIPLE="mips-unknown-linux-gnu"
31+
linker='-Clinker=m68k-linux-gcc'
32+
elif [[ "$TARGET_TRIPLE" == "aarch64-unknown-linux-gnu" ]]; then
3033
# We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
3134
linker='-Clinker=aarch64-linux-gnu-gcc'
3235
RUN_WRAPPER='qemu-aarch64 -L /usr/aarch64-linux-gnu'

0 commit comments

Comments
 (0)