Skip to content

Commit 16b3da8

Browse files
authored
Merge pull request #346 from rust-lang/fix/endianness
Fix/endianness
2 parents 2096606 + 7425c56 commit 16b3da8

28 files changed

+523
-333
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ jobs:
3737
steps:
3838
- uses: actions/checkout@v3
3939

40-
- uses: actions/checkout@v3
41-
with:
42-
repository: llvm/llvm-project
43-
path: llvm
44-
4540
- name: Install packages
4641
# `llvm-14-tools` is needed to install the `FileCheck` binary which is used for asm tests.
4742
run: sudo apt-get install ninja-build ripgrep llvm-14-tools
@@ -68,9 +63,6 @@ jobs:
6863
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
6964
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
7065
71-
- name: Set RUST_COMPILER_RT_ROOT
72-
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV
73-
7466
- name: Cache cargo installed crates
7567
uses: actions/cache@v3
7668
with:

.github/workflows/failures.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ jobs:
2525
steps:
2626
- uses: actions/checkout@v3
2727

28-
- uses: actions/checkout@v3
29-
with:
30-
repository: llvm/llvm-project
31-
path: llvm
32-
3328
- name: Install packages
3429
run: sudo apt-get install ninja-build ripgrep
3530

@@ -55,9 +50,6 @@ jobs:
5550
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
5651
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
5752
58-
- name: Set RUST_COMPILER_RT_ROOT
59-
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV
60-
6153
- name: Cache cargo installed crates
6254
uses: actions/cache@v3
6355
with:

.github/workflows/gcc12.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ jobs:
3737
steps:
3838
- uses: actions/checkout@v3
3939

40-
- uses: actions/checkout@v3
41-
with:
42-
repository: llvm/llvm-project
43-
path: llvm
44-
4540
- name: Install packages
4641
# `llvm-14-tools` is needed to install the `FileCheck` binary which is used for asm tests.
4742
run: sudo apt-get install ninja-build ripgrep llvm-14-tools libgccjit-12-dev
@@ -55,9 +50,6 @@ jobs:
5550
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
5651
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
5752
58-
- name: Set RUST_COMPILER_RT_ROOT
59-
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV
60-
6153
- name: Cache cargo installed crates
6254
uses: actions/cache@v3
6355
with:

.github/workflows/m68k.yml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# TODO: check if qemu-user-static-binfmt is needed (perhaps to run some tests since it probably calls exec).
2+
3+
name: m68k CI
4+
5+
on:
6+
- push
7+
- pull_request
8+
9+
permissions:
10+
contents: read
11+
12+
env:
13+
# Enable backtraces for easier debugging
14+
RUST_BACKTRACE: 1
15+
# TODO: remove when confish.sh is removed.
16+
OVERWRITE_TARGET_TRIPLE: m68k-unknown-linux-gnu
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-22.04
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
commands: [
26+
"--mini-tests",
27+
"--std-tests",
28+
# TODO(antoyo): fix those on m68k.
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: |
41+
sudo apt-get update
42+
sudo apt-get install qemu qemu-user-static
43+
44+
- uses: actions/checkout@v3
45+
46+
- name: Download GCC artifact
47+
uses: dawidd6/action-download-artifact@v2
48+
with:
49+
workflow: m68k.yml
50+
name: gcc-m68k-13
51+
repo: cross-cg-gcc-tools/cross-gcc
52+
branch: master
53+
event: push
54+
55+
- name: Download VM artifact
56+
uses: dawidd6/action-download-artifact@v2
57+
with:
58+
workflow: m68k.yml
59+
name: debian-m68k
60+
repo: cross-cg-gcc-tools/vms
61+
branch: master
62+
event: push
63+
64+
- name: Setup path to libgccjit
65+
run: |
66+
sudo dpkg -i gcc-m68k-13.deb
67+
echo /usr/lib/ > gcc_path
68+
69+
- name: Set env
70+
run: |
71+
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
72+
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
73+
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
74+
75+
- name: Cache cargo installed crates
76+
uses: actions/cache@v3
77+
with:
78+
path: ~/.cargo/bin
79+
key: cargo-installed-crates2-ubuntu-latest
80+
81+
#- name: Cache cargo registry
82+
#uses: actions/cache@v3
83+
#with:
84+
#path: ~/.cargo/registry
85+
#key: ${{ runner.os }}-cargo-registry2-${{ hashFiles('**/Cargo.lock') }}
86+
87+
#- name: Cache cargo index
88+
#uses: actions/cache@v3
89+
#with:
90+
#path: ~/.cargo/git
91+
#key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
92+
93+
- name: Cache cargo target dir
94+
uses: actions/cache@v3
95+
with:
96+
path: target
97+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain') }}
98+
99+
#- name: Cache rust repository
100+
## We only clone the rust repository for rustc tests
101+
#if: ${{ contains(matrix.commands, 'rustc') }}
102+
#uses: actions/cache@v3
103+
#id: cache-rust-repository
104+
#with:
105+
#path: rust
106+
#key: ${{ runner.os }}-packages-${{ hashFiles('rust/.git/HEAD') }}
107+
108+
- name: Prepare VM
109+
run: |
110+
mkdir vm
111+
sudo mount debian-m68k.img vm
112+
sudo cp $(which qemu-m68k-static) vm/usr/bin/
113+
114+
- name: Build
115+
run: |
116+
./y.sh prepare --only-libcore --cross
117+
./y.sh build --target-triple m68k-unknown-linux-gnu
118+
CG_GCC_TEST_TARGET=m68k-unknown-linux-gnu cargo test
119+
./clean_all.sh
120+
121+
- name: Prepare dependencies
122+
run: |
123+
git config --global user.email "[email protected]"
124+
git config --global user.name "User"
125+
./y.sh prepare --cross
126+
127+
# Compile is a separate step, as the actions-rs/cargo action supports error annotations
128+
- name: Compile
129+
uses: actions-rs/[email protected]
130+
with:
131+
command: build
132+
args: --release
133+
134+
- name: Add more failing tests because the sysroot is not compiled with LTO
135+
run: cat failing-non-lto-tests.txt >> failing-ui-tests.txt
136+
137+
- name: Run tests
138+
run: |
139+
./test.sh --release --clean --build-sysroot ${{ matrix.commands }}

.github/workflows/release.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ jobs:
2626
steps:
2727
- uses: actions/checkout@v3
2828

29-
- uses: actions/checkout@v3
30-
with:
31-
repository: llvm/llvm-project
32-
path: llvm
33-
3429
- name: Install packages
3530
run: sudo apt-get install ninja-build ripgrep
3631

@@ -56,9 +51,6 @@ jobs:
5651
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
5752
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
5853
59-
- name: Set RUST_COMPILER_RT_ROOT
60-
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV
61-
6254
- name: Cache cargo installed crates
6355
uses: actions/cache@v3
6456
with:

.github/workflows/stdarch.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ jobs:
2626
steps:
2727
- uses: actions/checkout@v3
2828

29-
- uses: actions/checkout@v3
30-
with:
31-
repository: llvm/llvm-project
32-
path: llvm
33-
3429
- name: Install packages
3530
run: sudo apt-get install ninja-build ripgrep
3631

@@ -70,9 +65,6 @@ jobs:
7065
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
7166
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
7267
73-
- name: Set RUST_COMPILER_RT_ROOT
74-
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV
75-
7668
- name: Cache cargo installed crates
7769
uses: actions/cache@v3
7870
with:

Readme.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ $ make check-jit RUNTESTFLAGS="-v -v -v jit.exp=jit.dg/test-asm.cc"
5555
$ dirname $(readlink -f `find . -name libgccjit.so`) > gcc_path
5656
```
5757

58-
You also need to set RUST_COMPILER_RT_ROOT:
59-
60-
```bash
61-
$ git clone https://github.com/llvm/llvm-project llvm --depth 1 --single-branch
62-
$ export RUST_COMPILER_RT_ROOT="$PWD/llvm/compiler-rt"
63-
```
64-
6558
Then you can run commands like this:
6659

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

9285
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.
9386

87+
### LTO
88+
9489
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`.
9590
Don't set `FAT_LTO` when compiling the sysroot, though: only set `EMBED_LTO_BITCODE=1`.
9691

92+
Failing to set `EMBED_LTO_BITCODE` will give you the following error:
93+
94+
```
95+
error: failed to copy bitcode to object file: No such file or directory (os error 2)
96+
```
97+
9798
### Rustc
9899

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

314315
#### Building libgccjit
315316

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

321319
#### Configuring rustc_codegen_gcc
322320

323-
* Set `TARGET_TRIPLE="m68k-unknown-linux-gnu"` in config.sh.
324-
* 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).
325-
* Set `linker='-Clinker=m68k-linux-gcc'`.
321+
* Run `./y.sh prepare --cross` so that the sysroot is patched for the cross-compiling case.
326322
* Set the path to the cross-compiling libgccjit in `gcc_path`.
327-
* Comment the line: `context.add_command_line_option("-masm=intel");` in src/base.rs.
328-
* (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.
323+
* Make sure you have the linker for your target (for instance `m68k-unknown-linux-gnu-gcc`) in your `$PATH`. Currently, the linker name is hardcoded as being `$TARGET-gcc`. Specify the target when building the sysroot: `./y.sh build --target-triple m68k-unknown-linux-gnu`.
324+
* Build your project by specifying the target: `OVERWRITE_TARGET_TRIPLE=m68k-unknown-linux-gnu ../cargo.sh build --target m68k-unknown-linux-gnu`.
325+
* If the target is not yet supported by the Rust compiler, create a [target specification file](https://docs.rust-embedded.org/embedonomicon/custom-target.html) (note that the `arch` specified in this file must be supported by the rust compiler).
326+
327+
If you get the following error:
328+
329+
```
330+
/usr/bin/ld: unrecognised emulation mode: m68kelf
331+
```
332+
333+
Make sure you set `gcc_path` to the install directory.

build_sysroot/build_sysroot.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if [[ "$1" == "--release" ]]; then
2222
RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3" cargo build --target $TARGET_TRIPLE --release
2323
else
2424
sysroot_channel='debug'
25-
cargo build --target $TARGET_TRIPLE --features compiler_builtins/c
25+
cargo build --target $TARGET_TRIPLE
2626
fi
2727

2828
# Copy files to sysroot

0 commit comments

Comments
 (0)