FROM ubuntu:22.04 RUN apt-get -y update && apt-get install -y --no-install-recommends \ git curl ca-certificates build-essential sudo python3 file \ flex libmpfr-dev libgmp-dev libmpc3 libmpc-dev texinfo RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y ENV PATH="/root/.cargo/bin:${PATH}" # Not sure why/if this is needed ENV LIBRARY_PATH=/usr/lib # Make sure we compile to the right target ENV OVERWRITE_TARGET_TRIPLE=m68k-elf RUN mkdir /build WORKDIR /build # Install binutils RUN curl -L https://sourceware.org/pub/binutils/releases/binutils-2.43.tar.xz | tar xJ RUN mkdir binutils-build && cd binutils-build && \ ../binutils-2.43/configure --prefix=/usr/local --target=m68k-elf --disable-multilib && \ make -j $(nproc) && \ make install # Install GCC RUN git clone https://github.com/antoyo/gcc RUN mkdir gcc-build && cd gcc-build && \ ../gcc/configure \ --enable-host-shared \ --enable-languages=jit \ --enable-checking=release \ --disable-bootstrap \ --disable-multilib \ --prefix=/usr/local \ --with-cpu=m68000 \ --with-arch=m68k \ --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath \ --disable-libquadmath-support --disable-libsanitizer --disable-libmpx --disable-libstdcxx-verbose \ --without-zstd --disable-threads --disable-tls --disable-cet \ --without-headers \ --target=m68k-elf && \ make -j $(nproc) && \ make install # Clone source repo RUN git clone https://github.com/rust-lang/rustc_codegen_gcc.git # Set gcc path in the rustc_codegen project RUN echo 'gcc-path = "/usr/local/lib"' > rustc_codegen_gcc/config.toml # Setup rustup RUN cd rustc_codegen_gcc && rustup show # Git config is needed for ./y.sh prepare RUN git config --global user.email "user@example.com" RUN git config --global user.name "User" # Apply hacky patch COPY 0001-codegen-add-support-for-megadrive.patch /tmp/0001-codegen-add-support-for-megadrive.patch RUN cd rustc_codegen_gcc && patch -p1 < /tmp/0001-codegen-add-support-for-megadrive.patch && rm /tmp/0001-codegen-add-support-for-megadrive.patch # Provide compiler-rt source so we can get intrinsics to work. (XXX: currently doesn't) RUN apt-get install -y unzip # <- move up. RUN curl -LO https://github.com/llvm/llvm-project/archive/refs/heads/main.zip && unzip main.zip && rm main.zip ENV RUST_COMPILER_RT_ROOT=/build/llvm-project-main/compiler-rt/ ENV CHANNEL=release # Build project # See https://github.com/rust-lang/rustc_codegen_gcc/blob/master/doc/tips.md#how-to-build-a-cross-compiling-libgccjit RUN cd rustc_codegen_gcc && ./y.sh prepare --cross ENV CG_RUSTFLAGS="-Cpanic=abort -Crelocation-model=static -Copt-level=3" RUN cd rustc_codegen_gcc && ./y.sh build --sysroot --features compiler_builtins/no-f16-f128 --target-triple m68k-unknown-linux-gnu --target /build/rustc_codegen_gcc/target_specs/m68k-unknown-linux-gnu.json --release # ENV CG_RUSTFLAGS="-Cpanic=abort -Crelocation-model=static -Copt-level=s" # Build "megapong" PoC # TODO: Make this a Makefile RUN git clone https://github.com/ricky26/rust-mega-drive.git COPY 0001-Make-project-compile-with-GCC.patch /tmp/rust-mega-drive.patch RUN cd rust-mega-drive && patch -p1 < /tmp/rust-mega-drive.patch && rm /tmp/rust-mega-drive.patch # Compile rust code RUN cd rustc_codegen_gcc && ./y.sh cargo build --target /build/rustc_codegen_gcc/target_specs/m68k-unknown-linux-gnu.json --manifest-path /build/rust-mega-drive/examples/megapong/Cargo.toml --release # Compile entrypoint + stdlib stub (should not be strictly necessary to reproduce) RUN cd rust-mega-drive/examples/megapong && m68k-elf-gcc -fno-exceptions -mcpu=68000 -T /build/rust-mega-drive/share/ldscripts/megadrive.x entry.S hack.c /build/rust-mega-drive/target/m68k-unknown-linux-gnu/release/libmegapong.a -o out.elf -O2 -nostartfiles -nostdlib -static -nolibc -s -flto -Wl,-gc-sections -ffunction-sections -fdata-sections RUN cd rust-mega-drive/examples/megapong && m68k-elf-objcopy -O binary out.elf out.md