Skip to content

Commit

Permalink
Add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
antoyo committed Oct 21, 2023
1 parent 2096606 commit dd73848
Show file tree
Hide file tree
Showing 28 changed files with 533 additions and 318 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: actions/checkout@v3
with:
repository: llvm/llvm-project
path: llvm

- name: Install packages
# `llvm-14-tools` is needed to install the `FileCheck` binary which is used for asm tests.
run: sudo apt-get install ninja-build ripgrep llvm-14-tools
Expand All @@ -68,9 +63,6 @@ jobs:
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
- name: Set RUST_COMPILER_RT_ROOT
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV

- name: Cache cargo installed crates
uses: actions/cache@v3
with:
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/failures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: actions/checkout@v3
with:
repository: llvm/llvm-project
path: llvm

- name: Install packages
run: sudo apt-get install ninja-build ripgrep

Expand All @@ -55,9 +50,6 @@ jobs:
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
- name: Set RUST_COMPILER_RT_ROOT
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV

- name: Cache cargo installed crates
uses: actions/cache@v3
with:
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/gcc12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: actions/checkout@v3
with:
repository: llvm/llvm-project
path: llvm

- name: Install packages
# `llvm-14-tools` is needed to install the `FileCheck` binary which is used for asm tests.
run: sudo apt-get install ninja-build ripgrep llvm-14-tools libgccjit-12-dev
Expand All @@ -55,9 +50,6 @@ jobs:
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
- name: Set RUST_COMPILER_RT_ROOT
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV

- name: Cache cargo installed crates
uses: actions/cache@v3
with:
Expand Down
139 changes: 139 additions & 0 deletions .github/workflows/m68k.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# TODO: check if qemu-user-static-binfmt is needed (perhaps to run some tests since it probably calls exec).

name: m68k CI

on:
- push
- pull_request

permissions:
contents: read

env:
# Enable backtraces for easier debugging
RUST_BACKTRACE: 1
# TODO: remove when confish.sh is removed.
OVERWRITE_TARGET_TRIPLE: m68k-unknown-linux-gnu

jobs:
build:
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
commands: [
"--mini-tests",
"--std-tests",
# TODO(antoyo): fix those on m68k.
#"--test-libcore",
#"--extended-rand-tests",
#"--extended-regex-example-tests",
#"--extended-regex-tests",
#"--test-successful-rustc --nb-parts 2 --current-part 0",
#"--test-successful-rustc --nb-parts 2 --current-part 1",
#"--test-failing-rustc",
]

steps:
- name: Install packages
run: |
sudo apt-get update
sudo apt-get install qemu qemu-user-static
- uses: actions/checkout@v3

- name: Download GCC artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow: m68k.yml
name: gcc-m68k-13
repo: cross-cg-gcc-tools/cross-gcc
branch: master
event: push

- name: Download VM artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow: m68k.yml
name: debian-m68k
repo: cross-cg-gcc-tools/vms
branch: master
event: push

- name: Setup path to libgccjit
run: |
sudo dpkg -i gcc-m68k-13.deb
echo /usr/lib/ > gcc_path
- name: Set env
run: |
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
- name: Cache cargo installed crates
uses: actions/cache@v3
with:
path: ~/.cargo/bin
key: cargo-installed-crates2-ubuntu-latest

#- name: Cache cargo registry
#uses: actions/cache@v3
#with:
#path: ~/.cargo/registry
#key: ${{ runner.os }}-cargo-registry2-${{ hashFiles('**/Cargo.lock') }}

#- name: Cache cargo index
#uses: actions/cache@v3
#with:
#path: ~/.cargo/git
#key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo target dir
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain') }}

#- name: Cache rust repository
## We only clone the rust repository for rustc tests
#if: ${{ contains(matrix.commands, 'rustc') }}
#uses: actions/cache@v3
#id: cache-rust-repository
#with:
#path: rust
#key: ${{ runner.os }}-packages-${{ hashFiles('rust/.git/HEAD') }}

- name: Prepare VM
run: |
mkdir vm
sudo mount debian-m68k.img vm
sudo cp $(which qemu-m68k-static) vm/usr/bin/
- name: Build
run: |
./y.sh prepare --only-libcore --cross
./y.sh build --target-triple m68k-unknown-linux-gnu
CG_GCC_TEST_TARGET=m68k-unknown-linux-gnu cargo test
./clean_all.sh
- name: Prepare dependencies
run: |
git config --global user.email "[email protected]"
git config --global user.name "User"
./y.sh prepare --cross
# Compile is a separate step, as the actions-rs/cargo action supports error annotations
- name: Compile
uses: actions-rs/[email protected]
with:
command: build
args: --release

- name: Add more failing tests because the sysroot is not compiled with LTO
run: cat failing-non-lto-tests.txt >> failing-ui-tests.txt

- name: Run tests
run: |
./test.sh --release --clean --build-sysroot ${{ matrix.commands }}
8 changes: 0 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: actions/checkout@v3
with:
repository: llvm/llvm-project
path: llvm

- name: Install packages
run: sudo apt-get install ninja-build ripgrep

Expand All @@ -56,9 +51,6 @@ jobs:
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
- name: Set RUST_COMPILER_RT_ROOT
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV

- name: Cache cargo installed crates
uses: actions/cache@v3
with:
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/stdarch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: actions/checkout@v3
with:
repository: llvm/llvm-project
path: llvm

- name: Install packages
run: sudo apt-get install ninja-build ripgrep

Expand Down Expand Up @@ -70,9 +65,6 @@ jobs:
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
- name: Set RUST_COMPILER_RT_ROOT
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV

- name: Cache cargo installed crates
uses: actions/cache@v3
with:
Expand Down
37 changes: 21 additions & 16 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ $ make check-jit RUNTESTFLAGS="-v -v -v jit.exp=jit.dg/test-asm.cc"
$ dirname $(readlink -f `find . -name libgccjit.so`) > gcc_path
```

You also need to set RUST_COMPILER_RT_ROOT:

```bash
$ git clone https://github.com/llvm/llvm-project llvm --depth 1 --single-branch
$ export RUST_COMPILER_RT_ROOT="$PWD/llvm/compiler-rt"
```

Then you can run commands like this:

```bash
Expand Down Expand Up @@ -91,9 +84,17 @@ $ CHANNEL="release" $CG_GCCJIT_DIR/cargo.sh run

If you compiled cg_gccjit in debug mode (aka you didn't pass `--release` to `./test.sh`) you should use `CHANNEL="debug"` instead or omit `CHANNEL="release"` completely.

### LTO

To use LTO, you need to set the variable `FAT_LTO=1` and `EMBED_LTO_BITCODE=1` in addition to setting `lto = "fat"` in the `Cargo.toml`.
Don't set `FAT_LTO` when compiling the sysroot, though: only set `EMBED_LTO_BITCODE=1`.

Failing to set `EMBED_LTO_BITCODE` will give you the following error:

```
error: failed to copy bitcode to object file: No such file or directory (os error 2)
```

### Rustc

> You should prefer using the Cargo method.
Expand Down Expand Up @@ -313,16 +314,20 @@ generate it in [gimple.md](./doc/gimple.md).

#### Building libgccjit

* Follow these instructions: https://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/ with the following changes:
* 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`.
* Some shells, like fish, don't define the environment variable `$MACHTYPE`.
* 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).
* Follow the instructions on [this repo](https://github.com/cross-cg-gcc-tools/cross-gcc).

#### Configuring rustc_codegen_gcc

* Set `TARGET_TRIPLE="m68k-unknown-linux-gnu"` in config.sh.
* 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).
* Set `linker='-Clinker=m68k-linux-gcc'`.
* Run `./y.sh prepare --cross` so that the sysroot is patched for the cross-compiling case.
* Set the path to the cross-compiling libgccjit in `gcc_path`.
* Comment the line: `context.add_command_line_option("-masm=intel");` in src/base.rs.
* (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.
* Make sure you have the linker for your target (for instance `m68k-unknown-linux-gnu-gcc`) in your `$PATH`. Specify the target when building the sysroot: `./y.sh build --target-triple m68k-unknown-linux-gnu`.
* Build your project by specifying the target: `OVERWRITE_TARGET_TRIPLE=m68k-unknown-linux-gnu ../cargo.sh build --target m68k-unknown-linux-gnu`.
* If the target is not yet supported by the Rust compiler, 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).

If you get the following error:

```
/usr/bin/ld: unrecognised emulation mode: m68kelf
```

Make sure you set `gcc_path` to the install directory.
5 changes: 4 additions & 1 deletion build_sysroot/build_sysroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ if [[ "$1" == "--release" ]]; then
RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3" cargo build --target $TARGET_TRIPLE --release
else
sysroot_channel='debug'
cargo build --target $TARGET_TRIPLE --features compiler_builtins/c
# TODO: add flags to simplify the case for cross-compilation.
# TODO: or remove them completely if not needed.
#AR="m68k-unknown-linux-gnu-ar" CC="m68k-unknown-linux-gnu-gcc"
cargo build --target $TARGET_TRIPLE
fi

# Copy files to sysroot
Expand Down
Loading

0 comments on commit dd73848

Please sign in to comment.