Building c2rust

« Home

Created 2021-06-05, last updated 2021-12-15 05:49:28 UTC

c2rust is a really neat and useful tool :) Unfortunately I had some difficulty building c2rust, here are some notes on how I got it to work.

The c2rust build depends on the host environment, so basically you don't want to build it there or it will break. Building it in a container is the way to go. The c2rust repo has a docker subdirectory, but for some reason it just seems to be for setting up a build environment to build c2rust; it doesn't go all the way and just give you the binary. And the instructions don't actually say what to do with the scripts there, at least as far as I can tell (I may have missed something!), so it's all a bit confusing.

Here's what worked for me on Fedora:

  1. Create a Containerfile:

    FROM docker://immunant/c2rust:archlinux-base-latest
    RUN git clone
    WORKDIR c2rust
    RUN cargo +nightly-2019-12-05 build --release --locked
    ENTRYPOINT ["/c2rust/target/release/c2rust"]
  2. Build it (this will take a while):

    podman build -f Containerfile -t c2rust
  3. Run it in the container:

    podman run -v$PWD:/host:z c2rust transpile --output-dir /host/transpile/ /host/compile_commands.json

That last step assumes that you have a compile_commands.json in the current directory and that the paths it references are under /host. The output will go to /host/transpile.

© 2024 Nicholas BishopHomeRepo
Unless otherwise noted, content is licensed under CC BY 4.0. Code blocks are additionally available under CC0 and Apache License version 2.0 at your option.