gcc: locate codegen-backends via host_tuple() - #920
Conversation
`file_path` builds the `lib/rustlib/<host>/codegen-backends` path used to load the codegen backend. It passed `&sess.host.llvm_target`, but that is the host's LLVM target string, not its rustc target tuple. The two can differ (e.g. `arm64-apple-macosx` vs `aarch64-apple-darwin`), so the lookup can miss the directory that actually holds the backend. Use `rustc_session::config::host_tuple()` instead.
|
Looks good to me, thanks! Let's see if @antoyo agrees as well. |
|
I'll double-check something for the review, but in the meantime, could you please reopen rust-lang/rust#159753 (possibly marking it as draft is needed)? |
|
I think this is not needed, but just to double-check, do you need to adjust this host as well? This seems to already use the Rust host, so I believe this is correct. |
|
I haven't run into that issue, and it's been working well for me so far. For reference, I've settled on this script for building the GCC backend. It's been working really well, and I've accumulated several patches which I'm working to upstream. This is the first of the set, and I see I'll be able to drop my build-rust-sh4.sh#!/bin/sh
set -x
set -e
cd "$(dirname "$0")"
cd ..
export PATH=$PWD/install/gcc/bin:$PATH
# Apply Rust patches
cd src/rust
git reset --hard HEAD
git am --abort || true
cd src/gcc
git am --abort || true
cd ../..
git checkout df6ee909ef35c75aa58aa45af6ac071a9b8285c2
git am ../../patches/rust/*.patch
cd ../..
# On macOS, fix libgccjit symbol visibility
if [ "$(uname -s)" = "Darwin" ]
then
# Create .so symlinks for .dylib files (build system expects .so)
for d in install/*/aarch64-apple-darwin install/*/sh4-dreamcast-none-elf
do
[ -f "$d/libgccjit.dylib" ] && ln -sf libgccjit.dylib "$d/libgccjit.so"
[ -f "$d/libgccjit.0.dylib" ] && ln -sf libgccjit.0.dylib "$d/libgccjit.0.so"
done
ln -sf libgccjit.dylib install/gcc/lib/libgccjit.so
ln -sf libgccjit.0.dylib install/gcc/lib/libgccjit.0.so
fi
cat > src/rust/bootstrap.toml <<EOF
change-id = 154587
[install]
prefix = "$PWD/install/rust"
sysconfdir = "etc"
[build]
build-dir = "$PWD/build/rust"
extended = true
submodules = false
tools = ["cargo","src"]
docs = false
[rust]
codegen-backends = ["llvm", "gcc"]
[gcc]
libgccjit-libs-dir = "$PWD/install/gcc"
[target.sh4-dreamcast-none-elf]
codegen-backends = ["gcc"]
cc = "$PWD/install/gcc/bin/shle-elf-gcc"
ar = "$PWD/install/gcc/bin/shle-elf-ar"
rustflags = ["-Zcodegen-backend=gcc", "-Crelocation-model=static", "-Ccodegen-units=1", "-Copt-level=1"]
EOF
cd src/rust
python3 x.py install
BOOTSTRAP_SKIP_TARGET_SANITY=1 python3 x.py install library --target sh4-dreamcast-none-elf
BOOTSTRAP_SKIP_TARGET_SANITY=1 python3 x.py build rustc_codegen_gcc --target sh4-dreamcast-none-elf
rustup toolchain link sh4 ../../install/rust
# Copy librustc_codegen_gcc.so to the codegen-backends directory
SYSROOT=$(rustc +sh4 --print sysroot)
HOST=$(rustc --print host-tuple)
CG_DIR="$SYSROOT/lib/rustlib/$HOST/codegen-backends"
BUILD_DIR="../../build/rust/$HOST/stage2-codegen/$HOST/release"
mkdir -p "$CG_DIR"
for EXT in so dylib dll
do
[ -f "$BUILD_DIR/librustc_codegen_gcc.$EXT" ] && cp "$BUILD_DIR/librustc_codegen_gcc.$EXT" "$CG_DIR/librustc_codegen_gcc.$EXT"
done
# Copy libgccjit entries to their destination paths
mkdir -p $(rustc +sh4 --print sysroot)/lib/rustlib/$(rustc --print host-tuple)/codegen-backends/lib/sh4-dreamcast-none-elf
cp ../../install/gcc/$(rustc --print host-tuple)/sh4-dreamcast-none-elf/libgccjit.so $(rustc +sh4 --print sysroot)/lib/rustlib/$(rustc --print host-tuple)/codegen-backends/lib/sh4-dreamcast-none-elf
cd ../.. |
The script you use does not seem to use the build system used in this repo, but I think no changes are needed in it anyway. I'll wait for the CI to pass in the Rust repo, then we can merge this. |
|
Correct, it doesn't use the build system used in this repo. I'm working from the |
file_pathbuilds thelib/rustlib/<host>/codegen-backendspath used to load the codegen backend. It passed&sess.host.llvm_target, but that is the host's LLVM target string, not its rustc target tuple. The two can differ (e.g.arm64-apple-macosxvsaarch64-apple-darwin), so the lookup can miss the directory that actually holds the backend. Userustc_session::config::host_tuple()instead.This fixes an issue when building custom toolchains. In particular, I'm using the gcc backend to build a custom SH4 compiler. Without this patch, this command fails to find the backend: